为此,您可以使用 Service Bus 中的CorrelationFilter。默认情况下,如果您只指定一个字符串,则它与消息上的CorrelationId属性匹配。或者,您可以为任何其他系统属性(如ContentType)指定值,或使用您自己的用户属性进行过滤。
这是我写的一篇博客文章,描述了您可以使用的不同类型的模式:http:
//abhishekrlal.com/2012/02/07/enterprise-integration-patterns-with-service-bus-part-1/
以下是展示使用不同过滤器的示例: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);