azure-functions-dotnet-worker: ServiceBusTrigger and INameResolver
Hello,
Is it still possible to pass dynamic queue name to Service Bus trigger? Previously INameResolver was used for that, but the new extension is missing this interface.
public class QueueNameResolver : INameResolver
{
public string Resolve(string name)
{
return ConfigurationManager.AppSettings[name].ToString();
}
}
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 5
- Comments: 21 (3 by maintainers)
This is a blocker for us moving from Web Jobs to Azure Functions.
Is there any update here? It seems I can’t even put my queue names in a separate ‘queue-names.json’ file
eg
If the queue names are in
queue-names.jsonthen it simply doesn’t work. They have to be inlocal.settings.json@dhermyt I totally agree we should be able to inject our custom NameResolver like we can with the “normal” Azure Functions (called now class library AFAIK).
https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#version-3x-6
But have in mind that the Isolated mode does implement a the default NameResolver es mentioned here https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#custom-binding-expressions
“There’s a default NameResolver that takes effect if you don’t provide a custom one. The default gets values from app settings or environment variables.”
So, while it’s not as powerful and flexible as a custom NameResolver, it may work for you as the default behaviour is reading from an appsetting/enviromentvariable.
So this:
reads the queue name from a configuration setting / enviroment variable called myqueueName. I have tested this myself both locally and in Azure.
I insist, we should be able to inject our custom NameResolver for max flexibility
Hello Fabio,
In my case the queue name comes from the configuration and should be set dynamically. This is how it looked in the previous SDK:
Here is the example on SO: https://stackoverflow.com/a/30515085
I’m looking for clarification. With
ServiceBusTrigger, the value given toConnectionis used to get the connection string fromIConfiguration. This works as documented.However, if you use the
% %syntax fortopicNameandsubscriptionName, it only pulls those values from the environment variables, NOT fromIConfiguration. I have seen several statements in documentation (and in issues of this repo) that state these values are pulled from configuration when the value begins and ends with%, but based on my testing, that isn’t true.Please let me know if I’m incorrect and if anyone has been able to set these values from
IConfiguration. FYI, if you set the values inlocal.settings.jsonwhen running locally, those become environment variables at runtime.I have added my code to Stack Overflow here : https://stackoverflow.com/questions/78897966/azure-functions-trigger-variables-isolated-functions/78897967#78897967
Please upvote, question and answer, if useful.
I agree - I’m going to try and do a blog post on how I worked around this - but it’s convoluted, build step, generate local.settings.json for each user. Honestly, such a lot of work for something that should be so simple!