类 UserDestinationMessageHandler
- java.lang.Object
- org.springframework.messaging.simp.user.UserDestinationMessageHandler
- 所有已实现的接口:
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.
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
字段概要
从接口继承的字段 org.springframework.context.SmartLifecycle
DEFAULT_PHASE
构造器概要
构造器 构造器 说明 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.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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.UserDestinationResolvergetUserDestinationResolver()Return the configuredUserDestinationResolver.voidhandleMessage(Message<?> message)Handle the given message.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()从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
从接口继承的方法 org.springframework.context.SmartLifecycle
getPhase, isAutoStartup
构造器详细资料
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.- 参数:
clientInboundChannel- messages received from clients.brokerChannel- messages sent to the broker.resolver- the resolver for "user" destinations.
方法详细资料
getUserDestinationResolver
public UserDestinationResolver getUserDestinationResolver()
Return the configuredUserDestinationResolver.
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.
- 参数:
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 customMessageHeaderInitializerto 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()
从接口复制的说明: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.
- 指定者:
start在接口中Lifecycle- 另请参阅:
SmartLifecycle.isAutoStartup()
stop
public final void stop()
从接口复制的说明: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在接口中Lifecycle- 另请参阅:
SmartLifecycle.stop(Runnable),DisposableBean.destroy()
stop
public final void stop(Runnable callback)
从接口复制的说明: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).- 指定者:
stop在接口中SmartLifecycle- 另请参阅:
Lifecycle.stop(),SmartLifecycle.getPhase()
isRunning
public final boolean isRunning()
从接口复制的说明: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
从接口复制的说明:MessageHandlerHandle the given message.- 指定者:
handleMessage在接口中MessageHandler- 参数:
message- the message to be handled- 抛出:
MessagingException- if the handler failed to process the message