Azure functions 我是否可以在持久函数中的orchestrationTrigger函数中传递或以某种方式获取由httpTrigger函数生成的orchestrationID?
我想在我的持久函数中对SEQ进行一些日志记录,为此我需要一些标识符,因为httpTrigger函数生成一个唯一的orchestrationID,所以我想在特定于一个请求的所有日志中使用它。因此,我正在寻找如何获取或发送到其他函数。更新:Azure functions 我是否可以在持久函数中的orchestrationTrigger函数中传递或以某种方式获取由httpTrigger函数生成的orchestrationID?,azure-functions,orchestration,azure-durable-functions,Azure Functions,Orchestration,Azure Durable Functions,我想在我的持久函数中对SEQ进行一些日志记录,为此我需要一些标识符,因为httpTrigger函数生成一个唯一的orchestrationID,所以我想在特定于一个请求的所有日志中使用它。因此,我正在寻找如何获取或发送到其他函数。更新: using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Microsoft.Azure.WebJobs; using Microso
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);
}
}
}
但是,请注意,每次触发函数时,IdurableCorchestrationContext都会生成一个全新的orchestrationID。感谢您的回复,是的,我知道orchestrationID是在httpTrigger函数中生成的,我希望它出现在我的其他函数中:OrchestrationTrigger函数和活动中function@BilalShafqat没问题,这是可以实现的。您可以预先设置一个值,该值用于存储orchestrationId。我稍后会更新答案。@BillalShafqat您可以自定义字符串类型字段b以用于存储。在OrchestrationTrigger中,您可以从IDurableOrchestrationContext获取此只读字段,并将其分配给刚才定义的字符串类型的字段b。然后在活动中,您可以获得字段b,字段b是orchestrationId:)@BillalShafqat很乐意帮忙。:)
string orchestrationID = await starter.StartNewAsync("YourOrchestrationTriggerName", null);