public abstract class AbstractBrokerMessageHandler extends Object implements MessageHandler, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.SmartLifecycle
MessageHandler that broker messages to
registered subscribers.| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
checkDestinationPrefix(String destination)
Whether a message with the given destination should be processed.
|
org.springframework.context.ApplicationEventPublisher |
getApplicationEventPublisher() |
SubscribableChannel |
getBrokerChannel() |
SubscribableChannel |
getClientInboundChannel() |
MessageChannel |
getClientOutboundChannel() |
protected MessageChannel |
getClientOutboundChannelForSession(String sessionId)
Get the MessageChannel to use for sending messages to clients, possibly
a per-session wrapper when
preservePublishOrder=true. |
Collection<String> |
getDestinationPrefixes()
Return destination prefixes prefixes to use to filter messages to forward
to the broker.
|
void |
handleMessage(Message<?> message)
Handle the given message.
|
protected abstract void |
handleMessageInternal(Message<?> message) |
boolean |
isAutoStartup() |
boolean |
isBrokerAvailable()
Whether the message broker is currently available and able to process messages.
|
boolean |
isPreservePublishOrder()
Whether to ensure messages are received in the order of publication.
|
boolean |
isRunning()
Check whether this message handler is currently running.
|
protected void |
publishBrokerAvailableEvent() |
protected void |
publishBrokerUnavailableEvent() |
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher publisher) |
void |
setAutoStartup(boolean autoStartup) |
void |
setPreservePublishOrder(boolean preservePublishOrder)
Whether the client must receive messages in the order of publication.
|
void |
setUserDestinationPredicate(Predicate<String> predicate)
Configure a Predicate to identify messages with a user destination.
|
void |
start() |
protected void |
startInternal() |
void |
stop() |
void |
stop(Runnable callback) |
protected void |
stopInternal() |
protected final Log logger
public AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel)
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 brokerpublic AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel, @Nullable Collection<String> destinationPrefixes)
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 messagespublic SubscribableChannel getClientInboundChannel()
public MessageChannel getClientOutboundChannel()
public SubscribableChannel getBrokerChannel()
public Collection<String> getDestinationPrefixes()
By default this is not set.
public void setUserDestinationPredicate(@Nullable
Predicate<String> predicate)
destination prefixes are configured,
this helps to recognize and skip user destination messages that need to
be pre-processed by the
UserDestinationMessageHandler
before they reach the broker.predicate - the predicate to identify user messages with a non-null
destination as messages with a user destinations.public void setPreservePublishOrder(boolean preservePublishOrder)
By default messages sent to the "clientOutboundChannel" may
not be processed in the same order because the channel is backed by a
ThreadPoolExecutor that in turn does not guarantee processing in order.
When this flag is set to true messages within the same session
will be sent to the "clientOutboundChannel" one at a time in
order to preserve the order of publication. Enable this only if needed
since there is some performance overhead to keep messages in order.
preservePublishOrder - whether to publish in orderpublic boolean isPreservePublishOrder()
public void setApplicationEventPublisher(@Nullable
org.springframework.context.ApplicationEventPublisher publisher)
setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware@Nullable public org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()
public void setAutoStartup(boolean autoStartup)
public boolean isAutoStartup()
isAutoStartup in interface org.springframework.context.SmartLifecyclepublic void start()
start in interface org.springframework.context.Lifecycleprotected void startInternal()
public void stop()
stop in interface org.springframework.context.Lifecycleprotected void stopInternal()
public final void stop(Runnable callback)
stop in interface org.springframework.context.SmartLifecyclepublic final boolean isRunning()
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.
isRunning in interface org.springframework.context.Lifecyclepublic boolean isBrokerAvailable()
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.
public void handleMessage(Message<?> message)
MessageHandlerhandleMessage in interface MessageHandlermessage - the message to be handledprotected abstract void handleMessageInternal(Message<?> message)
protected boolean checkDestinationPrefix(@Nullable
String destination)
destination prefixes.
userDestinationPredicate.
destination - the destination to checkprotected void publishBrokerAvailableEvent()
protected void publishBrokerUnavailableEvent()
protected MessageChannel getClientOutboundChannelForSession(String sessionId)
preservePublishOrder=true.