Search code examples
rabbitmqbroker

RabbitMQ How can a publisher know if a message was recieved by the broker


I'm working with RabbitMQ in java. I'd like to publish multiple messages, knowing if the broker recieved it or not. Note that i don't want to know if the message was acknowledged or not. The examples I found seem to rely in the client sending a basicAck or Nack.

ch.setConfirmListener(new ConfirmListener() {
    public void handleAck(long seqNo, boolean multiple) {
        if (multiple) {
            unconfirmedSet.headSet(seqNo+1).clear();
        } else {
            unconfirmedSet.remove(seqNo);
        }
    }
    public void handleNack(long seqNo, boolean multiple) {
        // handle the lost messages somehow
    }
});

I only want to know if the message was recieved in the broker as a publisher, after a basicPublish.


Solution

  • You are looking for publisher confirms.

    The ACK's usage you are citing is for consumers, since RabbitMQ require a message to be ACKed, before removing it from its queues.

    Note that receiving a confirm for a published message, does not imply that the message has been stored in a queue: that message can be "unroutable", and in this case the confirms are sent to the publisher immediately, but the message discarded. See: When will messages be confirmed

    If you want to track also unroutable messages, you have to use Alternate Exchanges.