Is there anyway for azure to route messages to appropriate handler/operation/subscriber based on the message type?
In NServiceBus, when an event is publishedd, only subscribers that can handle the event will be called. How does Azure service bus achieve this, given that WCF is an RPC framework and is not particularly "message oriented" which tends to have
That being said should I send a message of Type MyMessage
, how would the AzureServiceBus know only to pass this message to MyMessageHandler
WCF service? I could configure message properties and routing, but that is a real PITA when a simple convention like the one in NServiceBus would have worked really well for 99% of use cases.
You can use the CorrelationFilter in Service Bus for this. By default if you just specify a string then it matches with the CorrelationId property on the message. Alternatively you can specify values for any of the other system properties like ContentType or use your own user Properties for filtering.
Here is a blog post I wrote describing the different types of patterns you can use: http://abhishekrlal.com/2012/02/07/enterprise-integration-patterns-with-service-bus-part-1/
Following is a sample that showcases the use of different filters: http://code.msdn.microsoft.com/windowsazure/Brokered-Messaging-6b0d2749
// Create a topic and 3 subscriptions.
TopicDescription topicDescription = namespaceManager.CreateTopic(Program.TopicName);
Console.WriteLine("Topic created.");
// Create a subscription for all messages sent to topic.
namespaceManager.CreateSubscription(topicDescription.Path, SubsNameAllMessages, new TrueFilter());
Console.WriteLine("Subscription {0} added with filter definition set to TrueFilter.", Program.SubsNameAllMessages);
// Create a subscription that'll receive all orders which have color "blue" and quantity 10.
namespaceManager.CreateSubscription(topicDescription.Path, SubsNameColorBlueSize10Orders, new SqlFilter("color = 'blue' AND quantity = 10"));
Console.WriteLine("Subscription {0} added with filter definition \"color = 'blue' AND quantity = 10\".", Program.SubsNameColorBlueSize10Orders);
// Create a subscription that'll receive all high priority orders.
namespaceManager.CreateSubscription(topicDescription.Path, SubsNameHighPriorityOrders, new CorrelationFilter("high"));
Console.WriteLine("Subscription {0} added with correlation filter definition \"high\".", Program.SubsNameHighPriorityOrders);