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?

Louise
  • 1,063
  • 1
  • 9
  • 20

2 Answers2

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.

Undo
  • 25,519
  • 37
  • 106
  • 129
Louise
  • 1,063
  • 1
  • 9
  • 20
0

Queue has to be parameter called durable its never losses

ch.queue(queue, {
       durable: true
     });
instead 
q    = ch.queue("")
  • 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](/help/how-to-answer). – Community Dec 13 '21 at 07:21