16

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="/>
chuckd
  • 13,460
  • 29
  • 152
  • 331

1 Answers1

37

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.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • how can this be set to a variable such as from ConfigurationBuilder's ConfigurationRoot? – roberto tomás Mar 24 '20 at 02:48
  • Do you have a link to documentation where this is stated? It doesn't really make sense to me that a string defining means to connect isn't considered a connectionString – Marvin Brouwer Apr 09 '21 at 14:28
  • @MarvinBrouwer, Here is the doc that states that the connection string is the name of the setting: [Service Bus Trigger Annotations](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=in-process%2Cextensionv5&pivots=programming-language-java#annotations) – Redbeard Mar 24 '23 at 22:17
  • @Redbeard, thanks. I still think the description is a bit ambiguous in the docs. But, there's nothing you can do about that. It's almost comical to me that this is solved in this way, by the same people who gave us [`GetConnectionStringOrSetting`](https://github.com/Azure/azure-webjobs-sdk/blob/dev/src/Microsoft.Azure.WebJobs.Host/Extensions/IConfigurationExtensions.cs#L79) – Marvin Brouwer Apr 18 '23 at 13:10