Enterprise Integration Patterns with Service Bus (Part 2)
The scenario here is that a receiver is interested in receiving messages in order of priority for a single or multiple senders. A common use cases for this is event notification, where critical alerts need to be processed first. Today Service Bus Queues do not have the capability to internally sort messages by priority but we can achieve this pattern using Topics and Subscriptions.
We achieve this scenario by routing messages with different priorities to different subscriptions. Routing is done based on the Priority property that the sender adds to the message. The recipient processes messages from specific subscriptions and thus achieves the desired priority order of processing.
The Service Bus implementation for this is thru use of SQL Rules on Subscriptions. These Rules contain Filters that are applied on the properties of the message and determine if a particular message is relevant to that Subscription.
Service Bus Features used:
1. SQL Filters can specify Rules in SQL 92 syntax
2. Typically Subscriptions have one Rule but multiple can be applied
3. Rules can contain Actions that may modify the message (in that case a copy
of the message is created by each Rule that modifies it)
4. Actions can be specified in SQL 92 syntax too.
The code sample for this is available here.