{"id":148,"date":"2023-06-27T05:29:55","date_gmt":"2023-06-27T04:29:55","guid":{"rendered":"https:\/\/ishooscode.com\/?p=148"},"modified":"2023-07-05T07:13:37","modified_gmt":"2023-07-05T06:13:37","slug":"test-azure-service-bus-trigger","status":"publish","type":"post","link":"https:\/\/ishooscode.com\/index.php\/2023\/06\/27\/test-azure-service-bus-trigger\/","title":{"rendered":"How to trigger azure service bus trigger functions from postman"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>Development process is equally important aspect of a SDLC as testing. Testers and developers often face this issue when it comes to testing azure service bus trigger functions or any non-http trigger functions. In order to test azure service bus trigger function apps before deployment, 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.<\/p>\n\n\n\n<p>Microsoft provides an out of the 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. It is easy to and does not require any additional code or infra changes. Following are the steps to do it.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized is-style-default\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/ishooscode.com\/wp-content\/uploads\/2023\/07\/PostmanToFAFlowDiagram.png\" alt=\"Request flow diagram\" class=\"wp-image-276\" width=\"621\" height=\"248\" srcset=\"https:\/\/ishooscode.com\/wp-content\/uploads\/2023\/07\/PostmanToFAFlowDiagram.png 621w, https:\/\/ishooscode.com\/wp-content\/uploads\/2023\/07\/PostmanToFAFlowDiagram-300x120.png 300w\" sizes=\"(max-width: 621px) 100vw, 621px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Steps<\/h2>\n\n\n\n<p><strong>1.<\/strong>&nbsp;Note down the service bus trigger name of the function app<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/f4n3x6c5.stackpathcdn.com\/article\/how-to-trigger-service-bus-trigger-function-app-from-postman\/Images\/image-20230622134724-1.png\" alt=\"Test azure queue trigger\"\/><\/figure>\n\n\n\n<p>In our case name is <strong>onsb-message-received<\/strong><\/p>\n\n\n\n<p><strong>2.&nbsp;<\/strong>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&nbsp;<strong><a href=\"http:\/\/<localhostaddress>\/admin\/functions\/onsb-message-received&#8221;>http:\/\/&lt;localhostaddress&gt;\/admin\/functions\/onsb-message-received<\/a><\/strong><\/p>\n\n\n\n<p><strong>3.<\/strong>&nbsp;Identify the localhost address on which your function app is running. In the console panel of the function app, you can find a statement \u201cRegistered SignalR trigger Endpoint =<strong>&nbsp;<a href=\"http:\/\/localhost:7071\/runtime\/webhooks\/signalr\" rel=\"nofollow\" title=\"\">http:\/\/localhost:7071\/runtime\/webhooks\/signalr<\/a>\u201d&nbsp;<\/strong>Hostname can be used from that url directly.<\/p>\n\n\n\n<p><strong>4.&nbsp;<\/strong>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.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/f4n3x6c5.stackpathcdn.com\/article\/how-to-trigger-service-bus-trigger-function-app-from-postman\/Images\/step4.jpg\" alt=\"azure service bus trigger\"\/><\/figure>\n\n\n\n<p>The body should be in this format only.<\/p>\n\n\n\n<p><strong>5.<\/strong>&nbsp;Sending request from the Postman.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/f4n3x6c5.stackpathcdn.com\/article\/how-to-trigger-service-bus-trigger-function-app-from-postman\/Images\/step5.jpg\" alt=\"trigger service\"\/><\/figure>\n\n\n\n<p>As soon as send is clicked, we get 202 Accepted responses which indicates that request is successfully delivered to endpoint. Note: If you are doing this for the first time request may take 1 minute to trigger function.<\/p>\n\n\n\n<p><strong>6.&nbsp;<\/strong>Put a breakpoint at the code to see the flow.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/f4n3x6c5.stackpathcdn.com\/article\/how-to-trigger-service-bus-trigger-function-app-from-postman\/Images\/step6.jpg\" alt=\"trigger service\"\/><\/figure>\n\n\n\n<p>Here you can see the message sent from the Postman is received.<\/p>\n\n\n\n<p>This way, we can easily test non-http triggers easily. Cheers!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Development process is equally important aspect of a SDLC as testing. Testers and developers&#8230;<\/p>\n","protected":false},"author":1,"featured_media":152,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[34,21,35],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/posts\/148"}],"collection":[{"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":4,"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":278,"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/posts\/148\/revisions\/278"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/media\/152"}],"wp:attachment":[{"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ishooscode.com\/index.php\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}