10
votes

I have a Azure service bus queue trigger function and when I created it it asked me 3 fields, access rights, connection and queue name.

I put in listen for the access rights. For the connection I used the the 'primary connection' name given in the 'RootManageSharedAccessKey' in the service bus I created. It looks something like this

Endpoint=sb://yogaband2017.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=JG0gwJ90bkbGl1BU=

and I created a queue in my service bus called yogaband and that is what I used for the queue name as the third parameter.

My function looks like this

public static class PostEventEmails
{
    [FunctionName("PostEventEmails")]
    public static void Run([ServiceBusTrigger("yogaband2017", AccessRights.Listen, Connection = "Endpoint=sb://yogaband2017.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=gkbGl1BU=")]string myQueueItem, TraceWriter log)
    {
        log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
    }
}

When I publish the function I get this warning

.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): warning : Function [PostEventEmails]: cannot find value named 'Endpoint=sb://yogaband2017.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=0bkbGl1BU=' in local.settings.json that matches 'connection' property set on 'serviceBusTrigger' [C:\Users\Source\Workspaces\YogaBand2017\YogaBand2017\PostEventEmails\PostEventEmails.csproj]

and in my site I can pass the queue a message and I see the message in the queue in my Azure portal, but the function isn't picking up the message and processing it. So I still see '1 message' in the active message count in the queue. I assume it would be 0 after the function picks it up and processes it and I would see the log trace in the window? But I don't so I think the connection isn't correct or I didn't configure something correctly but I don't know what!

Here is what I put into the local.settings.json file

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "Endpoint=sb://yogaband2017.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=bGl1BU=",
"AzureWebJobsDashboard": ""}}

FYI - here is how I send the mesage to the queue in c#

 var queueClient = QueueClient.Create("yogaband2017");
            BrokeredMessage message = new BrokeredMessage("some test message");
            message.MessageId = newEvent.YogaSpaceEventId.ToString();

            queueClient.Send(message);

and in my web.config file I added this

<add key="Microsoft.ServiceBus.ConnectionString" value="Endpoint=sb://yogaband2017.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=0gwJ90bkbGl1BU="/>
1
Frankly, this is the top google result for this error, so kindly troll elsewhere @MikhailShilkovSSH This
@SSHThis It wasn't two years ago! :) Deleted the comment.Mikhail Shilkov

1 Answers

30
votes

Connection property of ServiceBusTrigger should be set to a setting name, not connection string itself:

[ServiceBusTrigger("yogaband2017", AccessRights.Listen, Connection = "MyConn")]

You then define a setting with this name in local.settings.json for local development environment:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "... azure storage connection string ...",
    "MyConn": "... service bus connection string ..."
  }
}

and in App Settings for Azure deployment.

Note that AzureWebJobsStorage is NOT service bus connection.