简体   繁体   English

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

[英]Spring Cloud Stream + RabbitMQ - Consuming existing messages in queue

I have a RabbitMQ message broker running in a server, to which I'm trying to configure a Producer and a Consumer using Spring Cloud Stream.我有一个在服务器中运行的 RabbitMQ 消息代理,我正在尝试使用 Spring Cloud Stream 配置生产者和消费者。 My Producer is creating messages in a queue every second, while my Consumer reads them at the same rate.我的生产者每秒都在队列中创建消息,而我的消费者以相同的速度读取它们。 However, if I stop my Consumer and the Producer keeps pushing messages, when I restart my Consumer again it is unable to retrieve the messages created in that period of time it was down, only picking up the messages produced from the time that it was started.但是,如果我停止我的消费者并且生产者继续推送消息,当我再次重新启动我的消费者时,它无法检索在它关闭的那段时间创建的消息,只能拾取从它启动时产生的消息. How can I make my Consumer consume existing messages in the queue when it starts?如何让我的消费者在启动时使用队列中的现有消息?

Here are my Consumer properties:这是我的消费者属性:

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

And my Producer properties:还有我的 Producer 属性:

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

Appreciate any help!感谢任何帮助!

You need to add a group to the consumer (input) binding;您需要在消费者(输入)绑定中添加一个group otherwise it will bind an anonymous, auto-delete, queue to the exchange.否则它将绑定一个匿名的、自动删除的队列到交换器。

With a group , a permanent, durable, queue is bound instead.使用group ,则绑定一个永久的、持久的队列。

I have a question too.我也有一个问题。 Before the consumer gets up, I send data to the producer.在消费者起床之前,我向生产者发送数据。 After a certain time, I wake up the consumer.一段时间后,我唤醒了消费者。 Consumer receives the printed data since it stands up.消费者收到打印的数据,因为它站起来。 So it doesn't do a reading from the beginning.所以它不会从一开始就进行阅读。 Is there any way to fix this?有没有什么办法解决这一问题? -GaryRussell ——加里·罗素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Cloud Stream并批量发送消息以排队 - Spring Cloud Stream and sending messages to queue in batches 如何暂停消费者在Spring云流中消费消息 - how to pause consumers from consuming messages in spring cloud stream Spring 云 stream RabbitMQ 随机失败,出现队列 NOT_FOUND 错误 - Spring cloud stream RabbitMQ randomly fails with queue NOT_FOUND error 如何关闭/停止 Spring 云 stream 绑定的 RabbitMQ 队列 - How to Shutdown/Stop RabbitMQ queue of Spring Cloud stream bindings Spring Cloud Stream RabbitMQ - Spring Cloud Stream RabbitMQ 如何配置 spring boot 以使用 spring-cloud-stream 和 rabbit-binder 将供应商绑定到 rabbitmq 队列? - How to configure spring boot to bind a supplier to a rabbitmq queue with spring-cloud-stream and rabbit-binder? Spring 启动应用程序不使用队列消息 - Spring Boot App not consuming queue messages 使用 Spring Cloud Stream Kafka Binder 批量消费 Kafka 消息及其密钥 - Consuming Kafka messages with its key in batches using Spring Cloud Stream Kafka Binder 使用Spring Boot的RabbitMQ队列中的消息计数 - Count of messages in rabbitMQ queue using spring boot 将多个 RabbitMQ 交换绑定到单个队列会在 Spring Cloud Stream 中引发错误 - Binding multiple RabbitMQ exchanges to single queue throws error in Spring Cloud Stream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM