How to set queue name configurable from app settings in Azure Service Bus Trigger Function?

Raj
Raj
Member
606 Points
25 Posts

I'm trying following Azure Service Bus Queue Triggered function as:

        [Function(nameof(DequeueMessageTrend))]
        public async Task Run(
            [ServiceBusTrigger("dev-field-queue",
            Connection = "SBNSConnectionString",
            IsBatched = true)]
            ServiceBusReceivedMessage[] messages)
        {
            try
            {
                _logger.LogInformation("Service Bus trigger batch started");

Can we add queue name in appsetting as configurable?

 

Views: 95
Total Answered: 2
Total Marked As Answer: 1
Posted On: 29-May-2024 21:50

Share:   fb twitter linkedin
Answers
Raj
Raj
Member
606 Points
25 Posts
         

Found solution, we can set it from env. variable in azure and in local debugging from local.setting.

we can reference the queue name as a setting (using the %settingName% syntax) for App Function? Then in each function app you deploy have change the setting to the required queue name.

[Function(nameof(DequeueMessageTrend))]
        public async Task Run(
            [ServiceBusTrigger("%FieldQueue%",
            Connection = "SBNSConnectionString",
            IsBatched = true)]
            ServiceBusReceivedMessage[] messages)
        {
            try
            {
                _logger.LogInformation("Service Bus trigger batch started");

And specify the setting in local.settings.json for running locally

{
  "Values: {
     "FieldQueue": "dev-field-queue"
   }
}

In Azure:

  1. Go to overview page
  2. Select environment varriables
  3. Add new application setting

Posted On: 29-May-2024 22:30
Thanks for sharing solution. It's great!
 - Smith  30-May-2024 03:20
Brian
Brian
Moderator
2342 Points
13 Posts
         

Thanks for sharing solution.

Posted On: 30-May-2024 03:42
 Log In to Chat