过期的邮件不会从RabbitMQ中删除 [英] Messages with expiration are not removed from RabbitMQ

查看:439
本文介绍了过期的邮件不会从RabbitMQ中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过生产者向RabbitMQ发送一条普通消息,然后发送第二条消息,该消息的expiration属性分配了一个值.然后使用rabbitmqctl list_queues命令监视消息的状态.

I am sending a normal message through a producer to RabbitMQ and then I send a second message with the expiration attribute assigned to a value. Then using the rabbitmqctl list_queues command I monitor the status of the messages.

我发现,如果我先发送一条普通消息,然后再发送一条带有expiration的消息,则rabbitmqctl list_queues总是向我显示队列中有2条待处理的消息.当我食用它们时,我只会得到一个.

I found that if I send a normal message first and then a message with expiration, the rabbitmqctl list_queues is always showing me 2 messages pending on the queue. When I consume them, I get only one.

另一方面,如果我仅用expiration发送1条消息,则一开始我会看到该消息,然后在正确的到期时间之后,我发现它已删除.

On the other hand if I send just 1 message with expiration, in the beginning I see the message and then after the correct expiration time, I find it deleted.

我的问题是,第一种情况实际上是消息占用空间吗?还是界面错误?

My question is, on the first situation is actually the message taking space? Or it is an interface bug?

我的RabbitMQ版本是: rabbitmq-server.noarch -> 3.1.5-1.el6

My rabbitMQ version is: rabbitmq-server.noarch -> 3.1.5-1.el6

推荐答案

好像您错过了有关此功能的一些文档.如果您阅读关于每条消息TTL(到期)的RabbitMQ文档,则会注意到以下警告确切了解您所看到的行为(添加了重点):

Looks like you missed some of the documentation on this feature. If you read the RabbitMQ documentation on per-message TTL (expiration), you will notice the following warning for exactly the behavior you are seeing (emphasis added):

注意事项

尽管使用者永远不会看到过期的消息,但是只有当过期的消息到达队列的开头时,它们才会被实际丢弃(或用死字母标记).当设置每个队列的TTL时,这不是问题,因为过期的消息始终位于队列的开头. 但是,当设置每个邮件的TTL时,过期的邮件可以在未过期的邮件之后排队,直到未过期的邮件被消耗或过期为止.因此,此类过期的邮件所使用的资源将不会被释放,并且将被计数队列统计信息(例如,队列中的消息数).

Caveats

While consumers never see expired messages, only when expired messages reach the head of a queue will they actually be discarded (or dead-lettered). When setting a per-queue TTL this is not a problem, since expired messages are always at the head of the queue. When setting per-message TTL however, expired messages can queue up behind non-expired ones until the latter are consumed or expired. Hence resources used by such expired messages will not be freed, and they will be counted in queue statistics (e.g. the number of messages in the queue).

这篇关于过期的邮件不会从RabbitMQ中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆