我如何从RabbitMQ获取旧消息? [英] How do I get old messages from RabbitMQ?

查看:1849
本文介绍了我如何从RabbitMQ获取旧消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Bunny(Ruby)发布RabbitMQ消息,如下所示:

I'm publishing RabbitMQ messages using Bunny (Ruby) like this:

x.publish("Message !"+n.to_s, :routing_key => 'mychannel')

并这样订阅:

    ch   = conn.create_channel
x    = ch.topic('fling',durable: true)
q    = ch.queue("")
q.bind(x, :routing_key => 'mychannel')


puts "Waiting for messages."
q.subscribe( :block => true) do |delivery_info, properties, body|
puts " [x] Received #{body}, message properties are #{properties.inspect}"

一旦启动订户,它将立即接收所发送的所有消息.但是,如果我在不启动订阅服务器的情况下发送消息,则在启动订阅服务器时不会收到消息(发件人是否仍在推送消息).

Once I start the subscriber, it immediately receives any messages which are sent. However, if I send messages without starting the subscriber, they aren't received when I start the subscriber (whether the sender is still pushing messages, or not).

是否有可能在没有订阅者正在收听的情况下返回队列并接收过去发送的消息?

Is it possible to go back through the queue and receive messages that were sent in the past, when no subscribers were listening?

推荐答案

每次启动使用者时,您都会在创建新队列!因此,当您重新启动使用者时,新队列将获得新消息,但没有以前的消息.

You're making a new queue each time you start the consumer! So when you restart the consumer, the new queue gets new messages, but doesn't have previous ones.

执行此操作:

q    = ch.queue("myqueue",durable: true)

代替此:

q    = ch.queue("")

然后,一旦重新启动使用者,它将立即以最快的速度获取所有备份的消息.

Then, as soon as you restart the consumer, it will immediately get all backed-up messages as fast as it can.

这篇关于我如何从RabbitMQ获取旧消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆