Search code examples
javarabbitmqspring-cloud-stream

Does StreamBridge.send() return value can be used as publishing confirmation?


I want to guarantee a message will be delivered to the broker, the classic case of publisher confirms, when using Spring Cloud Stream with RabbitMQ.

When using the StreamBridge.send() method, the javadocs says the following about the return of the method:

true if data was sent successfully, otherwise false or throws an exception

So it could imply that's all you need to confirm the message has been received by the broker. However if you browser RabbitMQ Binder docs, it makes mention of another entirely different mechanism that relies on adding a callback and so on, as seen here: https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream-binder-rabbit.html#publisher-confirms

So the question is, which of the two options is the reliable one? Just the return of the StreamBridge.send() call, or do I need the callback to confirm publishing of a given message?


Solution

  • RabbitMQ is async so the send will always be successful. You can use transactions, but even then it will be successful, even if there is no queue bound to the exchange.

    Use the publisher confirm (and check for a returned message).