gpt4 book ai didi

Azure Functions - ICollector 绑定(bind)不在结果 function.json 中

转载 作者:行者123 更新时间:2023-12-04 00:33:29 26 4
gpt4 key购买 nike

我有以下 C# 函数代码:

[FunctionName("UpdateCohortsByTenantFunction")]
[return: Queue("my-queue", Connection = "MyStorage")]
//note - I have tried both method decoration and parameter decoration
public static async Task Run([TimerTrigger("* * * * * *")]TimerInfo myTimer, IAsyncCollector<AudienceMessage> output)
{
//some logic
foreach (var audience in audiences)
{
await output.AddAsync(new AudienceMessage
{
AudienceId = audience.Id,
TenantId = tenant.Id
});
}
}

生成以下 function.json:

{
"generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.6",
"configurationSource": "attributes",
"bindings": [
{
"type": "timerTrigger",
"schedule": "* * * * * *",
"useMonitor": true,
"runOnStartup": false,
"name": "myTimer"
}
],
"disabled": false,
"scriptFile": "../bin/MyApp.App.Tasks.Functions.dll",
"entryPoint": "MyApp.App.Tasks.Functions.UpdateCohortsByTenantFunction.Run"
}

根据文档here json 输出应包含与我的队列的绑定(bind),并具有“out”方向。即:

{
"type": "queue",
"direction": "out",
"name": "$return",
"queueName": "outqueue",
"connection": "MyStorageConnectionAppSetting",
}

当我尝试通过 npm 工具运行队列(配置描述 here )时,出现以下错误:

Run: Microsoft.Azure.WebJobs.Host: Error indexing method 'UpdateCohortsByTenantFunction.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'output' to type IAsyncCollector`1. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

该文档不包含对通过启动代码进行绑定(bind)的引用。我的理解是,这是通过上面链接的 Microsoft 文档和我的示例代码中描述的属性来完成的,但错误消息表明并非如此。

最佳答案

  1. 你应该用属性来装饰你的参数,而不是返回值:

    public static async Task Run(
    [TimerTrigger("* * * * * *")]TimerInfo myTimer,
    [Queue("my-queue", Connection = "MyStg")] IAsyncCollector<AudienceMessage> output)
  2. function.json 中预计不会有输出绑定(bind)。属性定义的绑定(bind)不会传输到生成的 function.json。它们仍然可以工作,不用担心。

关于Azure Functions - ICollector 绑定(bind)不在结果 function.json 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47284972/

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