Azure WebJobs SDK ServiceBus连接字符串'AzureWebJobsAzureSBConnection'丢失或为空 [英] Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsAzureSBConnection' is missing or empty

查看:158
本文介绍了Azure WebJobs SDK ServiceBus连接字符串'AzureWebJobsAzureSBConnection'丢失或为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2015中创建了一个Azure Function应用程序.该应用程序具有服务总线队列的触发器.当我在本地运行该应用程序时,它运行完美.它能够从Service Bus队列中读取数据(通过名为AzureSBConnection的变量配置)并将其记录在我的数据库中.

I created an Azure Function App in Visual Studio 2015. The App has a trigger for service bus queues. The app works perfectly when I run it locally. It is able to read the data from the Service Bus queue (configured via a variable named AzureSBConnection) and log it in my database.

但是在Azure中部署它会给我以下错误:

But it gives me the following error when deployed in Azure:

函数($ ServiceBusQueueTriggerFunction)错误:Microsoft.Azure.WebJobs.Host:错误索引方法"Functions.ServiceBusQueueTriggerFunction". Microsoft.Azure.WebJobs.ServiceBus:Microsoft Azure WebJobs SDK ServiceBus连接字符串'AzureWebJobsAzureSBConnection'丢失或为空.

Function ($ServiceBusQueueTriggerFunction) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ServiceBusQueueTriggerFunction'. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsAzureSBConnection' is missing or empty.

请注意,我的连接称为AzureSBConnection,而不是AzureWebJobsAzureSBConnection.同样,该连接在本地工作.最后,部署的文件看起来与本地文件完全一样.

Note that my connection is called AzureSBConnection and not AzureWebJobsAzureSBConnection. Also, the connection works locally. And finally, the deployed file looks exactly like the local file.

Visual Studio结构如下:

The Visual Studio structure looks like the following:

function.json文件具有一系列设置,如下所示:

The function.json file has a bunch of settings as shown below:

然后在Appsettings.json文件中,我具有以下内容:

Then in the Appsettings.json file, I have the following:

为了进行部署,我将文件通过FTP传输到Azure中的功能应用程序的D:\ home \ site \ wwwroot位置. Kudu中的最终结构如下:

For deploying, I FTPed the files to the D:\home\site\wwwroot location for my Function App in Azure. The final structure in Kudu looks like:

如果我进入函数文件夹,

And if I go inside my function folder:

这是部署的function.json:

Here is the deployed function.json:

这是部署的应用程序设置:

And here is the deployed appsettings:

部署的json文件与本地文件完全相同.但是由于缺少AzureWebJobsAzureSBConnection,因此部署的版本出错了.我究竟做错了什么?

The deployed json files are exactly the same as the local files. But the deployed version is erroring out because of the missing AzureWebJobsAzureSBConnection. What am I doing wrong?

推荐答案

应用设置和连接字符串仅支持环境变量.

Only environment variables are supported for app settings and connection strings.

您需要确保在门户网站的功能"应用程序设置中设置了环境变量AzureWebJobsAzureSBConnection:

You need to make sure that the environment variable AzureWebJobsAzureSBConnection is set on your Function's app settings in the portal:

,然后在其中添加具有正确连接字符串的AzureWebJobsAzureSBConnection变量:

and then once there, you need to add the AzureWebJobsAzureSBConnection variable with the proper connection string:

,然后您可以通过以下方式通过代码进行访问:

and then you can access this via code by:

Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);

这将从appsettings.json或环境变量中获取值,具体取决于函数从何处执行(本地调试或在Azure上部署)

This will obtain the value from either the appsettings.json or the environment variable depending on where the function is being executed from, (local debugging or deployed on Azure)

这篇关于Azure WebJobs SDK ServiceBus连接字符串'AzureWebJobsAzureSBConnection'丢失或为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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