我遇到了 Azure 服务总线输出绑定(bind)问题,不确定如何继续处理。我没有运气找到类似的问题,所以如果这是重复的,我深表歉意。
我正在尝试使用本地 VS 2017 开发过程,因此应该自动生成 function.json 绑定(bind)。函数签名如下:
[FunctionName("RequestNewPaladinInvitation")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequestMessage req,
[ServiceBus("thequeue")] ICollector<Invitation> invitationOutputQueue,
TraceWriter log)
{
//Do some stuff and write to the queue
invitationOutputQueue.Add(invite);
}
在本地运行该函数时出现以下错误。
Microsoft.Azure.WebJobs.Host: Error indexing method 'RequestNewPaladinInvitation.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'invitationOutputQueue' to type ICollector`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.). [9/1/2017 5:42:49 PM] Error indexing method 'RequestNewPaladinInvitation.Run'
我的host.json和local.settings.json定义如下:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "<MyStorageAccountInfo>",
"AzureWebJobsDashboard": "<MyDashboardInfo>",
"AzureWebJobsServiceBus": "<MyServiceBusConnectionString>"
}
}
令我印象深刻的是,定义 AzureWebJobsServiceBus
值将使其成为整个函数应用中任何 ServiceBus 绑定(bind)的默认 ServiceBusAccount。
我还尝试使用以下替代属性将 ServiceBus 绑定(bind)显式指向帐户的连接字符串[ServiceBus("createpaladininvitation",Connection = "ServiceBus")]
。我对约定的理解是不应包含该属性的 AzureWebJobs 部分。以防万一我误解了,我也尝试了 [ServiceBus("createpaladininvitation",Connection = "AzureWebJobsServiceBus")]
。我什至尝试使用以下属性来装饰方法和参数:[ServiceBusAccount("ServiceBus")]
。我还尝试了与 ServiceBus 属性的 Connection 参数相同的变体。
在所有情况下,我都会得到相同的 function.json 输出,该输出显示没有为 ServiceBus 输出绑定(bind)生成任何绑定(bind)。
这是 function.json:
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
"type": "httpTrigger",
"methods": [
"post"
],
"authLevel": "anonymous",
"name": "req"
}
],
"disabled": false,
"scriptFile": "..\\bin\\AzureFunctionsPoc.dll",
"entryPoint": "AzureFunctionsPoc.RequestNewPaladinInvitation.Run"
}
感觉我错过了一些明显的东西。
[更新]
当我试图继续弄清楚发生了什么时,我在本地运行了该函数并编辑了生成的 function.json 文件,并添加了我认为应该生成的绑定(bind)。手动编辑的 function.json 的结果是:
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
"type": "httpTrigger",
"methods": [
"post"
],
"authLevel": "anonymous",
"name": "req"
},
{
"type": "serviceBus",
"name": "invitationOutputQueue",
"queueName": "createpaladininvitation",
"connection": "ServiceBus",
"direction": "out"
}
],
"disabled": false,
"scriptFile": "..\\bin\\AzureFunctionsPoc.dll",
"entryPoint": "AzureFunctionsPoc.RequestNewPaladinInvitation.Run"
}
经过这些编辑,该方法完全按照预期工作。
这感觉更像是我遗漏的语法或约定问题,或者是工具错误。
最佳答案
目前,ServiceBus 输出触发器存在一个突出的工具错误。如果您将应用程序“部署”到 Azure Functions,而不是使用工具在本地,它将起作用
请在此处查看相关的 GitHub 问题:Service Bus output binding issue
这里:Latest v1.0.0 not working with ServiceBus. alpha 6 still works.
This is related to the lazy load. We're not picking up the service bus extension, hence the indexing error. (Azure/azure-webjobs-sdk-script#1637)
The reason for that is that ServiceBus extension is different than the others. We expect extensions to have a public parameterless config object that implements IExtensionConfigProvider.
SB is internal (https://github.com/Azure/azure-webjobs-sdk/blob/663a508e8a851629c26a51e7de3af36629dfd120/src/Microsoft.Azure.WebJobs.ServiceBus/Config/ServiceBusExtensionConfig.cs#L17 ) so our scan for ExportedTypes misses it (see https://github.com/Azure/azure-webjobs-sdk-script/blob/b1445485807bb190ba0716af1a8dc81a864b5228/src/WebJobs.Script/Host/ScriptHost.cs#L735) . SB's config does not have a parameterless ctor, so the Activator.createInstance call will fail too. This hotfix (which we made to script runtime) Azure/azure-webjobs-sdk-script#1804 would fix it; but that would need to be pulled to CLI.
关于azure - Azure Function 服务总线输出绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46005865/