How to have a configuration based queue name for web job processing?

爱⌒轻易说出口 提交于 2019-12-04 10:14:34

I've found an implementation of the INameResolver using configuration setting from the 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;
    }
}

Yes, you can do this. You can implement your own INameResolver and set it on JobHostConfiguration.NameResolver. Then, you can use a queue name like %myqueue% in our ServiceBusTrigger attribute - the runtime will call your INameResolver to resolve that %myqeuue% variable - you can use whatever custom code you want to resolve the name. You could read it from app settings, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!