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

查看:33
本文介绍了过期的消息不会从 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 的消息,一开始我会看到该消息,然后在正确的过期时间之后,我发现它已被删除.

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.

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

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

推荐答案

看起来您错过了有关此功能的一些文档.如果您阅读 RabbitMQ 文档关于 per-message TTL (expiration),您会注意到以下警告对于您所看到的行为(强调):

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天全站免登陆