javaspring-cloud-stream

When is StreamBridge returning false and when is it throwing an Exception


The documentation for StreamBridge states, that the send method returns false or throws an exception if data wasn't sent successfully.

I am wondering for which cases sending is returning false and for which it is throwing an exception. I hope somebody can give me some clarification regarding this open question.


Solution

  • StreamBridge#send internally uses Spring's MessageChannel to send the message. Therefore, the boolean that StreamBridge returns is completely based on the MessageChannel#send implementation. See this for more details on that: https://github.com/spring-projects/spring-framework/blob/main/spring-messaging/src/main/java/org/springframework/messaging/MessageChannel.java#L44

    More specifically:

    /**
         * Send a {@link Message} to this channel. If the message is sent successfully,
         * the method returns {@code true}. If the message cannot be sent due to a
         * non-fatal reason, the method returns {@code false}. The method may also
         * throw a RuntimeException in case of non-recoverable errors.
         * <p>This method may block indefinitely, depending on the implementation.
         * To provide a maximum wait time, use {@link #send(Message, long)}.