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

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

问题描述

我在 Visual Studio 2015 中创建了一个 Azure 函数应用程序.该应用程序具有服务总线队列的触发器.当我在本地运行该应用程序时,它可以完美运行.它能够从服务总线队列中读取数据(通过名为 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 中的 Function App 的 D:homesitewwwroot 位置.Kudu 中的最终结构如下所示:

For deploying, I FTPed the files to the D:homesitewwwroot 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:

这是部署的应用设置:

部署的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天全站免登陆