Windows Azure Service Bus Topic is a great service that provide as the ability to distribute a message to more than one subscriber. When we publish a message to Service Bus Topic we don’t need to know how many subscribers are. Each subscriber can register to a topic and receive the messages (each subscriber can define custom rules – to filter what kind of message he wants to receive).
But how can we check if a message will be received by at least one subscriber. When we publish a message we don’t know who will receive the message, because of this we need a way to know what messages were not received by anyone. In this current implementation of Service Bus Topic, when a message is send to the Service Bus Topic and the current messages is not accepted by any subscriber, the message is not persisted in the Topic. Because of this the message will be lost and we will not be notifies about this action.
Service Bus Topic give us the ability to be notifies when we send a message to the Service Bus Topic and will not be received by any subscriber. When we create the topic, we need to set the “EnableFilteringMessagesBeforePublishing” to TRUE. In this moment when we will send a message to the topic, Windows Azure will check if there are subscribers for these messages. When there are subscribers everything will go as normal, but when there will be 0 subscribers for our message, a NoMatchingSubscriptionException will be throw. This exception will notify us that there are not subscribers for our client and we will be able to take any kind of action.
To create a topic with this setup we need to do the following:
We saw the mechanism that Windows Azure offer to us the detect messages that don’t have at least one subscriber. If we don’t need to know and detect them we can set this flag to FALSE. This is a great mechanism that is very easy to use.
But how can we check if a message will be received by at least one subscriber. When we publish a message we don’t know who will receive the message, because of this we need a way to know what messages were not received by anyone. In this current implementation of Service Bus Topic, when a message is send to the Service Bus Topic and the current messages is not accepted by any subscriber, the message is not persisted in the Topic. Because of this the message will be lost and we will not be notifies about this action.
Service Bus Topic give us the ability to be notifies when we send a message to the Service Bus Topic and will not be received by any subscriber. When we create the topic, we need to set the “EnableFilteringMessagesBeforePublishing” to TRUE. In this moment when we will send a message to the topic, Windows Azure will check if there are subscribers for these messages. When there are subscribers everything will go as normal, but when there will be 0 subscribers for our message, a NoMatchingSubscriptionException will be throw. This exception will notify us that there are not subscribers for our client and we will be able to take any kind of action.
To create a topic with this setup we need to do the following:
NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString([connectionString]);
namespaceManager.CreateTopic(
new TopicDescription([topicName])
{
EnableFilteringMessagesBeforePublishing = true
});
When we send the message we will need to cache “NoMatchingSubscriptionException” exception and do our custom action.We saw the mechanism that Windows Azure offer to us the detect messages that don’t have at least one subscriber. If we don’t need to know and detect them we can set this flag to FALSE. This is a great mechanism that is very easy to use.
"Service Bus has one feature that is used specifically for development which should never be used in production configurations: TopicDescription.EnableFilteringMessagesBeforePublishing."
ReplyDeletehttps://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-performance-improvements#development--testing-features