HobojoeBr
HobojoeBr

Reputation: 619

Azure Webjobs - Define QueueName trigger on app.config

With the new release of Azure Webjobs 3.0.0 SDK it was announced the: http://azure.microsoft.com/blog/2014/06/18/announcing-the-0-3-0-beta-preview-of-microsoft-azure-webjobs-sdk/

Improved function discovery

We added an ITypeLocator and INameResolver to enable customizing how the WebJobs SDK looks >for functions. This enables scenarios such as the following:

  1. You can define functions where the QueueName is not explicit. You can read Queue names from a config source and specify this value at runtime.
  2. Restrict function discovery to a particular class or assembly.
  3. Dynamic functions at indexing time: you can define the function signature at runtime.

But there's no sample code on how to do it.

Does anyone know how to define the queue name at runtime (e.g. from app.config)?

Upvotes: 1

Views: 1356

Answers (2)

OzBob
OzBob

Reputation: 4530

To use an external runtime service to define the name of the queue:

public class QueueNameResolver : INameResolver
{
    public string Resolve(string practiceId)
    {
        //define in appsettings the queuename property
        return CloudConfigurationManager.GetSetting("queuname");
        //or some other service of your design
    }
}

In the WebJob Code, Program.cs:

    public void init()
    {
        // Retrieve storage account from connection string.            
        string azureJobStorageConnectionString = ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString;
        var config =
               new JobHostConfiguration(azureJobStorageConnectionString)
               {
                   NameResolver = new QueueNameResolver()
               };
        host = new JobHost(config);
        host.RunAndBlock();
    }

as per azure doco

Upvotes: 0

Rasmus Christensen
Rasmus Christensen

Reputation: 8541

If you take advantage of the new INameResolver in the configuration you can make your own implementation of the interface and replace it in the JobHostConfiguration. Take a look at this blog post where I made a small POC on the topic.

Upvotes: 2

Related Questions