By Sai Kiran Reddy Vallapreddy
I’m going to assume that you are familiar with Azure Service Bus topics/subscriptions, the publish-subscribe pattern and Azure Table Storage.
Let’s Code and Configure
In this article, I am working on an application for receiving messages from the Azure Service Bus Topic/subscription using Service bus trigger Azure Functions.
Please follow the below steps
We can use Azure to create a function app and functions, but right now I am using Visual studious -2017 for that.
In pictures 1,2,3 we need to open VS 2017 and open Azure functions in visual c# cloud.
Then You will get all the different types of triggers starting from time, Http, service bus topic, queue etc. In this article, I am taking the service Bus topic as the trigger. The new Azure function has an attribute which is used to define the client for the topic subscription. The service bus connection string is defined as Service Bus Connection String. This will be specified later. The message is then deserialized to an object. Now you can handle the payload as required.
Now copy the Connection string, topic name, subscription name that you got from service bus topic in azure as shown above, and follow steps in the below URL to create service bus topic.
C-Sharpcorner: Azure Service Bus Topics
In the above image, you will notice the function app that has service bus topic trigger. Please add a Topic name, subscription name, and connection in local.json settings. Once the message comes to the subscription the azure function will run and will call the method as shows (AzureSBtest). where I am sending the files to Blob and Cosmos DB.
The above image shows how we are reading each message from the SBQ and sending to Cosmos and Archive.
The above image shows all the functions in the function app.
Tips: Use Service Bus Explorer to see the messages in Subscription and you can also purge the messages, send to the dead letter and copy and see the message. After all the subscriptions are read, and the functions finish processing the in- and outgoing request in the live metrics of the Application Insights drop to zero.