Respond to Service Bus Events with Event Grid + Logic Apps
Event Grid is Azure’s event routing service. It enables applications to react to events in near real time by connecting publishers and subscribers in a clean and scalable way.
An event is simply a fact that something has happened. Event Grid takes those facts from publishers, such as Azure Blob Storage, Service Bus, or even a custom application, and delivers them to subscribers like Logic Apps, Azure Functions, or Event Hubs. The delivery is push-based, so there is no need for polling or constant checks.
Imagine a scenario where customer orders are sent into a Service Bus queue. Without Event Grid, a Logic App would need to keep checking for new messages.
Can you use direct integration with Service Bus? It works, but here's the catch: under the hood, Logic Apps are polling the queue. That means some added latency, and possible double processing of same message.
With Event Grid in place, the moment a new order arrives, an event is raised and pushed into your workflow. From there, you can automatically notify your operations team in Microsoft Teams, call an Azure Function to validate and enrich the order, or record the details in Microsoft Dataverse for business tracking.
It is straightforward to set up and can be applied across many scenarios, so let’s get started.
We will follow this official Documentation from Microsoft:
1. Setup Service Bus (+ topic and subscription)
2. Send messages to the Service Bus topic
3. Create new Logic App to Receive messages
4. Add a step receive messages from Service Bus using Event Grid
The following two actions (5 & 6) are inside a foreach looping over the body of the messages received from the bus
5. Add a step to process received messages (Here, we send an email)
6. Add a step to complete received messages.
6. Test the app.
If you haven't already sent test messages to the topic, use the code in the step 2 to send test messages to the Topic.
Navigate to the Overview page of your logic app. Then select the Run history tab in the bottom pane. You see the logic app runs messages that were sent to the topic. It could take a few minutes before you see the logic app runs. Select Refresh on the toolbar to refresh the page.
Select a logic app run to see the details. Notice that it processed five messages in the for loop.
6. You should get an email for each message the logic app receives.
That’s all for today, see you in the next one.