Alex
Alex

Reputation: 6149

How Rabbit MQ Consumers Work?

I have 2 questions regarding rabbitmq consumers (receivers):

  1. How can I define (statically from the queue) what are the consumers that are registered to a certain queue, so that if one consumer is down the message will still be delivered after that consumer is up again, or is there any other way to achieve this?
  2. How does consumers connects to a queue that is still not created, in rabbitmq tutorials, I can call the consumer before the producer and it will still work, can someone please explain how this works?

Thanks

Upvotes: 0

Views: 1315

Answers (1)

cantSleepNow
cantSleepNow

Reputation: 10170

  1. To achieve what you want is simple, this is by design in rabbitmq (just be sure that you don't auto-acknowledge). The message remains in the queue until it's acknowledged. So basically the consumer should finish processing the message and then acknowledge it. If the consumer dies during processing, the message is not ACKed and it gets re-queued. Next time the consumer is up it gets that message. Of course if you have multiple instances of the same (for the sake of simplicity) consumers, the one that is up takes the re-queued message. It's nicely explained in the second tutorial on rmq website.

  2. Declaring queue is an idempotent operation, the queue will be created if it doesn't exist already. If the consumer is the first one to create the queue, that's fine, it's actually usually how it works. The publisher actually does not even (need to) know about the queue, it only cares about exchanges and routing keys. It also doesn't care if anyone is listening, it simply publishes the message. The consumer needs to tell to what routing key does it want to bind the queue.

Upvotes: 3

Related Questions