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

Spring Cloud Stream + RabbitMQ - Consuming existing messages in queue

我在服务器中有一个 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

感谢任何帮助!

您需要向消费者(输入)绑定添加一个group;否则它将绑定一个匿名的 auto-delete 队列到交换器。

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