Spring Cloud Stream + RabbitMQ-消耗队列中的现有消息

时间:2020-10-16 15:00:06

标签: spring-boot rabbitmq spring-cloud-stream

我有一个运行在服务器上的RabbitMQ消息代理,我正尝试使用Spring Cloud Stream配置到该服务器上的生产者和使用者。生产者正在每秒创建一个队列中的消息,而我的消费者以相同的速率读取它们。但是,如果我停止我的使用者,并且生产者继续推送消息,那么当我再次重新启动使用者时,它将无法检索在它停机期间创建的消息,只能拾取从其启动时产生的消息。 。如何让我的使用者在队列启动时使用队列中的现有消息?

以下是我的消费者属性:

cloud:
    stream:
      bindings:
        input:
          destination: spring-cloud-stream-demo
          consumer:
            auto-bind-dlq: true
            republishToDlq: true
            maxAttempts: 5

我的生产者属性:

cloud:
    stream:
      bindings:
        output:
          destination: spring-cloud-stream-demo

感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

您需要向使用者(输入)绑定添加group;否则它将绑定一个匿名的自动删除队列到交换机。

使用group绑定一个持久的持久队列。