【问题标题】:context.GetInput<T> getting null in Durable Functioncontext.GetInput<T> 在持久函数中为空
【发布时间】:2021-02-16 13:39:28
【问题描述】:

我正面临一个奇怪的问题。搜索了多个问题,但并没有真正解决这个问题。我有以下默认模板代码。

 [FunctionName("OrchFunction_HttpStart")]
    public 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("OrchFunction", null);

        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

        return starter.CreateCheckStatusResponse(req, instanceId);
    }

在 Orchstrator 函数中我有以下代码

[FunctionName("OrchFunction")]
        public  async Task<List<string>> RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            var outputs = new List<string>();
            var data = context.GetInput<JobPayload>();
            var inst=context.InstanceId;
           

            // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
            return outputs;
        }

这里的问题是我在var data = context.GetInput&lt;JobPayload&gt;(); 中得到NULL。不知道为什么,因为它是 T 类型,我在 HttpRequestMessage 中传递。我知道它错了,但尝试使用 var data = context.GetInput&lt;HttpResponseMessage&gt;(); ,仍然为空。这里有什么问题?我得到了context.InstanceId 的价值。

【问题讨论】:

    标签: c# asp.net-core asp.net-core-3.1 azure-function-app azure-durable-functions


    【解决方案1】:

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableorchestrationclient.startnewasync?view=azure-dotnet#Microsoft_Azure_WebJobs_Extensions_DurableTask_IDurableOrchestrationClient_StartNewAsync_System_String_System_String_

    下面是 StartNewAsync 的不同重载。您正在使用的那个不会将任何输入传递给编排器,因此您不会在编排器中有任何输入。 以此为首发

     [FunctionName("OrchFunction_HttpStart")]
        public async Task<HttpResponseMessage> HttpStart(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            var payload = new JobPayload()
            {
              //Fill with data
            }
            // Function input comes from the request content.
            string instanceId = await starter.StartNewAsync<JobPayload>("OrchFunction", payload);
    
            log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
    
            return starter.CreateCheckStatusResponse(req, instanceId);
        }
    

    注意:JobPayload 必须是可序列化的

    【讨论】:

      猜你喜欢
      • 2020-10-01
      • 1970-01-01
      • 2020-10-27
      • 2019-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      相关资源
      最近更新 更多