New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I configure an Azure Function triggered by Service Bus with a custom INameResolver? #345
Comments
I'm linking this to Azure/azure-functions-host#1579 -- we can start treating that as our tracking issue for a 'Dependency Injection' solution. |
FYI that you can use IBinder instead. See https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#binding-at-runtime-via-imperative-bindings. |
@lindydonna Thanks, I've added a comment to that article, perhaps you could have a look rather than me duplicating it here? |
@tjrobinson That's a good question, I don't know the answer. @brettsam could you reply? |
@brettsam Any chance of your help with this? How can I set the subscription name when using I can set the topic name using Is it supported or not? This is the code I have so far: public static class ProcessEventUpdateFunction
{
[FunctionName("ProcessEventUpdate")]
public static async Task Run(Binder binder, TraceWriter log)
{
string topicName = ("eventupdates" + Environment.MachineName).ToLowerInvariant();
var attributes = new Attribute[]
{
new ServiceBusAccountAttribute("AzureWebJobsServiceBus"),
new ServiceBusAttribute(topicName, AccessRights.Listen),
};
string message = await binder.BindAsync<string>(attributes); Before I had this, but it didn't allow the topic name to be customised at runtime: public static class ProcessEventUpdateFunction
{
// When running locally, change "eventupdates" to "eventupdatesYOURMACHINENAME" to avoid sharing the same topic as others
[FunctionName("ProcessEventUpdate")]
public static async Task Run([ServiceBusTrigger("eventupdates", "casemanager", AccessRights.Listen)]string message, TraceWriter log)
{ |
@tjrobinson I tried that and it didn't work:
|
@ichivers That's the problem, it doesn't work. My code is just my attempt so far. |
@lindydonna, @brettsam, anyone - please could you help with this? All I want to do is be able to use C# code to determine the name of my Service Bus topic name at runtime. I've looked at all the documentation I can find but nothing covers this. My latest attempt:
This errors with:
|
This gets me close, but I still need to edit a file rather than making it dynamic:
|
@tjrobinson, @lindydonna, @brettsam Anyone find an answer for @tjrobinson? We have the exact same situation: Configure a Service Bus topic name trigger at runtime (and also subscription filter, hopefully). Abandoning trying to use a Service Bus trigger and wrapping a C# Service Bus client in a Durable function would probably be a work-around, but that's not nearly as clean as being able to change the trigger configuration at runtime. Thanks! |
@zsmorris Take a look a this extremely useful blog post: https://blog.wille-zone.de/post/azure-functions-dependency-injection/ I've used the above to successfully inject other dependencies, just not the specific one in my original post yet (due to lack of time and other priorities). Though I'm going off Azure Functions and will probably be migrating to Web Jobs soon, due to this issue: Azure/azure-functions-host#992 (comment) |
Thank you, @tjrobinson. Some sobering caveats discussed there. |
Can't https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#binding-expressions---app-settings be used for the purpose. |
2 years later and no solution? |
as suggested by @tjrobinson you can use dependency injection |
This is quite an old issue and I suspect it's no longer a problem in Azure Functions 3. You might also like to try FunctionMonkey which sits on top of Azure Functions: https://functionmonkey.azurefromthetrenches.com/guides/serviceBus/topics.html |
Someone Please suggest, Can we pass dynamic connection in Azure service bus trigger in Azure Function 3 or only approach is need to be use FunctionMonkey. |
I'm also curious if we can make dynamic service bus input bindings. I'll look at the FunctionMonkey, but if this is doable without that dependency, I'd like to know. |
I want to be able to control the name of the Service Bus Queue or Subscription that my Azure Function reads from at run-time.
With WebJobs (which Azure Functions are based on) you could do this by implementing and configuring a custom
INameResolver
, see: https://stackoverflow.com/questions/33860550/how-to-have-a-configuration-based-queue-name-for-web-job-processingHowever, with Azure functions I have no access to
JobHostConfiguration
to wire up this custom resolver.Can I still use an
INameResolver
, and if so how?Cross-posted to https://stackoverflow.com/questions/44625782/how-can-i-configure-an-azure-function-triggered-by-service-bus-with-a-custom-ina
Thanks!
The text was updated successfully, but these errors were encountered: