Service bus Subscribers can define which messages they want to receive from a topic.
These messages are specified in the form of one or more named subscription rules. Each rule consists of a filter condition that selects particular message
Correlation Filter:
This filter focusses on message`s user and system properties.
For instance, in the below screenshot , the subscription carries the filter for the label .
There are other properties available
Label = "Important";
ReplyTo = "johndoe@contoso.com";
filter.Properties["color"] = "Red";
So how to apply this filter in the message?
I have used logic apps to filter the message :
Similar options are available in advanced parameters
Now , when the message is sent, only the subscription where this filter is applied and the subscription which doesn’t have any filter will receive the message.
For instance, I have created another subscription without any filter.
When I trigger the logic apps via the postman message
The logic apps acts as sender to the topic subscription
Once the execution is completed, user would see the messages in both the subscriptions. This is because the subscription without filter would receive this message as well.
I have another logic apps which acts as a receiver to process the message .
This receiver processes the messages in ‘CorrelationFilterSubscription’. Thus the message in the NoFilter subscription remains there.
SQL Filter:
A SqlFilter holds a SQL-like conditional expression that is validated in the messages’ user-defined properties and system properties.
All system properties must be prefixed with sys.
in the conditional expression.
System properties filter
sys.label LIKE '%bus%'
sys.messageid = 'xxxx'
sys.correlationid like 'abc-%'
User properties filter
MessageProperty = 'A'
user.SuperHero like 'SuperMan%'
MessageProperty = 1
MessageProperty > 1
MessageProperty > 2.08
MessageProperty = 1 AND MessageProperty2 = 3
MessageProperty = 1 OR MessageProperty2 = 3
Thus , when the label in the logic apps carries this SQL value, the FilterSubscription receives the message.
When the message is received by the topic, both NoFilter and SQLFilter subscriptions receive the messages. Correlation subscription doesnt receive as the filter was not applicable.
Thus using the filters, Azure Service Bus leverages the broadcasting of messages which makes sure only the intended recipient receives the message.