簡體   English   中英

Azure函數 - ICollector綁定不在結果function.json中

[英]Azure Functions - ICollector binding not in resulting function.json

我有以下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
        });
    }
}

其中產生以下函數.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"
}

根據這里的文檔,json輸出應該包含一個帶有“out”方向的隊列綁定。 即:

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

當我嘗試通過npm工具( 這里描述的配置)運行隊列時,我收到以下錯誤:

運行:Microsoft.Azure.WebJobs.Host:錯誤索引方法'UpdateCohortsByTenantFunction.Run'。 Microsoft.Azure.WebJobs.Host:無法將參數'output'綁定到類型IAsyncCollector`1。 確保綁定支持參數Type。 如果您正在使用綁定擴展(例如ServiceBus,Timers等),請確保您已在啟動代碼中調用擴展的注冊方法(例如config.UseServiceBus(),config.UseTimers()等)。

該文檔不包含通過啟動代碼進行綁定的引用。 我的理解是,這是通過上面鏈接的Microsoft文檔和我的示例代碼中描述的屬性完成的,但錯誤消息表明不是這樣。

  1. 你應該用屬性修飾你的參數,而不是返回值:

     public static async Task Run( [TimerTrigger("* * * * * *")]TimerInfo myTimer, [Queue("my-queue", Connection = "MyStg")] IAsyncCollector<AudienceMessage> output) 
  2. function.json沒有輸出綁定。 屬性定義的綁定不會傳輸到生成的function.json 他們仍然會工作,不用擔心。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM