简体   繁体   English

如果设置了AutoDeleteOnIdle,服务总线是否删除没有过滤器/规则的主题订阅?

[英]Does Service Bus Delete Topic Subscriptions with No Filters/Rules if AutoDeleteOnIdle is Set?

Good afternoon. 下午好。

We're using Service Bus Topics as the engine for a pub/sub system. 我们使用Service Bus Topics作为pub / sub系统的引擎。 Our logic involves our C# services hooking up to a topic with a subscription. 我们的逻辑涉及我们的C#服务连接到订阅主题。 We remove $Default (TrueFilter) and set AutoDeleteOnIdle to 5 minutes. 我们删除$ Default(TrueFilter)并将AutoDeleteOnIdle设置为5分钟。

As other parts of the system need things, they tell our C# service, "I need this." 由于系统的其他部分需要的东西,他们告诉我们的C#服务,“我需要这个。” The C# service then adds new rules (usually CorrelationFilter). 然后,C#服务添加新规则(通常是CorrelationFilter)。

As those same parts of the system no longer need things, they tell our C# service, "I don't need this any more." 由于系统的相同部分不再需要东西,他们告诉我们的C#服务,“我不再需要它了。” The C# service then removes the corresponding rules. 然后,C#服务删除相应的规则。

As such, it is possible for a Topic Subscription to still be connected (complete with a SubscriptionClient object) but to have no rules at all. 因此,主题订阅仍然可以连接(完成SubscriptionClient对象),但根本没有规则。

Issue 问题

The subscriptions "disappear" and I couldn't put my finger on why. 订阅“消失”,我无法理解为什么。 After all, I have an active subscription with a SubscriptionClient instance and a callback function hooked in. 毕竟,我有一个订阅了SubscriptionClient实例和一个回调函数的活动订阅。

Then, when I go to take an action with my SubscriptionClient object, it throws a MessagingEntityNotFoundException. 然后,当我使用我的SubscriptionClient对象进行操作时,它会抛出MessagingEntityNotFoundException。

It seemed to me as though Service Bus was randomly and arbitrarily losing or deleting my subscriptions. 在我看来,服务总线是随机和随意丢失或删除我的订阅。

Service Bus's Definition of "Idle" 服务总线对“空闲”的定义

My understanding is that the subscription is not "idle" so long as there is an active connection to the subscription (in my case, via a SubscriptionClient instance). 我的理解是,只要存在与订阅的活动连接(在我的情况下,通过SubscriptionClient实例),订阅就不是“空闲”。 Even if there are no messages of interest coming through, it's still not idle and thus still not deleted. 即使没有感兴趣的消息通过,它仍然没有空闲,因此仍然没有被删除。 If a message comes a day later, the SubscriptionClient instance will receive it. 如果一天后收到消息,则SubscriptionClient实例将接收该消息。

This has been my experience with other parts of the system that don't dynamically add/remove rules. 这是我对系统中不动态添加/删除规则的其他部分的经验。 It works quite well. 它运作得很好。

But then I started wondering: 但后来我开始疑惑:

In spite of having a connection to the subscription, does Service Bus see my subscription as being idle since it has no rules and thus couldn't possibly receive messages? 尽管与订阅有连接,Service Bus是否将我的订阅视为空闲,因为它没有规则,因此无法接收消息? And would Service Bus then follow the AutoDeleteOnIdle property and delete it? 然后Service Bus会遵循AutoDeleteOnIdle属性并将其删除吗?

If the above is true then would adding a FalseFilter as the $Default keep the subscription alive? 如果以上是真的那么会添加一个FalseFilter,因为$ Default保持订阅活着吗?

Any insight and help would be most appreciated. 任何见解和帮助将是最受欢迎的。

Many thanks - Shaun 非常感谢 - 肖恩

Update 更新

I made a rudimentary test in a WinForms application and something seems to be fundamentally wrong with Service Bus. 我在WinForms应用程序中进行了初步测试,似乎服务总线出现了根本性的错误。 Or, at least, our instance of Service Bus. 或者,至少,我们的服务总线实例。

I have 17 Topics, as follows: 我有17个主题,如下:

  • d860ffbe-e9c6-4ede-b6e9-959be4373128/notify-0 d860ffbe-e9c6-4ede-b6e9-959be4373128 /通知-0
  • d860ffbe-e9c6-4ede-b6e9-959be4373128/notify-1 d860ffbe-e9c6-4ede-b6e9-959be4373128 /通知-1
  • ... (you get the idea) ......(你明白了)
  • d860ffbe-e9c6-4ede-b6e9-959be4373128/notify-e d860ffbe-e9c6-4ede-b6e9-959be4373128 /通知-E
  • d860ffbe-e9c6-4ede-b6e9-959be4373128/notify-f d860ffbe-e9c6-4ede-b6e9-959be4373128 /通知-F
  • d860ffbe-e9c6-4ede-b6e9-959be4373128/notify-root d860ffbe-e9c6-4ede-b6e9-959be4373128 /通知根

notify-root forwards all messages it receives to the other notify topics. notify-root将收到的所有消息转发给其他通知主题。 We do this for sharding. 我们这样做是为了分片。

So... 所以...

I created 3 subscriptions on each of the 0 through f topics: 我在0到f主题的每一个上创建了3个订阅:

  • No Rule (I removed $Default) 没有规则(我删除了$ Default)
  • TrueFilter (I left the $Default as it is) TrueFilter(我保留了$ Default)
  • FalseFilter (I set the default filter to FalseFilter when creating the subscripption) FalseFilter(我在创建订阅时将默认过滤器设置为FalseFilter)

I created a SubscriptionClient instance for each of these 48 subscriptions and kept the instances in memory. 我为这48个订阅中的每一个创建了一个SubscriptionClient实例,并将实例保存在内存中。 I also used the OnMessageAsync method to pass in a callback that tells me when a message gets written. 我还使用OnMessageAsync方法传入一个回调,告诉我何时写入消息。

Each subscription's AutoDeleteOnIdle is set to TimeSpan.FromMinutes(5). 每个订阅的AutoDeleteOnIdle都设置为TimeSpan.FromMinutes(5)。

I iterated through my topics, subscriptions and rules every 1 minute to see when subscriptions and rules appear and disappear. 我每1分钟遍历我的主题,订阅和规则,以查看订阅和规则何时出现和消失。

Finally, I published a message every 1 minute on notify-root. 最后,我在notify-root上每隔1分钟发布一条消息。

Each one of the 16 subscriptions with the TrueFilter received a message every one minute and displayed it on my WinForms app as expected. 使用TrueFilter的16个订阅中的每一个每隔一分钟收到一条消息,并按预期在我的WinForms应用程序上显示它。

At the 5 minute mark, Service Bus automatically deleted all of my subscriptions for topics ending in 0, 1, 2, 4, 5, 6, B, C and F. 在5分钟标记处,Service Bus会自动删除我在0,1,2,4,5,6,B,C和F结尾的主题的所有订阅。

Service Bus deleted these subscriptions in spite of the fact that they are not idle and actively received messages less than 1 minute before being deleted. 服务总线删除了这些订阅,尽管它们在被删除之前不会闲置并且在不到1分钟内主动接收消息。

Some 30 minutes later, topics ending in 3, 7, 8, 9, A and E were still receiving messages with no signs of having their subscriptions deleted. 大约30分钟后,以3,7,8,9,A和E结尾的主题仍在接收消息,没有删除订阅的迹象。

Also, Service Bus did not delete some of the Subscriptions that either weren't receiving messages due to no rules or having a FalseFilter. 此外,Service Bus没有删除由于没有规则或没有FalseFilter而未接收消息的某些订阅。 The SubscriptionClient instances did have a callback hooked up via OnMessageAsync. SubscriptionClient实例确实通过OnMessageAsync连接了一个回调。 It's noteworthy that the ones that did not get deleted were in the same topic as the TrueFilter subscriptions that also did not get deleted. 值得注意的是,那些没有被删除的主题与TrueFilter订阅相同,但也没有被删除。

It seems like it's deleting subscriptions from some topics in spite of having activity but not others. 似乎它正在删除某些主题的订阅,尽管有活动而不是其他主题。

I repeated the test and it was the exact same topics that had their subscriptions deleted (in spite of having activity). 我重复了测试,这是完全相同的主题,删除了他们的订阅(尽管有活动)。

Once I stopped publishing, Service Bus deleted the remaining subscriptions after 5 minutes (as expected). 一旦我停止发布,Service Bus在5分钟后删除了剩余的订阅(正如预期的那样)。

I will repeat the test with a different set of 17 topics. 我将用17个不同的主题重复测试。

As it turns out, AutoDeleteOnIdle works exactly the way I thought it did. 事实证明,AutoDeleteOnIdle的工作方式完全符合我的想法。

As long as the Topic Subscription has a connection, it shouldn't be deleted. 只要主题订阅具有连接,就不应删除它。 It doesn't matter whether you have no rules, a FalseFilter or no messages getting published. 是否没有规则,FalseFilter或没有消息发布并不重要。 As long as you have an active connection and you are currently trying to get messages using OnMessage(), OnMessageAsync(), Receive() or ReceiveAsync() then the subscription is not idle and will not be deleted . 只要您有活动连接并且您当前正在尝试使用OnMessage(),OnMessageAsync(),Receive()或ReceiveAsync()来获取消息,那么订阅不会处于空闲状态且不会被删除

However, our Service Bus Topic Subscriptions were still disappearing from some of the Topics. 但是,我们的服务总线主题订阅仍然从一些主题中消失。 They were still being deleted at the AutoDeleteOnIdle time. 它们仍然在AutoDeleteOnIdle时删除。 I was never able to reproduce the issue on my dev box. 我无法在我的开发盒上重现这个问题。

We've had the issue in our Production environment for the last few months and it has only gotten worse. 过去几个月我们在生产环境中遇到了这个问题,而且情况变得更糟。 We assumed we were doing something wrong. 我们以为我们做错了什么。

As it so happens, Microsoft confirmed to me today that their West US 2 region has this issue. 碰巧的是,微软今天向我证实他们的西美2区有这个问题。 No other regions are affected. 没有其他地区受到影响。 MS has not confirmed why it's happening, for how long it has been happening or how long it will take to rectify. MS尚未确认为什么会发生这种情况,发生了多长时间或需要多长时间才能纠正。

This is the last thing I would have imagined. 这是我想象的最后一件事。 I assumed I was doing something wrong. 我以为我做错了什么。

Most troubling is how long this issue existed without being discovered by Microsoft. 最令人不安的是,这个问题存在多久没有被微软发现。

Hopefully it will be mended soon. 希望它很快就会被修补。

If someone else encounters Service Bus subscriptions disappearing or being deleted in spite of activity, I'd recommend building a test as I did. 如果其他人遇到Service Bus订阅消失或被删除尽管有活动,我建议像我一样建立测试。 If the test doesn't behave as expected, reach out to Microsoft. 如果测试的行为不符合预期,请与Microsoft联系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM