Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What are publisher confirms and returned messages in RabbitMQ, and why does a producer need both to know a message was routed and stored?

A publisher confirm is the broker telling the producer that it has taken responsibility for a message (an ack) or could not (a nack). But a message sent to an exchange where no binding matches is still confirmed, and then silently dropped, unless the producer sets the mandatory flag; with mandatory set, an unroutable message is returned to the producer through a return callback. So the producer needs both: the confirm says the broker accepted and stored the message, and the absence of a return says it was routed to a queue. In Spring Boot we enable them with spring.rabbitmq.publisher-confirm-type=correlated and spring.rabbitmq.publisher-returns=true.

Why this question is asked

By default, publishing to RabbitMQ is fire-and-forget: the send method returns as soon as the bytes are written to the socket, and the producer never learns whether the broker stored the message. For many messages that is fine, but for orders or payments it means a broker failover or a missing binding can lose messages without anyone noticing. Interviewers ask this to check that we know the two separate mechanisms and why one alone is not enough. In this answer, we will recap what can go wrong after a send, explain confirms and returns, configure them in Spring Boot with code, and see how they combine into one answer per message.

1A Quick Recap: What Can Happen After a Send

When our code calls rabbitTemplate.convertAndSend, the message travels to the broker, the exchange tries to route it to queues using the bindings, and each queue stores it, on disk for a persistent message on a durable queue, or replicated to a majority of nodes for a quorum queue. Several things can go wrong on the way: the connection can break before the broker received the message, the broker can fail before storing it, or the routing can find no queue at all.

Without extra mechanisms, the producer sees none of this. The send call succeeded, because it only wrote to a socket. So we need the broker to report back, and RabbitMQ has two kinds of reports for two different questions.

2Publisher Confirms: Did the Broker Take Responsibility?

With confirms enabled on a channel, the broker numbers every published message and later sends back an ack for it once it has handled the message: routed to all matching queues and, for persistent messages on durable queues, written to disk or, for quorum queues, accepted by a majority of replicas. If something goes wrong inside the broker, it sends a nack instead. If the connection drops before the ack arrives, the producer gets no confirm at all and must treat the message as possibly not received and publish it again.

The important detail is what an ack does not mean. If the exchange found no matching binding, the message is not stored anywhere, but from the broker's point of view it has finished handling it, so it acks. A confirm alone cannot tell routed from dropped.

3Returns: Was the Message Routed?

The mandatory flag on a publish says: if this message cannot be routed to any queue, send it back to me instead of dropping it. The broker then sends a basic.return containing the message, a reply code (312 NO_ROUTE) and the exchange and routing key, followed by the ack. In Spring AMQP the returned message arrives in a ReturnsCallback.

So the two mechanisms answer two questions. Confirms answer whether the broker accepted the message, and returns answer whether it reached a queue. Only together do they tell us the message is stored in at least one queue.

What the producer learns
SituationConfirmReturn (mandatory)Meaning
Routed and storedacknonesafe in a queue
No matching bindingackreturned, NO_ROUTEdropped unless we act
Broker internal errornacknonepublish again
Connection lostno confirm, timeoutnoneunknown: publish again
Without mandatory, the second row looks exactly like the first.

4Configuring Confirms and Returns in Spring Boot

Spring Boot exposes both through properties. publisher-confirm-type=correlated makes the connection factory use confirms and lets us attach a CorrelationData to each send, so we know which message a confirm belongs to. publisher-returns=true enables returns, and Boot then sets the template's mandatory flag as well, unless spring.rabbitmq.template.mandatory says otherwise.

Java
# application.properties
spring.rabbitmq.publisher-confirm-type=correlated
spring.rabbitmq.publisher-returns=true
spring.rabbitmq.template.mandatory=true
@Configuration
class RabbitCallbacks {
RabbitCallbacks(RabbitTemplate template) {
template.setConfirmCallback((correlation, ack, cause) -> {
if (!ack) log.warn("nack for {}: {}", correlation.getId(), cause); // retry this one
});
template.setReturnsCallback(returned ->
log.error("unroutable {} to {} with key {}: {}", // fix routing
returned.getMessage().getMessageProperties().getMessageId(),
returned.getExchange(), returned.getRoutingKey(), returned.getReplyText()));
}
}
// Sending and waiting for the result of one message
CorrelationData cd = new CorrelationData(orderId);
template.convertAndSend("orders", "order.created.eu", order, cd);
CorrelationData.Confirm confirm = cd.getFuture().get(5, TimeUnit.SECONDS); // ack=true
ReturnedMessage returned = cd.getReturned(); // null when it was routed
Step throughAn unroutable mandatory publish
ProducerExchange ordersQueues
publish order.created.xx, mandatory
no binding matches
basic.return 312 NO_ROUTE
basic.ack
ack with return: not stored, raise an alert

5 messages in order. Play them, or step through them one at a time.

Notice the last three lines. The CorrelationData's future completes when the confirm arrives, and getReturned() is filled in if the message came back first, because the broker sends a return before the ack. So after the future completes, ack true with no return means the message is in a queue. A RabbitTemplate can have only one ConfirmCallback and one ReturnsCallback, so in larger applications the per-message future is the more convenient style. Waiting for each confirm one by one is slow; for throughput we send many messages and check their futures together.

5Why Both Matter in Practice

Without confirms, a producer cannot tell whether a message was lost when a broker node failed or a connection dropped mid-send, so the only reliable pattern is to keep each message, for example in an outbox table, until its ack arrives, and publish again on a nack or a timeout. That gives at-least-once delivery, and consumers handle the occasional duplicate. Without returns, a typo in a routing key or a binding removed during a deployment makes every message vanish while every confirm says ack. Returns turn that silent loss into an error we can alert on. An alternate exchange on the exchange is another way to catch unroutable messages on the broker side.

6Follow-up questions

What is the difference between correlated and simple confirm types?

With correlated, confirms are delivered asynchronously to the ConfirmCallback and to each message's CorrelationData future, which suits normal application code. With simple, the template's invoke method can be used with waitForConfirms or waitForConfirmsOrDie to block until all messages sent in that scope are confirmed, which is handy for batch jobs. None, the default, disables confirms.

Do confirms make delivery exactly once?

No. When an ack is lost because the connection broke after the broker stored the message, the producer publishes again and the queue holds two copies. Confirms give at-least-once delivery from producer to broker; consumers make it effectively once by being idempotent.

7Conclusion

In this answer, we saw that a send returns before the broker has done anything, so a producer needs reports. Publisher confirms ack a message once the broker has taken responsibility for it and nack it when it fails, but an unroutable message is also acked. The mandatory flag makes the broker return unroutable messages through a ReturnsCallback. In Spring Boot, publisher-confirm-type=correlated and publisher-returns=true enable both, and CorrelationData gives us the confirm and any return for each message, which together tell us the message was routed and stored.

What to say in the interviewAbout 90 seconds aloud

Open with

Publisher confirms are the broker acknowledging to the producer that it has taken responsibility for a message. With confirms on, each publish gets an ack once the broker has routed it and, for persistent messages on durable or quorum queues, stored it safely; a nack means the broker failed to handle it, and no confirm at all, for example because the connection dropped, means I have to assume it might be lost and publish again.

Then, if they want more

The catch is that if the exchange has no matching binding, the message is dropped, but the broker still acks, because from its point of view it handled the message. So confirms alone cannot tell routed from dropped.

That is what returns are for: if I publish with the mandatory flag, an unroutable message is sent back to me with reply code NO_ROUTE before the ack, and Spring AMQP delivers it to a ReturnsCallback. Ack without a return means the message is in a queue.

In Spring Boot I set publisher-confirm-type to correlated and publisher-returns to true, and template mandatory true, then register a ConfirmCallback and a ReturnsCallback, or use CorrelationData per message and check its future and getReturned.

Without confirms a producer simply cannot know whether a message was lost during a broker failure, so for important messages I keep them in an outbox until the ack arrives.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
RabbitMQ documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What are publisher confirms and returned messages in RabbitMQ, and why does a producer...": https://scrivio-interview-library.netlify.app/spring-boot/rabbitmq-and-jms/f990933023/