How to get the configuration-based queue name for processing web jobs?

I have a webjob application to process a ServiceBus queue that works fine, with the following method:

public static void ProcessQueueMessage([ServiceBusTrigger("myQueueName")] BrokeredMessage message, TextWriter log)

However, I would like to be able to change the queue name without recompiling, for example, according to the configuration setting, can this be done?

+3
source share
2 answers

I found the implementation of INameResolver using the configuration setting from azure-webjobs-sdk-samples .

/// <summary>
/// Resolves %name% variables in attribute values from the config file.
/// </summary>
public class ConfigNameResolver : INameResolver
{
    /// <summary>
    /// Resolve a %name% to a value from the confi file. Resolution is not recursive.
    /// </summary>
    /// <param name="name">The name to resolve (without the %... %)</param>
    /// <returns>
    /// The value to which the name resolves, if the name is supported; otherwise throw an <see cref="InvalidOperationException"/>.
    /// </returns>
    /// <exception cref="InvalidOperationException"><paramref name="name"/>has not been found in the config file or its value is empty.</exception>
    public string Resolve(string name)
    {
        var resolvedName = CloudConfigurationManager.GetSetting(name);
        if (string.IsNullOrWhiteSpace(resolvedName))
        {
            throw new InvalidOperationException("Cannot resolve " + name);
        }

        return resolvedName;
    }
}
+4
source

, . INameResolver JobHostConfiguration.NameResolver. % myqueue% ServiceBusTrigger - INameResolver % myqeuue% - , , ..

+3

Source: https://habr.com/ru/post/1679618/


All Articles