c# - context.GetInput在持久函数中获取 null
问题描述
我面临一个奇怪的问题。搜索了多个问题,但并没有真正解决这个问题。我有以下默认模板代码。
[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;
}
这里的问题是我要NULL
进去了var data = context.GetInput<JobPayload>();
。不知道为什么,因为它是我传递的 T 类型HttpRequestMessage
。我知道它错了,但试过了var data = context.GetInput<HttpResponseMessage>();
,仍然是空的。这里有什么问题?我得到了context.InstanceId
价值。
解决方案
下面是 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 必须是可序列化的
推荐阅读
- amazon-web-services - 如何解决 AWS Bad String 上的 JSON 错误?
- node.js - Google maps API returning No 'Access-Control-Allow-Origin' with Node.js module
- python - 获取pyspark中每行的最大值的列索引
- nginx - Kubernetes -“拒绝”注解.nginx.org/listen-ports
- python - 如何在 Visual Studio 中注释多行代码
- javascript - “Uncaught ReferenceError: require is not defined” 我想知道如何解决它
- css - Material UI/React Custom 主题黑暗模式给了我两种非常不同的灰色阴影
- azure - Azure Synapse Analytics 是否有 python 支持?
- google-cloud-platform - Anthos 配置管理 Prometheus 指标
- python - 通过 gspread 从本地安装的驱动器中获取 Google 表格数据