我可以在持久函数中的 orchestrationTrigger 函数中传递或以某种方式获取由 httpTrigger 函数生成的 orchestrationID 吗?

Can I pass or somehow get the orchestrationID that is generated by httpTrigger function in my orchestrationTrigger function in durable functions?

我想在我的持久函数中对 SEQ 进行一些记录,为此我需要一些标识符,因为 httpTrigger 函数生成一个唯一的 orchestrationID,所以我考虑在特定于一个请求的所有日志中使用它。所以我正在寻找如何获取或将其发送给我的其他功能。

更新:

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。