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
MessageHandlerwith 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
Constructor Summary
Constructors Constructor 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 Modifier and Type Method Description StringgetBroadcastDestination()Return the configured destination for unresolved messages.MessageSendingOperations<String>getBrokerMessagingTemplate()Return the messaging template used to send resolved messages to the broker channel.MessageHeaderInitializergetHeaderInitializer()Return the configured header initializer.intgetPhase()Return the phase value of this object.UserDestinationResolvergetUserDestinationResolver()Return the configuredUserDestinationResolver.voidhandleMessage(Message<?> message)Handle the given message.booleanisAutoStartup()Returnstrueif thisLifecyclecomponent should get started automatically by the container at the time that the containingApplicationContextgets refreshed.booleanisRunning()Check whether this component is currently running.voidsetBroadcastDestination(String destination)Set a destination to broadcast messages to that remain unresolved because the user is not connected.voidsetHeaderInitializer(MessageHeaderInitializer headerInitializer)Configure a customMessageHeaderInitializerto initialize the headers of resolved target messages.voidstart()Start this component.voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.voidstop(Runnable callback)Indicates that a Lifecycle component must stop if it is currently running.StringtoString()
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 configuredUserDestinationResolver.
setBroadcastDestination
public void setBroadcastDestination(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
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(MessageHeaderInitializer headerInitializer)
Configure a customMessageHeaderInitializerto initialize the headers of resolved target messages.By default this is not set.
getHeaderInitializer
public MessageHeaderInitializer getHeaderInitializer()
Return the configured header initializer.
isAutoStartup
public boolean isAutoStartup()
Description copied from interface:SmartLifecycleReturnstrueif thisLifecyclecomponent should get started automatically by the container at the time that the containingApplicationContextgets refreshed.A value of
falseindicates that the component is intended to be started through an explicitLifecycle.start()call instead, analogous to a plainLifecycleimplementation.- Specified by:
isAutoStartupin interfaceSmartLifecycle- See Also:
Lifecycle.start(),Phased.getPhase(),LifecycleProcessor.onRefresh(),ConfigurableApplicationContext.refresh()
getPhase
public int getPhase()
Description copied from interface:PhasedReturn the phase value of this object.
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 the start signal to all components that apply.
- Specified by:
startin interfaceLifecycle- See Also:
SmartLifecycle.isAutoStartup()
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.
- Specified by:
stopin interfaceLifecycle- See Also:
SmartLifecycle.stop(Runnable),DisposableBean.destroy()
stop
public final void stop(Runnable callback)
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.- Specified by:
stopin interfaceSmartLifecycle- See Also:
Lifecycle.stop(),Phased.getPhase()
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
public void handleMessage(Message<?> message) throws MessagingException
Description copied from interface:MessageHandlerHandle the given message.- Specified by:
handleMessagein interfaceMessageHandler- Parameters:
message- the message to be handled- Throws:
MessagingException- if the handler failed to process the message