0
votes

Just a questions about Azure service bus topic subscriptions, is it possible to assign multiple properties to a single subscription?

Also is it possible to enable null values to one of the properties?

What I'm trying to do is to be able to use a azure function to somehow filter the messages on a identifier depending on if it exists or not.

I haven't been able to do this only by queue messages because i cant find a way to insert som type of metadata.

Another solution to my problem would be a separate Service bus Topic subscription where its property can accept being set and shift between to two different values, by which i then can filter.

The reason i want to do this is not to duplicate a whole sequence of actions, only to insert some kind of filtering functionality inside the action after the Service bus topic so to speak.

--------------------UPDATE-------------------

Ok So a bit of update, i've made some progress in this matter. Another question related to this matter is:

When I have sent a Brokered message to a servicebus topic subscription with a property as for example:

message.Properties['id'] = "1";

Is it possible to access that messages propertie value some how? I know it's probably not ment to be used this way but this would open a new door for me.

1
Not quite following... if you ask about having multiple rules on one subscriptions - yes you can. You can also create complex SQL filters as well.Sean Feldman
@SeanFeldman i've made some progress in this matter and i have a followup question, please look at the update, Thank you.John

1 Answers

1
votes

According to your description, I checked the Service Bus client library for C# and found when creating the subscription via NamespaceManager.CreateSubscription, we could only pass a single Filter or a RuleDescription with a single Filter as follows:

public SubscriptionDescription CreateSubscription(string topicPath, string name, Filter filter);
public SubscriptionDescription CreateSubscription(string topicPath, string name, RuleDescription ruleDescription);

As Sean Feldman mentioned about creating complex SQL filters, I created my application to test it. You could refer to my test as follows:

Sample Message

var body = "Hello World";
var message1 = new BrokeredMessage(body);
message1.Properties["From"] = "Ian Smith";
message1.Properties["MessageId"] = -1;
message1.Label = null;

var message2 = new BrokeredMessage("Second message");
message2.Properties["From"] = "Alan Smith";
message2.Label = "important";
message2.Properties["MessageId"] = 2;

var message3 = new BrokeredMessage("Third message");
message3.Properties["From"] = "Kelly Smith";
message3.Label = "information";
message3.Properties["MessageId"] = 1;

Create subscription with Filter

var filter=new SqlFilter("(sys.Label='important' or sys.Label IS NOT NULL) or MessageId<0 or From LIKE '%Smith'");
namespaceManager.CreateSubscription(topicName, subName,filter);

The above subscription could receive all the three messages. For more details, you could refer to SQLFilter syntax.

UPDATE:

For receiving messages, you could leverage Subscription​Client.​On​Message and refer to the following code snippet:

//Processes a message in an event-driven message pump.
 client.OnMessage((receivedMessage)=>{
    Console.WriteLine(receivedMessage.Properties['id'].ToString());
    receivedMessage.Complete(); //manually mark the message as processed and deleted.  
 },new OnMessageOptions(){
   AutoComplete=false,
   MaxConcurrentCalls=5
 });