gpt4 book ai didi

c# - 持久函数 : How to pass a parameter to the Orchestrator?

转载 作者:行者123 更新时间:2023-12-04 16:25:04 25 4
gpt4 key购买 nike

我是 Azure Durable 函数的新手,一直在关注书中的示例代码 'Azure Serverless Computing Cookbook'我被卡住了,因为我的 Orchestrator 中的 .GetInput 函数返回 null。我的 Blob 触发器正在将文件名作为参数传递给我的 Orchestrator。我认为它调用了错误的重载函数,但不确定如何调用正确的函数。

await starter.StartNewAsync("CSVImport_Orchestrator", name); 
        [FunctionName("CSVImport_Orchestrator")]
public static async Task<List<string>> RunOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context)
{
var outputs = new List<string>();
string CSVFileName = context.GetInput<string>(); //<<== returns null???
{
List<Employee> employees = await context.CallActivityAsync<List<Employee>>("ReadCSV_AT", CSVFileName);
}
return outputs;
}

[FunctionName("CSVImportBlobTrigger")]
public static async void Run([BlobTrigger("import-obiee-report/{name}", Connection = "StorageConnection")]Stream myBlob, string name, [DurableClient]IDurableOrchestrationClient starter, ILogger log)
{
string instanceId = await starter.StartNewAsync("CSVImport_Orchestrator", name);
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
}
在此先感谢您的帮助。

最佳答案

您正在调用 non-generic overload of StartAsync(string, string) 第二个,string参数表示 InstanceId 而不是输入参数。还有一个generic overload其中第二个参数代表数据。您正在传递一个 string所以重载决议看到了两个潜在的候选人。然后它更喜欢非通用的,因为它是 精确 匹配,从而“丢失”您的数据。
如果您真的需要string对于您的输入数据,您需要明确指定泛型参数以强制编译器选择正确的重载:

await starter.StartAsync<string>("CSVImport_Orchestrator", name);
现在,文档还指出输入应该是一个 JSON 可序列化对象。技术上是 string是,但我不确定它是如何与编排器的序列化程序一起使用的。您可以改为传递包含您的数据的类。这样做的好处是可以正确推断出泛型参数:
public class Data {
public string Name { get; set; }
}

// calling
await starter.StartAsync("CSVImport_Orchestrator", new Data { Name = name });

// using
var csvFileName = context.GetInput<Data>()?.Name;

关于c# - 持久函数 : How to pass a parameter to the Orchestrator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66619880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com