Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter a ServiceBus topic subscription based on a built-in property of the BrokeredMessage class?

Using the June 2012 Azure SDK, I have a service bus topic, and I am adding a subscription to it.

I want to filter that subscription. If I do this based on one of the items that I have added to the BrokeredMessage Properties bag, then this works fine:

// 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();

If, however, I do the same, but add the filter value to one of the direct properties of the BrokeredMessage object, such as SessionId, then this fails:

// 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();

How can I construct an SqlFilter that will address the built-in properties of the BrokeredMessage object (SessionId, or ReplyToSessionId, or MessageId?

Is this even possible?

like image 226
Jude Fisher Avatar asked Aug 28 '12 15:08

Jude Fisher


1 Answers

The property expressions in SQL filters actually have scoping prefixes. You usually don't see them, because the default is "user." for the user-defined properties. You can get at the system properties by prefixing with "sys."

See syntax description here; look for 'scope' http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.servicebus.messaging.sqlfilter.sqlexpression.aspx

like image 72
Clemens Vasters Avatar answered Oct 13 '22 17:10

Clemens Vasters