Azure Functions无法接收Azure队列消息[.net Core 2.0]

时间:2018-01-20 00:35:01

标签: c# azure azure-functions asp.net-core-2.0 azure-servicebus-queues

当我将Azure Functions项目更新为.net core 2.0时,它开始无法触发我的队列上的消息。

TranslatorAPI.cs

public static class TranslatorAPI
{
    [FunctionName("TranslatorAPI")]
    public static void Run([QueueTrigger("Translator")]string mySbMsg, TraceWriter log)
    {
        //breakpoint here, but never hit
        CallTranslator callTranslator = new CallTranslator();

        //something
    }
}

local.setting.json

{
  "IsEncrypted": false,
  "Values": {
    "WEBSITE_SLOT_NAME": "Production",
    "FUNCTIONS_EXTENSION_VERSION": "~1",
    "ScmType": "None",
    "WEBSITE_AUTH_ENABLED": "False",
    "FUNCTION_APP_EDIT_MODE": "readwrite",
    "APPINSIGHTS_INSTRUMENTATIONKEY": "<Key>",
    "WEBSITE_NODE_DEFAULT_VERSION": "6.5.0",
    "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "DefaultEndpointsProtocol=https;AccountName=<AccountName>;AccountKey=<Key>",
    "WEBSITE_CONTENTSHARE": "<ShareName>",
    "WEBSITE_SITE_NAME": "<Functions'Name>",
    "<ServiceBusInstanceName>_RootManageSharedAccessKey_SERVICEBUS": "Endpoint=<ConnectionString>",
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=<AccountName>;AccountKey=<Key>",
    "AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=<AccountName>;AccountKey=<Key>;BlobEndpoint=<BlobURL>;TableEndpoint=<TableURL>;QueueEndpoint=<QueueURL>;FileEndpoint=<FileURL>"
  }
}

解决方法:

使用最新的NuGet软件包&#34; Microsoft.Azure.WebJobs&#34; 3.0.0-beta4,a known issue处理ServiceBus连接的扩展,项目构建失败,无法建立ServiceBus元数据的路径。从源Azure App Service更新这些包:

Microsoft.Azure.WebJobs: 3.0.0-beta4-11131
Microsoft.Azure.WebJobs.Extensions: 3.0.0-beta4-10578
Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator: 1.0.0-beta3
Microsoft.Azure.WebJobs.ServisBus: 3.0.0-beta4-11131

启用构建成功。但是,它仍然无法从我的队列中接收消息。这是功能控制台的日志。

[2018/01/20 0:22:38] Reading host configuration file '<ProjectPath>\bin\Debug\netstandard2.0\host.json'
[2018/01/20 0:22:38] Host configuration file read:
[2018/01/20 0:22:38] {}
[2018/01/20 0:22:40] Loading custom extension 'HttpExtensionConfiguration'
[2018/01/20 0:22:40] Unable to load custom extension type for extension 'HttpExtensionConfiguration' (Type: `Microsoft.Azure.WebJobs.Extensions.Http.HttpExtensionConfiguration, Microsoft.Azure.WebJobs.Extensions.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null`).The type does not exist or is not a valid extension. Please validate the type and assembly names.
[2018/01/20 0:22:40] Loading custom extension 'ServiceBusExtensionConfig'
[2018/01/20 0:22:40] Loaded custom extension: ServiceBusExtensionConfig from '<ProjectPath>\bin\Debug\netstandard2.0\bin\Microsoft.Azure.WebJobs.ServiceBus.dll'
[2018/01/20 0:22:41] Generating 1 job function(s)
[2018/01/20 0:22:42] Starting Host (HostId=<PCName>-1149239943, Version=2.0.11415.0, ProcessId=12536, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=~1)
[2018/01/20 0:22:44] Found the following functions:
[2018/01/20 0:22:44] <Functions'Name>.TranslatorAPI.Run
[2018/01/20 0:22:44]
[2018/01/20 0:22:44] Job host started
[2018/01/20 0:22:44] Host lock lease acquired by instance ID '<ID>'.
Listening on http://localhost:7071/
Hit CTRL-C to exit...

虽然它无法读取http触发器类型的扩展名,但它成功生成了TranslatorAPI.Run。

那么这里会出现什么问题呢?

修改

我认为该方法无法获取连接字符串,因此我将方法参数更改为

public static void Run([QueueTrigger("Translator", Connection = "<ServiceBusInstanceName>_RootManageSharedAccessKey_SERVICEBUS")]string mySbMsg, TraceWriter log)

然后错误变为

[2018/01/20 1:32:57] Run: Microsoft.Azure.WebJobs.Host: Error indexing method 'TranslatorAPI.Run'. Microsoft.Azure.WebJobs.Host: Failed to validate Microsoft Azure WebJobs SDK <ServiceBusInstanceName>_RootManageSharedAccessKey_SERVICEBUS connection string. The Microsoft Azure Storage account connection string is not formatted correctly. Please visit https://go.microsoft.com/fwlink/?linkid=841340 for details about configuring Microsoft Azure Storage connection strings.

现在看来,根据Azure存储帐户的连接字符串验证,我的ServiceBus连接字符串是错误的。我不确定如何理解这个含义是什么并解决了这个问题。

1 个答案:

答案 0 :(得分:1)

看起来QueueTrigger的连接字符串实际上是服务总线连接字符串。 QueueTrigger连接字符串应采用以下格式:pip install -r requirements.txt

如果您确实想使用服务总线队列,可以尝试使用ServiceBusTrigger代替!