过期消息不会从 RabbitMQ 中删除

Messages with expiration are not removed from RabbitMQ

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

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

另一方面,如果我只发送一条带有 expiration 的消息,一开始我会看到消息,然后在正确的过期时间后,我发现它已被删除。

我的问题是,第一种情况实际上是space的消息?还是界面错误?

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

您似乎错过了有关此功能的一些文档。如果您阅读 RabbitMQ documentation on per-message TTL (expiration),您会注意到以下警告正是您所看到的行为(强调已添加):

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).