How to Trigger Service Bus Trigger Function App from Postman?

Introduction

Testers and developers often face this issue when it comes to testing nonhttp trigger function apps. To test these kinds of Azure functions, most of them end up creating temporary http trigger function or push messages directly to the services bus queue/topic. There is nothing wrong with both solutions. They work as well as they can. But these solutions are erroneous and inefficient.

Microsoft provides a box technique to trigger a service bus trigger function app without pushing messages directly to the service bus queue. This is achieved through admin endpoints of a function app. Following the below steps.

Step 1. Note down the service bus trigger name of the function app

trigger service

In our case name is onsb-message-received

Step 2. Create a postman collection to send messages to this function. This postman collection will have a Post http method, and url will be something like http://<localhostaddress>/admin/functions/onsb-message-received

Step 3. Identify the localhost address on which your function app is running. In the console panel of the function app, you can find a statement “Registered SignalR trigger Endpoint = http://localhost:7071/runtime/webhooks/signalr” Hostname can be used from that url directly.

Step 4. Prepare message for request. The message body should be entirely in string format. If the app accepts a request in json format, then the request needs to be stringified first to be sent from Postman.

trigger service

The body should be in this format only.

Step 5. Sending request from the Postman.

trigger service

As soon as send is clicked, we get 202 Accepted responses which indicates that the request is successfully sent to the endpoint. Note: If you are doing this for the first time request may take 1 minute to trigger function.

Step 6. Put a breakpoint at the code to see the flow.

trigger service

Here you can see the message sent from the Postman is received.

This way, we can easily test non-http triggers easily. Cheers!


Similar Articles