1

I have an Azure Function App that has ServiceBusTrigger binding.

public static void Run([ServiceBusTrigger("my-queue")]string request, TraceWriter log)

I would like to debug it locally without having to connect to an Azure Service Bus; however, there's no ASB Emulator available (Using Azure Service Bus in local). Thus, my next effort is to switch to Storage Queue (as I am having Azure Storage Emulator running on my device) when debugging it locally only.

public static void Run([QueueTrigger("my-queue")]string request, TraceWriter log)

My question is: Do we have a way to define binding as such it will listen to Storage Queue on local environment, but will switch to Service Bus when deployed to production?

This sounds like XY problem, so if anyone has better idea to solve my X problem, I'm all ears.

Harry Ninh
  • 16,288
  • 5
  • 60
  • 54
  • you can test your Non-Http triggered function using an admin endpoint, see more details https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local#run-functions-locally also your function can be decorated with DisableAttribute and controled by local.settings.json variable. – Roman Kiss Jan 10 '18 at 17:37
  • Hey that's new to me. Will try it out and see if I can connect my main web app with Azure Functions by using that admin endpoint. – Harry Ninh Jan 10 '18 at 22:52

1 Answers1

2

Substitution of trigger type based on configuration is not supported. So, you'd have to make a workaround somewhere. Options:

  1. Use Service Bus for testing, but a different namespace or queue name. Connection string is part of the App Settings, so you can set it up per environment. You can make queue name configurable by using ServiceBusTrigger("%my-queue%"), in which case app will be searching for my-queue app setting.

  2. You can move function body to a shared method, and then create two otherwise equal Azure Functions: one with Service Bus trigger, one with Storage Queue trigger. Add Disable attribute to both of them, and make this attribute declare a setting name. If that setting is set to true, the function will get disabled. Disable one or the other function based on environment.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • I'm using (1) btw, but it's going to be hard to share the code with fellow developers, as each of us needs to create our own queue to help with local development, and ASB is managed by another team (DevOps). (2) seems promising though. I'll try that, thanks. – Harry Ninh Jan 10 '18 at 22:48