I'm a bit confused about RabbitMQ best practices regarding the use of Queues and Exchanges. Let's say I would like to deliver a GenerateInvoice
message with some data for an invoice, and have multiple consumers processing the invoice data and generate a PDF. Each GenerateInvoice
should be processed only by one consumer.
One approach is to declare an queue and publish the GenerateInvoice
messages to this queue and let all consumers consume from this queue. That would distribute the message across the different consumers.
It's unclear to me, if the above is okay or best practice is delivering the messages to a Exchange instead of publishing them directly to a queue. Using an Exchange I have to ensure that an queue is declared after the producer has created the Exchange before it starts to publish messages. Otherwise no queue would receive the messages and the message would be lost.