org.springframework.messaging.simp.user

## Class UserDestinationMessageHandler

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

All Implemented Interfaces:
  org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, MessageHandler

    public class UserDestinationMessageHandler
    extends Object
    implements MessageHandler, org.springframework.context.SmartLifecycle

`MessageHandler` with support for "user" destinations.

Listens for messages with "user" destinations, translates their destination to actual target destinations unique to the active session(s) of a user, and then sends the resolved messages to the broker channel to be delivered.

Since:
  4.0
Author:
  Rossen Stoyanchev

### Field Summary

### Fields inherited from interface org.springframework.context.SmartLifecycle

`DEFAULT_PHASE`

### Constructor Summary

Constructors
Constructor and Description
`UserDestinationMessageHandler(SubscribableChannel clientInboundChannel, SubscribableChannel brokerChannel, UserDestinationResolver resolver)` Create an instance with the given client and broker channels subscribing to handle messages from each and then sending any resolved messages to the broker channel.

### Method Summary

All Methods Instance Methods Concrete Methods
`String` `getBroadcastDestination()` Return the configured destination for unresolved messages.
`MessageSendingOperations<String>` `getBrokerMessagingTemplate()` Return the messaging template used to send resolved messages to the broker channel.
`MessageHeaderInitializer` `getHeaderInitializer()` Return the configured header initializer.
`UserDestinationResolver` `getUserDestinationResolver()` Return the configured `UserDestinationResolver`.
`void` `handleMessage(Message<?> message)` Handle the given message.
`boolean` `isRunning()`
`void` `setBroadcastDestination(String destination)` Set a destination to broadcast messages to that remain unresolved because the user is not connected.
`void` `setHeaderInitializer(MessageHeaderInitializer headerInitializer)` Configure a custom `MessageHeaderInitializer` to initialize the headers of resolved target messages.
`void` `start()`
`void` `stop()`
`void` `stop(Runnable callback)`
`String` `toString()`

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

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

### Methods inherited from interface org.springframework.context.SmartLifecycle

`getPhase, isAutoStartup`

### Constructor Detail

#### UserDestinationMessageHandler

    public UserDestinationMessageHandler(SubscribableChannel clientInboundChannel,
                                         SubscribableChannel brokerChannel,
                                         UserDestinationResolver resolver)

Create an instance with the given client and broker channels subscribing to handle messages from each and then sending any resolved messages to the broker channel.

Parameters:
  `clientInboundChannel` - messages received from clients.
  `brokerChannel` - messages sent to the broker.
  `resolver` - the resolver for "user" destinations.

### Method Detail

#### getUserDestinationResolver

    public UserDestinationResolver getUserDestinationResolver()

Return the configured `UserDestinationResolver`.

#### setBroadcastDestination

    public void setBroadcastDestination(@Nullable
                                        String destination)

Set a destination to broadcast messages to that remain unresolved because the user is not connected. In a multi-application server scenario this gives other application servers a chance to try.

By default this is not set.

Parameters:
  `destination` - the target destination.

#### getBroadcastDestination

    @Nullable
    public String getBroadcastDestination()

Return the configured destination for unresolved messages.

#### getBrokerMessagingTemplate

    public MessageSendingOperations<String> getBrokerMessagingTemplate()

Return the messaging template used to send resolved messages to the broker channel.

#### setHeaderInitializer

    public void setHeaderInitializer(@Nullable
                                     MessageHeaderInitializer headerInitializer)

Configure a custom `MessageHeaderInitializer` to initialize the headers of resolved target messages.

By default this is not set.

#### getHeaderInitializer

    @Nullable
    public MessageHeaderInitializer getHeaderInitializer()

Return the configured header initializer.

#### start

    public final void start()

Specified by:
  `start` in interface `org.springframework.context.Lifecycle`

#### stop

    public final void stop()

Specified by:
  `stop` in interface `org.springframework.context.Lifecycle`

#### stop

    public final void stop(Runnable callback)

Specified by:
  `stop` in interface `org.springframework.context.SmartLifecycle`

#### isRunning

    public final boolean isRunning()

Specified by:
  `isRunning` in interface `org.springframework.context.Lifecycle`

#### 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` - if the handler failed to process the message

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`