Microservices
RabbitMQ
Use RabbitMQ for reliable queues.
RabbitMQ is a mature message broker built around queues: a message waits in a queue until a consumer takes it and acknowledges it. It is a good fit when messages must not be lost and work should be shared fairly.
app.connectMicroservice(RmqOptions("amqp://user:pass@rabbit:5672", queue = "orders", prefetch = 10, deadLetterExchange = "orders.dlx"))
import(ClientsModule.register { client("ORDERS", RmqOptions("amqp://user:pass@rabbit:5672", queue = "orders")) }) // in the caller's module- Requests use a
replyToqueue and a correlation id; the reply queue has a name the client chose, so it comes back under the same name after a broker restart. - Connection and topology recovery are automatic.
prefetchlimits unacknowledged messages per consumer, so a slow handler is not flooded.- Messages are at least once: a handler that fails or a service that dies mid-message causes redelivery. Make handlers idempotent.
- All instances of a service use the same
queue: each message goes to one of them.
When to choose it
Reliable work distribution, task queues between services, when you need acknowledgements and persistence.
Your handlers are the same on every transport: see Overview. Compare all of them in Transports compared.