logikfabrik

How to debug a Service­Bus­Trigger Azure Function in VS

1 min read

Here are two ways of debugging a ServiceBusTrigger Azure Function.

Open up VS, set a breakpoint in your Azure Function and start debugging. Sign in to the Azure Portal, go to your Service Bus, and send a message to it using the Service Bus Explorer. Your function will be triggered by your Service Bus and the breakpoint will be hit.

Or:

Open up VS, set a breakpoint in your Azure Function and start debugging. Do a POST to your function’s administrator endpoint, see the Azure Functions documentation.

POST http://localhost:7071/admin/functions/FunctionName
Content-type: application/json

{
  "input": ""
}

Your function will be called as if triggered by your Service Bus and the breakpoint will be hit.

namespace Logikfabrik.AzureFunction
{
  using Microsoft.Azure.WebJobs;

  public static class Function
  {
    [FunctionName("FunctionName")]
    public static void Run([ServiceBusTrigger("QueueName", Connection = "ServiceBusConnectionStringName")] string message)
    {
    }
  }
}

message has to be typed as string in your function signature, and not as Microsoft.Azure.ServiceBus.Message. Or else your function won’t be called.

That’s it!