Search code examples
rabbitmqnetwork-programmingqueueamqp

What is the difference between Publisher Confirm mode and transaction in RabbitMQ?


I think publisher confirm mode and transaction both requires the broker to confirm the receiving of messages, then why publisher confirm mode is regarded light-weight operation which has better throughput than transaction?

I thought transaction is with synchronous style while publisher confirm mode is with asynchronous style, but I'm wrong, there is publisher confirm mode with synchronous style.

So what is the difference between Publisher Confirm mode and transaction in RabbitMQ, and why Publisher Confirm mode provides better throughput performance?


Solution

  • Publisher confirms will give you a "yes or no" answer from the broker when you publish a message indicating whether the message was successfully enqueued into all bound queues (as of the time of publish). The confirm is issued for each message that the broker processes, or (according to the spec), it is possible for the broker to issue a "batch" confirm, which indicates all messages up to the one indicated by the confirmation have been processed. I personally don't know that the broker does this; I think it just issues a single confirm per message.

    Using this semantic, let's say you have 10 messages to publish. The broker accepts the first 9, but is unable to accept the 10th (maybe one of the queues is full). The other 9 messages are still enqueued.

    Transactional gives you the option to send "all or nothing." Under the scenario above, if you publish all 10 messages as part of a transaction, but the 10th fails, you can abort the transaction, and the broker will act as though none of the messages were published at all. This capability comes at a cost of performance (according to the docs is up to 250 times slower when operating in transactional mode).

    Transactional Acks are also possible - you can ack multiple messages as part of a single transaction.