Azure Function Service总线输出绑定错误 [英] Error with Azure Function Service Bus Output Binding

查看:119
本文介绍了Azure Function Service总线输出绑定错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Azure Service Bus输出绑定时遇到问题,不确定如何进行.我没有运气找到类似的问题,因此,如果这是重复的,我深表歉意.

I'm having an issue with an Azure Service Bus output binding that I'm uncertain about how to proceed with. I've had no luck finding a similar question, so I apologize if this is a duplicate.

我正在尝试使用本地VS 2017开发流程,因此应该自动生成function.json绑定.功能签名如下:

I'm trying to use the local VS 2017 development process, so the function.json bindings should be generated automatically. The function signature is as follows:

  [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);
  }

在本地运行该函数时出现以下错误.

I get the following error when running the function locally.

Microsoft.Azure.WebJobs.Host:错误索引方法 'RequestNewPaladinInvitation.Run'. Microsoft.Azure.WebJobs.Host: 无法将参数"invitationOutputQueue"绑定到ICollector`1类型. 确保绑定支持参数类型".如果你是 使用绑定扩展(例如ServiceBus,Timer等)确保 您已经在您的扩展中调用了注册方法 启动代码(例如config.UseServiceBus(),config.UseTimers()等). [9/1/2017 5:42:49 PM]错误索引方法 'RequestNewPaladinInvitation.Run'

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都定义如下:

Both my host.json and local.settings.json are defined as follows:

{
   "IsEncrypted": false,
   "Values": {
      "AzureWebJobsStorage": "<MyStorageAccountInfo>",
      "AzureWebJobsDashboard": "<MyDashboardInfo>",
      "AzureWebJobsServiceBus": "<MyServiceBusConnectionString>"
   }
}

给我留下深刻印象的是,定义AzureWebJobsServiceBus值将使整个功能应用程序中任何ServiceBus绑定的默认ServiceBusAccount都保持不变.

I was under the impressing that defining the AzureWebJobsServiceBus value would make that the default ServiceBusAccount for any ServiceBus bindings throughout the function app.

我还尝试使用以下替代属性[ServiceBus("createpaladininvitation",Connection = "ServiceBus")]显式地将ServiceBus绑定指向该帐户的连接字符串.我对约定的理解是,不应包含该属性的 AzureWebJobs 部分.以防万一我误解了,我也尝试了[ServiceBus("createpaladininvitation",Connection = "AzureWebJobsServiceBus")].我什至尝试使用以下属性[ServiceBusAccount("ServiceBus")]装饰方法和参数.我还尝试了与ServiceBus属性的Connection参数相同的变体.

I also tried explicitly pointing the ServiceBus binding to the connection string for the account with the following alternative attribute [ServiceBus("createpaladininvitation",Connection = "ServiceBus")]. My understanding of the convention is that the AzureWebJobs portion of the property should not be included. Just in case I misunderstood, I tried [ServiceBus("createpaladininvitation",Connection = "AzureWebJobsServiceBus")] as well. I even tried to decorate both the method and parameter with the following attribute, [ServiceBusAccount("ServiceBus")]. I also tried the same variations as with the Connection parameter for the ServiceBus attribute.

在所有情况下,我都会得到相同的function.json输出,该输出显示没有为ServiceBus输出绑定生成绑定.

In all cases, I get the same function.json output, which shows no binding generated for the ServiceBus output binding.

这是function.json:

Here's the 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"
}

感觉我缺少明显的东西.

It feels like I'm missing something obvious.

[更新]

当我试图继续弄清楚发生了什么时,我在本地运行了该函数并编辑了生成的function.json文件,并添加了我应该生成的绑定 think .最终手动编辑的function.json是:

As I tried to continue to figure out what's going on, I ran the function locally and edited the generated function.json file and added the binding that I think should have been generated. The resulting manually edited function.json is:

{
  "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"
}

进行这些编辑后,该方法将完全按预期工作.

With those edits, the method works exactly as expected.

这感觉更像是我所缺少的语法或约定问题或工具错误.

This feels even more like either a syntax or convention issue that I'm missing, or a tooling bug.

推荐答案

关于ServiceBus输出触发器,当前存在一个突出的工具错误.如果您将应用程序部署"到Azure Functions,而不是在本地使用工具,它将起作用

There is currently an outstanding tooling bug in regards to ServiceBus output triggers. It will work if you 'deploy' your app to Azure Functions, just not locally with the tooling

请在此处查看相关的GitHub问题:服务总线输出绑定问题

Please see relevant GitHub issues here: Service Bus output binding issue

和此处:最新的v1.0.0不能与ServiceBus一起使用. Alpha 6仍然有效.

这与延迟加载有关.我们没有接服务总线扩展,因此没有索引错误. (Azure/azure-webjobs-sdk-script#1637)

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)

其原因是ServiceBus扩展与其他扩展不同.我们希望扩展具有实现IExtensionConfigProvider的公共无参数配置对象.

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是内部的( https://github.com/Azure/azure-webjobs-sdk/blob/663a508e8a851629c26a51e7de3af36629dfd120/src/Microsoft.Azure.WebJobs.ServiceBus/Config/ServiceBusExtensionConfig.cs#L17 )我们对ExportedTypes的扫描错过了它(请参见 https://github.com/Azure/azure-webjobs-sdk-script/blob/b1445485807bb190ba0716af1a8dc81a864b5228/src/WebJobs.Script/Host/ScriptHost.cs#L735 ). SB的配置没有无参数的ctor,因此Activator.createInstance调用也将失败. 此修补程序(我们为脚本运行时制作了此修补程序)Azure/azure-webjobs-sdk-script#1804将对其进行修复;但这需要将其拉到CLI.

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 Function Service总线输出绑定错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆