12

使用 2012 年 6 月的 Azure SDK,我有一个服务总线主题,我正在向它添加订阅。

我想过滤该订阅。如果我根据我添加到 BrokeredMessage 属性包中的一项来执行此操作,那么这可以正常工作:

// Send the message:
BrokeredMessage message = new BrokeredMessage(serializableObject);
message.Properties.Add("MySessionId", "GUID");
getTopicClient("MY_TOPIC").Send(message); // method creates client. omitted here.

// Retrieve it:
SqlFilter myFilter = new SqlFilter(@"(MySessionId = ""GUID"")");
namespaceManager.CreateSubscription("MY_TOPIC", "MY_SUB", myFilter);
SubscriptionClient client = getSubscriptionClient("MY_TOPIC", "MY_SUB"); // method creates client. omitted here.

// This will work fine:
Message newMessage = client.Receive();

但是,如果我执行相同操作,但将过滤器值添加到 BrokeredMessage 对象的直接属性之一,例如 SessionId,则此操作将失败:

// Send the message:
BrokeredMessage message = new BrokeredMessage(serializableObject);
message.SessionId = "GUID";
getTopicClient("MY_TOPIC").Send(message); // method creates client. omitted here.

// Retrieve it:
SqlFilter myFilter = new SqlFilter(@"(SessionId = ""GUID"")");
namespaceManager.CreateSubscription("MY_TOPIC", "MY_SUB", myFilter);
SubscriptionClient client = getSubscriptionClient("MY_TOPIC", "MY_SUB"); // method creates client. omitted here.

// This will never receive a message
Message newMessage = client.Receive();

如何构造一个 SqlFilter 来处理 BrokeredMessage 对象的内置属性(SessionId、ReplyToSessionId 或 MessageId?

这甚至可能吗?

4

1 回答 1

20

SQL 过滤器中的属性表达式实际上具有范围前缀。您通常看不到它们,因为默认值为“用户”。对于用户定义的属性。您可以通过前缀“sys”来获取系统属性。

请参阅此处的语法描述;寻找“范围” http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.servicebus.messaging.sqlfilter.sqlexpression.aspx

于 2012-08-28T16:58:31.793 回答