[英]How to log errors in an azure function that uses an output binding to a service bus?
[英]Azure Function Output Service Bus Binding From Timer trigger
我正在運行Visual Studio 2017 Preview並在本地運行功能代碼,我正在使用開箱即用的Azure Function項目模板。 我正在嘗試使用定時器觸發的Azure功能使用輸出綁定將消息發送到服務總線隊列,但看起來WebJob SDK無法將輸出綁定到字符串類型。
捆綁
"bindings": [
{
"type": "serviceBus",
"name": "msg",
"queueName": "myqueue",
"connection": "ServiceBusQueue",
"accessRights": "manage",
"direction": "out"
}
]
定時器功能
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
namespace MyFunctionApp
{
public static class TimerTrigger
{
[FunctionName("TimerTriggerCSharp")]
public static void Run([TimerTrigger("1 * * * * *", RunOnStartup = true)]TimerInfo myTimer, TraceWriter log, out string msg)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
msg = "Hello!";
}
}
}
錯誤信息
TimerTriggerCSharp:Microsoft.Azure.WebJobs.Host:錯誤索引方法'Functions.TimerTriggerCSharp'。 Microsoft.Azure.WebJobs.Host:無法將參數'msg'綁定到String&。 確保綁定支持參數Type。 如果您正在使用綁定擴展(例如ServiceBus,Timers等),請確保您已在啟動代碼中調用擴展的注冊方法(例如config.UseServiceBus(),config.UseTimers()等)。
我錯過了設置中的一個步驟,或者Service Bus綁定是否真的不支持out
參數的字符串
看起來你錯過了ServiceBus
的綁定屬性。 我只使用ICollector<T>
類型而不是out string
但無論如何都應該無關緊要。
[FunctionName("TimerTriggerCSharp")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
TraceWriter log,
[ServiceBus("%QueueName%", Connection = "ServiceBusConnection", EntityType = Microsoft.Azure.WebJobs.ServiceBus.EntityType.Queue)] out string msg)
{
msg = "My message";
}
要使用VS2017預覽工具在本地運行,您還需要在local.settings.json
定義以下本地設置以匹配您的ServiceBus
屬性。
{
"Values": {
"ServiceBusConnection" : "Endpoint=sb://.....your connection",
"QueueName": "my-service-bus-queue
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.