RabbitMQ setExpiration(); 属性

RabbitMQ setExpiration(); property

你好朋友,我想了解 RabbitMQ 中的征用 属性。如果我不设置这个 属性 会发生什么。我是 rabbitMQ 的新手,请帮助我。

AMQP.BasicProperties properties = new AMQP.BasicProperties();
properties.setExpiration("432000000");

读这个https://www.rabbitmq.com/ttl.html

A TTL can be specified on a per-message basis, by setting the expiration field in the basic AMQP class when sending a basic.publish.

The value of the expiration field describes the TTL period in milliseconds. The same constraints as for x-message-ttl apply. Since the expiration field must be a string, the broker will (only) accept the string representation of the number.

假设你设置Expiration时间=1000

如果 1 秒内没有人消费该消息,则该消息将被丢弃。

您可以使用 https://www.rabbitmq.com/dlx.html 处理 "dropped" 条消息。

如果您不设置 Expiration 消息将永远保留在队列中(如果没有消费者)。

编辑

添加了 theMayer 的评论

消息在到达队列头部之前不会被丢弃 - 因此,如果在队列中的消息之前存在未过期的消息,则在非过期消息之前不会自动删除任何消息- 过期消息已被消费。

另请阅读 post