Могу ли я передать или каким-либо образом получить orchestrationID, сгенерированный функцией httpTrigger в моей функции orchestrationTrigger в долговременных функциях? - PullRequest
1 голос
/ 16 апреля 2020

Я хочу сделать некоторую регистрацию в SEQ в моих долговременных функциях, и для этого мне нужен некоторый идентификатор, так как функция httpTrigger генерирует уникальный идентификатор orchestrationID, поэтому я думаю об использовании его во всех журналах, указанных c для одного запроса , Поэтому я ищу, как я могу получить или отправить его другим моим функциям.

1 Ответ

1 голос
/ 17 апреля 2020

Обновление:

using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp25
{
    public static class Function1
    {
        // use b to save orchestrationID

        static string b = "";   

        [FunctionName("Function1")]
        public static async Task<List<string>> RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            var outputs = new List<string>();

            //use this to get the orchestrationID from IDurableOrchestrationContext

            string a = context.InstanceId;  
            b = a;
            // Replace "hello" with the name of your Durable Activity Function.
            outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "Tokyo"));
            outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "Seattle"));
            outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "London"));
            // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
            return outputs;
        }

        [FunctionName("Function1_Hello")]
        public static string SayHello([ActivityTrigger] string name, ILogger log, [DurableClient] IDurableOrchestrationClient starter)
        {
            log.LogInformation("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+b);
            log.LogInformation($"Saying hello to {name}.");
            return $"Hello {name}!";
        }

        [FunctionName("Function1_HttpStart")]
        public static async Task<HttpResponseMessage> HttpStart(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            // Function input comes from the request content.
            string instanceId = await starter.StartNewAsync("Function1", null);
            log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

            return starter.CreateCheckStatusResponse(req, instanceId);
        }
    }
}

Оригинальный ответ:

Этот orchestrationID является автоматически сгенерированным GUID. В httptrigger вы можете получить его следующим образом:

string orchestrationID = await starter.StartNewAsync("YourOrchestrationTriggerName", null);

Однако обратите внимание, что каждый раз, когда вы запускаете функцию, IDurableOrchestrationContext будет генерировать новый идентификатор orchestrationID.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...