Class UserDestinationMessageHandler
- All Implemented Interfaces:
Lifecycle, Phased, SmartLifecycle, MessageHandler
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 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 phase that this lifecycle object is supposed to run in.Return the configuredUserDestinationResolver.voidhandleMessage(Message<?> sourceMessage) Handle the given message.final booleanCheck whether this component is currently running.voidsetBroadcastDestination(@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()Start this component.final voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.final voidIndicates that a Lifecycle component must stop if it is currently running.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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()Description copied from interface:SmartLifecycleReturn the phase that this lifecycle object is supposed to run in.The default implementation returns
SmartLifecycle.DEFAULT_PHASEin order to letstop()callbacks execute before regularLifecycleimplementations.- Specified by:
getPhasein interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle- See Also:
-
start
public final void start()Description copied from interface:LifecycleStart this component.Should not throw an exception if the component is already running.
In the case of a container, this will propagate a hard start signal to all components that apply, even to non-auto-startup components.
-
stop
public final void stop()Description copied from interface:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecyclebeans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.Should not throw an exception if the component is not running (not started yet).
In the case of a container, this will propagate the stop signal to all components that apply.
-
stop
Description copied from interface:SmartLifecycleIndicates that a Lifecycle component must stop if it is currently running.The provided callback is used by the
LifecycleProcessorto support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after theSmartLifecyclecomponent does indeed stop.The
LifecycleProcessorwill call only this variant of thestopmethod; i.e.Lifecycle.stop()will not be called forSmartLifecycleimplementations unless explicitly delegated to within the implementation of this method.The default implementation delegates to
Lifecycle.stop()and immediately triggers the given callback in the calling thread. Note that there is no synchronization between the two, so custom implementations may at least want to put the same steps within their common lifecycle monitor (if any).- Specified by:
stopin interfaceSmartLifecycle- See Also:
-
isRunning
public final boolean isRunning()Description copied from interface:LifecycleCheck whether this component is currently running.In the case of a container, this will return
trueonly if all components that apply are currently running. -
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
-