org.springframework.messaging.simp.user

## Class UserDestinationMessageHandler

- java.lang.Object
- - org.springframework.messaging.simp.user.UserDestinationMessageHandler

- All Implemented Interfaces:
    Lifecycle, Phased, SmartLifecycle, MessageHandler

      public class UserDestinationMessageHandler
      extends Object
      implements MessageHandler, SmartLifecycle

  Provides support for messages sent to "user" destinations, translating the destination to one or more user-specific destination(s) and then sending message(s) with the updated target destination using the provided messaging template.

  See `UserDestinationResolver` for more details and examples.

  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `SUBSCRIBE_DESTINATION`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UserDestinationMessageHandler(SubscribableChannel clientInChannel, SubscribableChannel brokerChannel, UserDestinationResolver userDestinationResolver)` Create an instance of the handler with the given messaging template and a user destination resolver.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `MessageSendingOperations<String>` | `getBrokerMessagingTemplate()` Return the configured messaging template for sending messages with translated destinations.
    `int` | `getPhase()` Return the phase value of this object.
    `UserDestinationResolver` | `getUserDestinationResolver()` Return the configured `UserDestinationResolver`.
    `void` | `handleMessage(Message<?> message)` Handle the given message.
    `boolean` | `isAutoStartup()` Return whether this Lifecycle component should be started automatically by the container when the ApplicationContext is refreshed.
    `boolean` | `isRunning()` Check whether this component is currently running.
    `void` | `start()` Start this component.
    `void` | `stop()` Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.
    `void` | `stop(Runnable callback)` Indicates that a Lifecycle component must stop if it is currently running.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### SUBSCRIBE_DESTINATION

          public static final String SUBSCRIBE_DESTINATION

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### UserDestinationMessageHandler

          public UserDestinationMessageHandler(SubscribableChannel clientInChannel,
                                               SubscribableChannel brokerChannel,
                                               UserDestinationResolver userDestinationResolver)

      Create an instance of the handler with the given messaging template and a user destination resolver.
      Parameters:
        `clientInChannel` - the channel for receiving messages from clients (e.g. WebSocket clients)
        `brokerChannel` - the channel for sending messages with translated user destinations
        `userDestinationResolver` - the resolver to use to find queue suffixes for a user

  - ### Method Detail

    - #### getBrokerMessagingTemplate

          public MessageSendingOperations<String> getBrokerMessagingTemplate()

      Return the configured messaging template for sending messages with translated destinations.

    - #### getUserDestinationResolver

          public UserDestinationResolver getUserDestinationResolver()

      Return the configured `UserDestinationResolver`.

    - #### getPhase

          public int getPhase()

      Description copied from interface: `Phased`
      Return the phase value of this object.
      Specified by:
        `getPhase` in interface `Phased`

    - #### isAutoStartup

          public boolean isAutoStartup()

      Description copied from interface: `SmartLifecycle`
      Return whether this Lifecycle component should be started automatically by the container when the ApplicationContext is refreshed. A value of "false" indicates that the component is intended to be started manually.
      Specified by:
        `isAutoStartup` in interface `SmartLifecycle`

    - #### isRunning

          public final boolean isRunning()

      Description copied from interface: `Lifecycle`
      Check whether this component is currently running.

      In the case of a container, this will return `true` only if all components that apply are currently running.

      Specified by:
        `isRunning` in interface `Lifecycle`
      Returns:
        whether the component is currently running

    - #### start

          public final void start()

      Description copied from interface: `Lifecycle`
      Start this component. Should not throw an exception if the component is already running.

      In the case of a container, this will propagate the start signal to all components that apply.

      Specified by:
        `start` in interface `Lifecycle`

    - #### stop

          public final void stop()

      Description copied from interface: `Lifecycle`
      Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing `SmartLifecycle` and its `stop(Runnable)` variant in cases where asynchronous stop behavior is necessary.

      Should not throw an exception if the component isn't started yet.

      In the case of a container, this will propagate the stop signal to all components that apply.

      Specified by:
        `stop` in interface `Lifecycle`
      See Also:
        `SmartLifecycle.stop(Runnable)`

    - #### stop

          public final void stop(Runnable callback)

      Description copied from interface: `SmartLifecycle`
      Indicates that a Lifecycle component must stop if it is currently running.

      The provided callback is used by the `LifecycleProcessor` to support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after the SmartLifecycle component does indeed stop.

      The `LifecycleProcessor` will call only this variant of the `stop` method; i.e. `Lifecycle.stop()` will not be called for `SmartLifecycle` implementations unless explicitly delegated to within this method.

      Specified by:
        `stop` in interface `SmartLifecycle`

    - #### handleMessage

          public void handleMessage(Message<?> message)
                             throws MessagingException

      Description copied from interface: `MessageHandler`
      Handle the given message.
      Specified by:
        `handleMessage` in interface `MessageHandler`
      Parameters:
        `message` - the message to be handled
      Throws:
        `MessagingException`