How do I get old messages from RabbitMQ?
Asked Answered
M

2

5

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

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

and subscribing like this:

    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?

Muggins answered 5/11, 2015 at 14:2 Comment(0)
M
9

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.

Do this:

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

instead of this:

q    = ch.queue("")

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

Muggins answered 5/11, 2015 at 14:2 Comment(4)
How long duration does RabbitMQ do back-up the messages?Moulin
I don't understand what you mean by "back up."Muggins
What was the meaning of 'backed-up messages' you used then?Moulin
Backed-up messages means messages that are delayed. Are you asking "how long does RabbitMQ delay the messages?" It delays them until you collect them! How long is a piece of string...Muggins
G
0

Queue has to be parameter called durable its never losses

ch.queue(queue, {
       durable: true
     });
instead 
q    = ch.queue("")
Girardi answered 13/12, 2021 at 6:1 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Tilley

© 2022 - 2024 — McMap. All rights reserved.