0 votes
1 view
in Azure by (10.6k points)
I was trying to add a filter for subscription. Any idea how I can able to add it? Is it possible from Azure portal?

1 Answer

0 votes
by (21.5k points)

Basically, Azure portal does not provide this feature. But, you can add it using some tools like Service Bus explorer or Serverless 360 which contains an user interface. Also, if you want to do it using c# the below code will comes in handy.

var namespaceManager = SB.NamespaceManager.CreateFromConnectionString("{connectionString}");

//create a subscription with the filter expression

if (!namespaceManager.SubscriptionExists("{your-topic-name}", "{your-subscription-name}"))


    namespaceManager.CreateSubscription("{your-topic-name}", "{your-subscription-name}", new SqlFilter("sys.Label='important' or MessageId<0"));


//send topic message(s)

var msg= new BrokeredMessage("Hello World");

msg.Properties["From"] = "Bruce Chen";

msg.Label = "important";

msg.Properties["MessageId"] = 1;

var client = TopicClient.CreateFromConnectionString("{connectionString}", "{your-topic-name}");


//subscription receives message(s)

var subClient =SubscriptionClient.CreateFromConnectionString(connectionString, "{your-topic-name}", "{your-subscription-name}");

subClient .OnMessage(m =>


    Console.WriteLine(m.GetBody<string>() + "," + m.Label + "," + m.Properties["From"] + "," + m.Properties["MessageId"]);



I hope this will help.

Want to become an azure expert? join azure developer certification now!! 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !