Class OrderedMessageChannelDecorator

java.lang.Object
org.springframework.messaging.simp.broker.OrderedMessageChannelDecorator
All Implemented Interfaces:
MessageChannel

public class OrderedMessageChannelDecorator extends Object implements MessageChannel
Decorator for an ExecutorSubscribableChannel that ensures messages are processed in the order they were published to the channel. Messages are sent one at a time with the next one released when the previous has been processed. This decorator is intended to be applied per session.
Since:
5.1
Author:
Rossen Stoyanchev
  • Constructor Details

    • OrderedMessageChannelDecorator

      public OrderedMessageChannelDecorator(MessageChannel channel, Log logger)
  • Method Details

    • send

      public boolean send(Message<?> message)
      Description copied from interface: MessageChannel
      Send a Message to this channel. If the message is sent successfully, the method returns true. If the message cannot be sent due to a non-fatal reason, the method returns false. The method may also throw a RuntimeException in case of non-recoverable errors.

      This method may block indefinitely, depending on the implementation. To provide a maximum wait time, use MessageChannel.send(Message, long).

      Specified by:
      send in interface MessageChannel
      Parameters:
      message - the message to send
      Returns:
      whether the message was sent
    • send

      public boolean send(Message<?> message, long timeout)
      Description copied from interface: MessageChannel
      Send a message, blocking until either the message is accepted or the specified timeout period elapses.
      Specified by:
      send in interface MessageChannel
      Parameters:
      message - the message to send
      timeout - the timeout in milliseconds or MessageChannel.INDEFINITE_TIMEOUT
      Returns:
      true if the message is sent, false if not including a timeout of an interrupt of the send
    • getNextMessageTask

      @Nullable public static Runnable getNextMessageTask(Message<?> message)
      Obtain the task to release the next message, if found.
    • configureInterceptor

      public static void configureInterceptor(MessageChannel channel, boolean preserveOrder)
      Install or remove an ExecutorChannelInterceptor that invokes a completion task, if found in the headers of the message.
      Parameters:
      channel - the channel to configure
      preserveOrder - whether preserve the order or publication; when "true" an interceptor is inserted, when "false" it removed.