我有这个azure function
应该read a message from service bus queue.
我已经给连接字符串指定了代码,但是在运行func时仍然抛出错误-
Set the connection string named 'Endpoint=sb://demoser
vicebus2019.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKe
y;[Hidden Credential]' in the connectionStrings section of the .config file in t
he following format <add name="Endpoint=sb://demoservicebus2019.servicebus.windo
ws.net/;SharedAccessKeyName=RootManageSharedAccessKey;[Hidden Credential]" conne
ctionString="DefaultEndpointsProtocol=http|https;AccountName=NAME;AccountKey=KEY
代码- Function1.cs
public static class Function1
{
[FunctionName("Function1")]
public static void Run([QueueTrigger("customer", Connection = "Endpoint=sb://demoservicebus2019.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=text")]string myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
}
}
local.setting.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "storageaccount-connectionstring",
"AzureWebJobsDashboard": "storageaccount-connectionstring"
}
}
答案 0 :(得分:2)
因此,连接属性是环境/配置变量的键,而不是实际的连接字符串。
您可以了解有关绑定here
包含用于此绑定的存储连接字符串的应用程序设置的名称
因此将其更改为此:
public static class Function1
{
[FunctionName("Function1")]
public static void Run([QueueTrigger("customer", Connection = "MyConnection")]string myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
}
}
配置
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "storageaccount-connectionstring",
"AzureWebJobsDashboard": "storageaccount-connectionstring"
"MyConnection":"Endpoint=sb://demoservicebus2019.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=text"
}
}