Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Experts,

let me elaborate setup before i come to my problem.

I have a Azure Topic in place: Topic "MyTopic"
and 2 subscriptions created to it with different filters:

1) Subscription-A with filter {MessageTitle = 'Cool'}
2) Subscription-B with filter {MessageTitle = 'NotSoCool'}

both are user properties and thus are filtered using SQLFilter.

to consume these messages, i have created 2 clients as well:
1) CoolSubClient for Subscription-A
2) NotSoCoolSubClient for Subscription-B

To start, i delete my Topic and thus the subscriptions, and allow my worker role to run and create these Topic/Subscription with Appropriate filter. so as to avoid any human error while creating these tunnels.

code for reference:

C#
private SubscriptionClient CreateSubscriptionClient(string topicConfig, string subsConfig, string filterConfig)
        {
            string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
            var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

            string topicName = CloudConfigurationManager.GetSetting(topicConfig);
            string subscriptionName = CloudConfigurationManager.GetSetting(subsConfig);
            string filter = CloudConfigurationManager.GetSetting(filterConfig);

            if (!namespaceManager.TopicExists(topicName))
            {
                TopicDescription td = new TopicDescription(topicName);
                td.DefaultMessageTimeToLive = TimeSpan.FromDays(1);
                namespaceManager.CreateTopic(td);
            }

            if (!namespaceManager.SubscriptionExists(topicName, subscriptionName))
            {

                var rd= new RuleDescription()
                {
                    Filter = new SqlFilter(filter),
                    Name = filterConfig
                };

                SubscriptionDescription sd = new SubscriptionDescription(topicName, subscriptionName);
                sd.DefaultMessageTimeToLive = TimeSpan.FromDays(1);
                sd.EnableDeadLetteringOnMessageExpiration = true;

                namespaceManager.CreateSubscription(sd, rd);
            }
         
            var client = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, subscriptionName);
          
            return client;
        }



All done, Topic is Up, Subscriptions are Up. Publishers are happily publishing messages with above mentioned filters on it, Clients are busy consuming them as per their filters and all is well.

Time flies and after a week or so.. BOOM. Client "NotSoCoolSubClient" is consuming all messages coming to Subscription-B like it has nothing to do with filter. When i diagnose, what do i see? Subscription-B is having a True filter "1=1", and so the problem of this client consuming all messages coming to topic.

now i know this, i can programmatically reset filters, but what i don't know is why the Filter used to create this subscription no longer exists!! its a mystery for me and i do not know what caused this on the first place. pretty sure i created subscriptions correctly and they worked great for a good number of days.

So hey great code warriors, suggestions, guidance needed and appreciated.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900