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.
Listen for messages with "user" destinations, translate the destination to a target destination that's unique to the active user session(s), and send to the broker channel for delivery.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionUserDestinationMessageHandler(SubscribableChannel clientInboundChannel, SubscribableChannel brokerChannel, UserDestinationResolver destinationResolver) Create an instance with the given client and broker channels to subscribe to, and then send resolved messages to the broker channel. -
Method Summary
Modifier and TypeMethodDescriptionReturn the configured destination for unresolved messages.Return the messaging template used to send resolved messages to the broker channel.Return the configured header initializer.intgetPhase()Return the configuredUserDestinationResolver.voidhandleMessage(Message<?> sourceMessage) Handle the given message.final booleanvoidsetBroadcastDestination(@Nullable String destination) Set a destination to broadcast messages to that remain unresolved because the user is not connected.voidsetHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) Configure a customMessageHeaderInitializerto initialize the headers of resolved target messages.voidsetPhase(int phase) Set the phase that this handler should run in.final voidstart()final voidstop()final voidtoString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup, isPauseable
-
Constructor Details
-
UserDestinationMessageHandler
public UserDestinationMessageHandler(SubscribableChannel clientInboundChannel, SubscribableChannel brokerChannel, UserDestinationResolver destinationResolver) Create an instance with the given client and broker channels to subscribe to, and then send resolved messages to the broker channel.- Parameters:
clientInboundChannel- messages received from clients.brokerChannel- messages sent to the broker.destinationResolver- the resolver for "user" destinations.
-
-
Method Details
-
getUserDestinationResolver
Return the configuredUserDestinationResolver. -
setBroadcastDestination
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
-
getBrokerMessagingTemplate
Return the messaging template used to send resolved messages to the broker channel. -
setHeaderInitializer
Configure a customMessageHeaderInitializerto initialize the headers of resolved target messages.By default this is not set.
-
getHeaderInitializer
Return the configured header initializer. -
setPhase
public void setPhase(int phase) Set the phase that this handler should run in.By default, this is
SmartLifecycle.DEFAULT_PHASE, but with@EnableWebSocketMessageBrokerconfiguration it is set to 0.- Since:
- 6.1.4
-
getPhase
public int getPhase()- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-
start
public final void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public final void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
stop
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
isRunning
public final boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
handleMessage
Description copied from interface:MessageHandlerHandle the given message.- Specified by:
handleMessagein interfaceMessageHandler- Parameters:
sourceMessage- the message to be handled- Throws:
MessagingException- if the handler failed to process the message
-
toString
-