来自计时器触发器的 Azure 函数输出服务总线绑定
Azure Function Output Service Bus Binding From Timer trigger
我是 运行 Visual Studio 2017 预览版和 运行 本地函数代码,我正在使用开箱即用的 Azure 函数项目模板。我正在尝试让计时器触发的 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: Error indexing
method 'Functions.TimerTriggerCSharp'. Microsoft.Azure.WebJobs.Host:
Cannot bind parameter 'msg' to type String&. 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.).
我是否遗漏了设置中的一个步骤,或者服务总线绑定是否真的不支持 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
}
}
我是 运行 Visual Studio 2017 预览版和 运行 本地函数代码,我正在使用开箱即用的 Azure 函数项目模板。我正在尝试让计时器触发的 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: Error indexing method 'Functions.TimerTriggerCSharp'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'msg' to type String&. 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.).
我是否遗漏了设置中的一个步骤,或者服务总线绑定是否真的不支持 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
}
}