Azure Service Bus has a feature to set up publish and subscribe type behavior in queues.  This is similar to how BizTalk Server worked when message are published to the messages box.

For now, forget all the bells and whistles like dead-lettering, sessions, duplicate detection, etc.  This is just going to focus on message routing.

To use dynamic message routing in the Azure Service Bus, you need to use a Topis and one or more Subscriptions. 

The Topic is essentially the endpoint to which you send a message.

Inside the Topic, you can have one or more Subscriptions with criteria to select inbound messages.  These Subscriptions are essentially independent queues.  

A message sent to a Topic is routed to a Subscription through a Filers setup on the Subscription.

These Filters have three types:

  •  SQL Filters
  • Correlation Filters
  • Boolean Filters (not covered here)

In the first two scenarios, the Filter conditions are evaluated against both System and User-defined properties.

The Boolean Filters are used to select all or none messages to a queue like setting 1=1.

System Properties are those the Service Bus uses internally.  These include properties like the following:

  • ContentType
  • CorrelationId
  • SessionID
  • DeliveryCount
  • LockedUntilUtc
  • LockToken
  • MessageId
  • Label
  • ReplyTo
  • EnqueuedTimeUtc
  • SequenceNumber
  • TimeToLive
  • To
  • ScheduledEnqueueTimeUtc
  • ReplyToSessionId
  • PartitionKey

Let’s dive deeper into working with SQL and Correlation Filters.

 

SQL Filters on Service Bus Subscriptions 

These are simple, SQL-like expressions that are used to select messages to arrive at a subscription.  These can use the following SQL conditions:

  • Exists
  • Is Null
  • Logical NOT AND OR
  • Relational operators
  • Simple numerical arithmetic
  • Simple text patterns with LIKE

If the condition evaluates to True the message is delivered to the Subscription.

To use System Properties, use the sys prefix.

Example: sys.label LIKE ‘%D1%’

To use User Properties, use the user prefix.

Example: user.sendto LIKE ‘%D1%’

 Important:  The property name is not case sensitive but the value is case-sensitive.

In the above example user.sendto and user.SENDTO are the same thing.  But ‘%D1%’ and ‘%d1%’

 

Correlation Filters on Service Bus Subscriptions 

Like SQL filters, correlation filters can be used against system and user properties.  Also, like SQL filters, the values are case-sensitive.  

The Correlation Filers are equal only.  If more than one condition is entered, it will create an AND condition with all of them.

Not all system properties can be used as a Correlation Filter. If you need to use a non-supported System Property, you can use it in a SQL Filter rather than a Correlation Filter.  

The System Prperties that can be used for routing include:

  • ContentType
  • Label
  • MessageId
  • ReplyTo
  • ReplyToSessionId
  • SessionId
  • To

In addition to these properties, any user-created properties can be used as well.

See this in action in the YouTube video below.

Looking for other Azure quick tips and tricks, check them all out here:  https://www.stephenwthomas.com/azure-integration-services-tips-and-tricks/

References