D365: Service Bus Triggered Function error: Connection string ‘AzureWebJobsServiceBus’ is missing or empty

Recently, while working on Service Bus triggered Azure Durable Function, we got an error saying “The function runtime is unable to start. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string ‘AzureWebJobsServiceBus’ is missing or empty”.

Below is the code that we were using:

 [FunctionName("UpdateGlobalRatesOnRSLs")]
        public static async Task Run([ServiceBusTrigger("%QueueName%")] Message message, MessageReceiver messageReceiver, string lockToken, [OrchestrationClient]DurableOrchestrationClient starter, ILogger log)
        {
            string inputMessage = Encoding.UTF8.GetString(message.Body);
            log.LogInformation($"message - " + inputMessage);
            MessageReceiver receiver = messageReceiver;
            string token = lockToken;
}

NOTE: QueueName used above is defined in localsettings.json as a key/value pair to make it configurable.

We can fix this issue in couple of ways:

  • We can provide a Connection String name in the Service Bus Trigger attribute which will be defined in localsettings.json as shown below:
  [FunctionName("UpdateGlobalRatesOnRSLs")]
        public static async Task Run([ServiceBusTrigger("%QueueName%", Connection = "ServiceBusConnectionString")] Message message, MessageReceiver messageReceiver, string lockToken, [OrchestrationClient]DurableOrchestrationClient starter, ILogger log)
        {
            string inputMessage = Encoding.UTF8.GetString(message.Body);
            log.LogInformation($"message - " + inputMessage);
            MessageReceiver receiver = messageReceiver;
            string token = lockToken;
}

In localsettings.json:

{
  "IsEncrypted": false,
  "Values": {   
    "QueueName": "devglobalrateupdatequeue",
    "ServiceBusConnectionString": "[PrimaryConnectionStringOfSharedAccessPolicy]"
  }
}
  • It can be left blank in the Service Bus Trigger attribute and in localsettings.json file define a key/value pair with name AzureWebJobsServiceBus
[FunctionName("UpdateGlobalRatesOnRSLs")]
        public static async Task Run([ServiceBusTrigger("%QueueName%")] Message message, MessageReceiver messageReceiver, string lockToken, [OrchestrationClient]DurableOrchestrationClient starter, ILogger log)
        {
            string inputMessage = Encoding.UTF8.GetString(message.Body);
            log.LogInformation($"message - " + inputMessage);
            MessageReceiver receiver = messageReceiver;
            string token = lockToken;
}

In localsettings.json:

{
  "IsEncrypted": false,
  "Values": {   
    "QueueName": "devglobalrateupdatequeue",
    "AzureWebJobsServiceBus": "[PrimaryConnectionStringOfSharedAccessPolicy]"
  }
}

NOTE: During deployment of the Durable Function to Azure, create the above key/value pair application settings in Function App –> Function App Settings –> Manage Application Settings –> New Application Setting and Save them.

Hope it helps !!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.