类 AbstractBrokerMessageHandler
- java.lang.Object
- org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler
public abstract class AbstractBrokerMessageHandler extends Object implements MessageHandler, ApplicationEventPublisherAware, SmartLifecycle
Abstract base class for aMessageHandler
that broker messages to registered subscribers.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
构造器概要
构造器 构造器 说明 AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel)
Constructor with no destination prefixes (matches all destinations).AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes)
Constructor with destination prefixes to match to destinations of messages.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected boolean
checkDestinationPrefix(String destination)
ApplicationEventPublisher
getApplicationEventPublisher()
SubscribableChannel
getBrokerChannel()
SubscribableChannel
getClientInboundChannel()
MessageChannel
getClientOutboundChannel()
Collection<String>
getDestinationPrefixes()
int
getPhase()
Return the phase value of this object.void
handleMessage(Message<?> message)
Handle the given message.protected abstract void
handleMessageInternal(Message<?> message)
boolean
isAutoStartup()
Returnstrue
if thisLifecycle
component should get started automatically by the container at the time that the containingApplicationContext
gets refreshed.boolean
isBrokerAvailable()
Whether the message broker is currently available and able to process messages.boolean
isRunning()
Check whether this message handler is currently running.protected void
publishBrokerAvailableEvent()
protected void
publishBrokerUnavailableEvent()
void
setApplicationEventPublisher(ApplicationEventPublisher publisher)
Set the ApplicationEventPublisher that this object runs in.void
setAutoStartup(boolean autoStartup)
void
start()
Start this component.protected void
startInternal()
void
stop()
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.void
stop(Runnable callback)
Indicates that a Lifecycle component must stop if it is currently running.protected void
stopInternal()
构造器详细资料
AbstractBrokerMessageHandler
public AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel)
Constructor with no destination prefixes (matches all destinations).- 参数:
inboundChannel
- the channel for receiving messages from clients (e.g. WebSocket clients)outboundChannel
- the channel for sending messages to clients (e.g. WebSocket clients)brokerChannel
- the channel for the application to send messages to the broker
AbstractBrokerMessageHandler
public AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes)
Constructor with destination prefixes to match to destinations of messages.- 参数:
inboundChannel
- the channel for receiving messages from clients (e.g. WebSocket clients)outboundChannel
- the channel for sending messages to clients (e.g. WebSocket clients)brokerChannel
- the channel for the application to send messages to the brokerdestinationPrefixes
- prefixes to use to filter out messages
方法详细资料
getClientInboundChannel
public SubscribableChannel getClientInboundChannel()
getClientOutboundChannel
public MessageChannel getClientOutboundChannel()
getBrokerChannel
public SubscribableChannel getBrokerChannel()
getDestinationPrefixes
public Collection<String> getDestinationPrefixes()
setApplicationEventPublisher
public void setApplicationEventPublisher(ApplicationEventPublisher publisher)
从接口复制的说明:ApplicationEventPublisherAware
Set the ApplicationEventPublisher that this object runs in.Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked before ApplicationContextAware's setApplicationContext.
- 指定者:
setApplicationEventPublisher
在接口中ApplicationEventPublisherAware
- 参数:
publisher
- event publisher to be used by this object
getApplicationEventPublisher
public ApplicationEventPublisher getApplicationEventPublisher()
setAutoStartup
public void setAutoStartup(boolean autoStartup)
isAutoStartup
public boolean isAutoStartup()
从接口复制的说明:SmartLifecycle
Returnstrue
if thisLifecycle
component should get started automatically by the container at the time that the containingApplicationContext
gets refreshed.A value of
false
indicates that the component is intended to be started through an explicitLifecycle.start()
call instead, analogous to a plainLifecycle
implementation.
start
public void start()
从接口复制的说明:Lifecycle
Start 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()
startInternal
protected void startInternal()
stop
public void stop()
从接口复制的说明:Lifecycle
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycle
and itsstop(Runnable)
variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecycle
beans 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()
stopInternal
protected void stopInternal()
stop
public final void stop(Runnable callback)
从接口复制的说明:SmartLifecycle
Indicates that a Lifecycle component must stop if it is currently running.The provided callback is used by the
LifecycleProcessor
to support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after theSmartLifecycle
component does indeed stop.The
LifecycleProcessor
will call only this variant of thestop
method; i.e.Lifecycle.stop()
will not be called forSmartLifecycle
implementations unless explicitly delegated to within the implementation of this method.- 指定者:
stop
在接口中SmartLifecycle
- 另请参阅:
Lifecycle.stop()
,Phased.getPhase()
isRunning
public final boolean isRunning()
Check whether this message handler is currently running.Note that even when this message handler is running the
isBrokerAvailable()
flag may still independently alternate between being on and off depending on the concrete sub-class implementation.
isBrokerAvailable
public boolean isBrokerAvailable()
Whether the message broker is currently available and able to process messages.Note that this is in addition to the
isRunning()
flag, which indicates whether this message handler is running. In other words the message handler must first be running and then the#isBrokerAvailable()
flag may still independently alternate between being on and off depending on the concrete sub-class implementation.Application components may implement
org.springframework.context.ApplicationListener<BrokerAvailabilityEvent>
to receive notifications when broker becomes available and unavailable.
handleMessage
public void handleMessage(Message<?> message)
从接口复制的说明:MessageHandler
Handle the given message.- 指定者:
handleMessage
在接口中MessageHandler
- 参数:
message
- the message to be handled
handleMessageInternal
protected abstract void handleMessageInternal(Message<?> message)
checkDestinationPrefix
protected boolean checkDestinationPrefix(String destination)
publishBrokerAvailableEvent
protected void publishBrokerAvailableEvent()
publishBrokerUnavailableEvent
protected void publishBrokerUnavailableEvent()