Hello,
To define the Problem, I have a Service Bus Resource with me. I create Topic and Subscriptions under this Service Bus via code on it's first run, if topic and subscription are not already found. As a practice, I do not create topic explicitly from Azure Portal.
Code snippet which i use is:
private SubscriptionClient CreateSubscriptionClient(string topicConfig, string subsConfig, string filterConfig) { //TopicName, Subscription Name and Filter for that //Subscription is read from Cloud Configuration settings 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)) { //Create Topic if Not found // This would create it on first run TopicDescription td = new TopicDescription(topicName); td.DefaultMessageTimeToLive = TimeSpan.FromDays(1); namespaceManager.CreateTopic(td); } if (!namespaceManager.SubscriptionExists(topicName, subscriptionName)) { //Create Subscription if not found // This will Create a new subscription on first run // with filters as defined in this code block SqlFilter filter = new SqlFilter(filter); SubscriptionDescription sd = new SubscriptionDescription(topicName, subscriptionName); sd.DefaultMessageTimeToLive = TimeSpan.FromDays(1); sd.EnableDeadLetteringOnMessageExpiration = true; //Creates Subscription with Filter defined as above namespaceManager.CreateSubscription(sd, filter); } //Create Subscription Client for this Subscription var client = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, subscriptionName); return client; }
Above is the code block which I use to create Topic and Subscription on first run. Subscription and Subscription client is created within it. Messages coming to this topic with applied custom filters only are picked by this subscription client for processing, which is what is expected. this expected behavior is observed while running this code in development environment and tested.
On another staging environment, this Topic/Subscription is up for a couple of months now. while it displayed appropriate behavior early on, now months after it behaves strangely as in the Subscription Client which is created and returned from code snippet above started picking all messages in that topic. With further diagnosis, with help of Subscription description object, i found out that this Subscription no longer had the filter rule which was used to create it in the first place. it only had a true filter ('1'='1'), and thus subscription client was picking all messages being published to this topic, and thus the cause of my problem scenario.
As this Subscription is never manually created from portal, and only via the code above, I can not think of any reason for the expected filter not to be present in this subscription anymore.
So my questions to community on this to start with are:
- With code snippet above as reference, is it possible that when this Subscription was created, it may not actually had the expected filter to it? (highly doubt that, as in all tests it always create subscription with expected filter, but still open to suggestions on this)
- Assuming that subscription was created correctly with appropriate expected filter on it, is it possible for it to reset to default ('1'='1')? this subscription being created in a staging environment is not very actively used and remain idle for long time when code is not being tested. Could this cause subscription filters to reset?
- Is any time Bound expiry attached with filters on subscription as such? Is there any case where Subscription might be reset at all?
Any insights on this would be highly helpful or any suggestions/direction which community may have from description of this problem. I would be happy to add additional information if needed with context of this problem.
Thanks...