0

I have function that receive ServiceBusTrigger message:

public static void ProcessQueueMessage([ServiceBusTrigger("mysb")] string message)
{
    // do something with message
}

when I send message to "mysb" Azure Que - this function start to work.

My question is: Can I take the Que name from the App.config?

ZoharYosef
  • 247
  • 1
  • 2
  • 11

3 Answers3

2

As a complement to sebbrochet's answer, you'll probably have to implement a custom INameResolver to get the value from the app.config file as this GitHub issue suggests.
https://github.com/Azure/azure-webjobs-sdk/issues/581
Just use %paramname% in the ServiceBus param when you want your custom resolver to kick in.
Hope that helps.

baywet
  • 4,377
  • 4
  • 20
  • 49
1

This SO question seems to answer your question.

You'll use this code: Microsoft.WindowsAzure.CloudConfigurationManager.GetSettings("QueueName")

With this kind of code in your app.config file:

<configuration>
  <appSettings>
   <add key="QueueName" value="mysb"/>
  </appSettings>
</configuration>
Community
  • 1
  • 1
sebbrochet
  • 129
  • 2
1

Just an implementation of @Baywet's answer which I found here by @dprothero.

In your Program.cs file's Main Method, while registering Microsoft.Azure.WebJobs.JobHostConfiguration provide an implementation of INameResolver to NameResolver property like

static void Main()
{
    var config = new JobHostConfiguration
    {
        NameResolver = new QueueNameResolver()
    };

    //other configurations
}

and the QueueNameResolver class is like

public class QueueNameResolver : INameResolver
{
    public string Resolve(string name)
    {
        return ConfigurationManager.AppSettings[name].ToString();
    }
}

Now add a key in <appSettings> section of App.config file like

<appSettings>
    <add key="QueueName" value="myqueue" />
</appSettings>

and use it like

 public async Task ProcessQueueMessage([ServiceBusTrigger("%QueueName%")] BrokeredMessage receivedMessage)
Hamza Khanzada
  • 1,439
  • 1
  • 22
  • 39