Integration Patterns In Azure – Message Router Using Service Bus

In the previous post, we have seen how we can implement the Message Router pattern when working with Logic Apps. As discussed, Logic Apps are a great fit if you have a limited set of endpoints to which you want to route the message, and if you have a need for various connectors. In this post we will look into another technology to implement this pattern, Azure Service Bus Topics. Topics are a great solution if we want to implement a publish / subscribe mechanism.

  • Capability to send our messages to one or more subscriptions in our topic.
  • Each subscription represents a virtual queue, from where subscribers can pull their messages, allowing receiving systems to process messages at their own speed.
  • Receiver and sender are completely decoupled, so systems can work independently from each other.
  • Topics have dead-lettering capabilities built in, so messages are not lost even in case of issues.
  • Easily add new subscriptions, so we can quickly on-board new systems.
Azure Service Bus Topics

Azure Service Bus Topics

Scenario

For this sample, we will be implementing a postal carrier system, where customers can place requests for deliveries. There are various types of deliveries, each with its own speed and pricing model. Depending on the type of delivery requested, it will be sent to a specific warehouse, where they will be picked and shipped from.

Scenario

Scenario

Implementation

When working with Service Bus, we first have to create a namespace in which our topics and queues reside. As we are going to be using Topics, we need to at least have the Standard tier.

Create Service Bus Namespace

Create Service Bus Namespace

We can then create our topics, either from the portal, with Service Bus Explorer, or my personal favorite, by using ServiceBus360. Using the tool of your preference, create a new Topic.

Create Service Bus Topic

Create Service Bus Topic

Now that we have our topic, we can create our subscriptions. We will create one logging subscription, which will receive a copy of each incoming message, and three subscriptions for the different warehouses.

Create Topic Subscriptions

Create Topic Subscriptions

And finally we set the subscription filters (currently not supported in ServiceBus360, but should be coming soon). Filtering is done on the priority defined in the message properties, using a SQL-like filtering language.

Set Subscription Filters

Set Subscription Filters

Testing

Now that we have our topic with its subscriptions in place, we can test our solution by sending messages to the topic. We can use ServiceBus360 for this as well, as it allows us to send messages with specific properties into our Service Bus entities. The messages we will be sending are as following.

{
    "Address":"Kings Cross 20",
    "City":"New York",
    "Name":"Eldert Grootenboer"
}
Send Message Into Topic

Send Message Into Topic

Once we have sent in a couple of messages, we can check our subscriptions, and see that the messages were indeed routed to the correct subscriptions, from which the receiving systems can retrieve them.

Subscriptions Overview

Subscriptions Overview

Message Content

Message Content

Template

You can easily deploy this solution from the Azure Quickstart Templates site, or use the below button to directly deploy this to your own Azure environment.

Leave a Reply

Your email address will not be published. Required fields are marked *