简体   繁体   中英

.NET class library as an Azure Function App with ServiceBusTopic trigger does not work

I created an Azure function app locally in Visual Studio 2017(Not Azure portal) by following the steps at the following URL.

https://blogs.msdn.microsoft.com/appserviceteam/2017/03/16/publishing-a-net-class-library-as-a-function-app

I followed the steps exactly to create a function that has a “ServiceBusTopicTrigger”. I added the following to my function.json

{
    “disabled”: false,
    “bindings”: [
        {
            “name”: “mySbMsg”,
            “type”: “serviceBusTrigger”,
            “direction”: “in”,
            “topicName”: “negotiatedaddcharge_test”,
            “subscriptionName”: “clientdispatches”,
            “connection”: “servicebusnac”,
            “accessRights”: “manage”
        }
    ]
}

My appsenttings.json has the following

{
    “IsEncrypted”: true,
    “Values”: {
        “servicebusnac”: “Endpoint=MyCompanyEndPointPlaceHolder”
    }
}

When I run the function in Visual Studio I keep getting an error message “Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsservicebusnac' is missing or empty.”

Just for the heck of it I added another entry to the values collection with the name “AzureWebJobsservicebusnac” but still the same message shows up. Is there something that I am doing wrong?

Also how do you unit test this function? I cannot Access any function in the csx file in my unit test project.

Thanks.

Edited: I added information to make it clear that I am creating the function in Visual Studio rather than the Azure portal.

Function App will search for your Service Bus connection strings in Environment variables. You can set those from Azure portal:

  1. Go to your Function App.
  2. Select Platform features tab above the editor.
  3. Click Application settings .
  4. Under App settings section add an entry with connection name and string.

The appsettings.json file is used to support local development only, and settings defined there are not published to Azure.

The solution is simple; I actually ran into this myself and it had me completely stumped for a while.

In your appsettings.json , change "IsEncrypted" from true to false . This should fix the issue you're seeing.

The error messages are less than ideal for this scenario; the Azure Functions team already has a bugfix in for it.

Hope this helps anyone who runs into this issue. (I swear, it was a week before I figured this out, and not without help.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM