简体   繁体   English

如何自动使Azure Service Bus订阅上的消息过期?

[英]How can I automatically expire messages on an Azure Service Bus subscription?

The documentation on BrokeredMessage says: BrokeredMessage上的文档说:

If the TTL set on a message by the sender exceeds the destination's TTL, then the message's TTL will be overwritten by the later value. 如果发送方在消息上设置的TTL超过目的地的TTL,则消息的TTL将被后一个值覆盖。 See DefaultMessageTimeToLive, DefaultMessageTimeToLive and DefaultMessageTimeToLive to learn more about how to control message TTL at an entity level. 请参阅DefaultMessageTimeToLive,DefaultMessageTimeToLive和DefaultMessageTimeToLive以了解有关如何在实体级别控制消息TTL的更多信息。

So, to achieve messages to be automatically removed from my "Log" subscription, When creating the subscription, I have set the SubscriptionDescription.DefaultMessageTimeToLive property to TimeSpan.FromDays(5) . 因此,要实现从“Log”订阅中自动删除的消息,在创建订阅时,我已将SubscriptionDescription.DefaultMessageTimeToLive属性设置为TimeSpan.FromDays(5)

When I create and send a brokered message, leaving the TimeToLive property on that message to the default value, when I inspect messages arriving in that the subscription, the ExpiresAtUtc property for the messages is 31-12-9999 23:59 . 当我创建并发送代理消息时,将该消息上的TimeToLive属性保留为默认值,当我检查到达该订阅的消息时,消息的ExpiresAtUtc属性为31-12-9999 23:59 and the TimetoLive property is 10675199.02:48:05.4775807 . TimetoLive属性是10675199.02:48:05.4775807 Since the TTL on the 'destination' subscription is 5 days, I would have expected a value 5.00:00:00 there. 由于“目的地”订阅的TTL是5天,我原本预计会在5.00:00:00

Is there something else that I need to do to get this working? 我需要做些什么来使这个工作吗?

Steps to reproduce with Service Bus Explorer 2.2.1.0 使用Service Bus Explorer 2.2.1.0重现的步骤

  1. Connect to a Service Bus Namespace on azure 连接到azure上的服务总线命名空间
  2. Create a new topic "MyTopic" 创建一个新主题“MyTopic”
  3. Create a subscription "Log" under the topic and set the Default Message Time to Live to 5 days. 在主题下创建订阅“日志”,并将默认消息时间设置为5天。
  4. Right click on the MyTopic topic node and choose "Send messages" 右键单击MyTopic主题节点,然后选择“发送消息”
  5. On the "Send messages to MyTopic" screen: click "Start" 在“向MyTopic发送消息”屏幕上:单击“开始”
  6. Click the "Log" subscription node 单击“日志”订阅节点
  7. Click the "Messages" button and choose Peek 10 点击“信息”按钮,然后选择皮克 10
  8. Click the message in the list 单击列表中的消息
  9. Look at the TimeToLive field in the "Message Properties" area 查看“消息属性”区域中的TimeToLive字段

Apparenlty the TTL value on peeked messages is meaningless: 在偷看的消息上使用TTL值是没有意义的:

This behavior is currently by design and should be seen independent of SDK version: the effective TTL is the minimum TTL of message and entity and is checked at runtime, rather than imprinted on the message at enqueue time (because the entity-level TTL could be changed at any time after messages were enqueued). 此行为目前是设计使用,应该独立于SDK版本:有效TTL是消息和实体的最小TTL,并在运行时检查,而不是在入队时刻印在消息上(因为实体级TTL可能是在邮件入队后随时更改)。 The documentation is misleading and should be fixed. 文档具有误导性,应予以修复。

This answer was given on this MSDN thread: http://social.msdn.microsoft.com/Forums/windowsazure/en-US/dfe58dbb-186d-4c71-a708-8f6f7267b451/when-peeking-for-messages-the-time-to-live-value-seems-not-to-be-set-is-this-a-bug 这个答案是在这个MSDN线程上给出的: http//social.msdn.microsoft.com/Forums/windowsazure/en-US/dfe58dbb-186d-4c71-a708-8f6f7267b451/when-peeking-for-messages-the-time -to-活的价值似乎-不是将要设置的,是-这-A-错误

You have to set the DefaultMessageTimeToLive property when you create the queue itself and not when you create the queue client. 您必须在创建队列时设置DefaultMessageTimeToLive属性,而不是在创建队列客户端时设置。 Try deleting the queue and creating it again with the new queue description. 尝试删除队列并使用新队列描述再次创建它。

You need to log into your topic and set “Default Message Time to Live” to 14 days. 您需要登录主题并将“默认消息生存时间”设置为14天。

What went wrong? 什么地方出了错? Luckily this error was self-explanatory and indicating that the Max Topic size is 1 GB (1073741824 bytes) while the Topic is already utilized 1073742326 bytes which translates to approx 1 GB limit. 幸运的是,这个错误是不言自明的,表明Max Topic大小是1 GB(1073741824字节),而Topic已经被利用了1073742326字节,转换为大约1 GB的限制。 We logged into the Azure Portal and verified the same. 我们登录Azure门户并验证了相同的内容。 Next we ran Service Bus Explorer to check the status of the messages. 接下来,我们运行Service Bus Explorer来检查消息的状态。 We saw thousands of messages are in the Topics. 我们在主题中看到了数千条消息。

Why messages were not getting cleared from the Topic? 为什么消息没有从主题中清除? Now the obvious question arise, what is keeping those thousands of message in topic. 现在出现了一个显而易见的问题,那就是在主题中保留数以千计的信息。 After some investigation we found that “Default Message Time to Live” for Topic was set to very high number. 经过一番调查后,我们发现Topic的“默认消息生存时间”被设置为非常高的数字。 In this case it was set to 1 year. 在这种情况下,它被设定为1年。 In order to fix the issue, we set “Default Message Time to Live” to 2 days as recommended by the their App Developer. 为了解决问题,我们按照App Developer的建议将“默认消息生存时间”设置为2天。 This resolved the issue. 这解决了这个问题。 Here is a screen-shot of the configuration from Azure Management Portal: 以下是Azure管理门户配置的屏幕截图:

See: https://blogs.msdn.microsoft.com/cie/2013/07/21/service-bus-error-the-maximum-entity-size-has-been-reached-or-exceeded-for-topic/ 请参阅: https//blogs.msdn.microsoft.com/cie/2013/07/21/service-bus-error-the-maximum-entity-size-has-been-reached-or-exceeded-for-topic/

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

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