[英]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.