public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler
SimpMessageType
, keeps track of subscriptions with the help of a
SubscriptionRegistry
and sends messages to subscribers.logger
Constructor and Description |
---|
SimpleBrokerMessageHandler(SubscribableChannel clientInboundChannel,
MessageChannel clientOutboundChannel,
SubscribableChannel brokerChannel,
java.util.Collection<java.lang.String> destinationPrefixes)
Create a SimpleBrokerMessageHandler instance with the given message channels
and destination prefixes.
|
Modifier and Type | Method and Description |
---|---|
MessageHeaderInitializer |
getHeaderInitializer()
Return the configured header initializer.
|
long[] |
getHeartbeatValue()
The configured value for the heart-beat settings.
|
SubscriptionRegistry |
getSubscriptionRegistry() |
TaskScheduler |
getTaskScheduler()
Return the configured TaskScheduler.
|
protected void |
handleMessageInternal(Message<?> message) |
protected void |
sendMessageToSubscribers(java.lang.String destination,
Message<?> message) |
void |
setCacheLimit(java.lang.Integer cacheLimit)
When configured, the specified cache limit is passed down to the
underlying SubscriptionRegistry, overriding any default there.
|
void |
setHeaderInitializer(MessageHeaderInitializer headerInitializer)
Configure a
MessageHeaderInitializer to apply to the headers
of all messages sent to the client outbound channel. |
void |
setHeartbeatValue(long[] heartbeat)
Configure the value for the heart-beat settings.
|
void |
setPathMatcher(PathMatcher pathMatcher)
When configured, the given PathMatcher is passed down to the underlying
SubscriptionRegistry to use for matching destination to subscriptions.
|
void |
setSelectorHeaderName(java.lang.String selectorHeaderName)
Configure the name of a header that a subscription message can have for
the purpose of filtering messages matched to the subscription.
|
void |
setSubscriptionRegistry(SubscriptionRegistry subscriptionRegistry)
Configure a custom SubscriptionRegistry to use for storing subscriptions.
|
void |
setTaskScheduler(TaskScheduler taskScheduler)
Configure the
TaskScheduler to
use for providing heartbeat support. |
void |
startInternal() |
void |
stopInternal() |
java.lang.String |
toString() |
checkDestinationPrefix, getApplicationEventPublisher, getBrokerChannel, getClientInboundChannel, getClientOutboundChannel, getDestinationPrefixes, getPhase, handleMessage, isAutoStartup, isBrokerAvailable, isRunning, publishBrokerAvailableEvent, publishBrokerUnavailableEvent, setApplicationEventPublisher, setAutoStartup, start, stop, stop
public SimpleBrokerMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SubscribableChannel brokerChannel, java.util.Collection<java.lang.String> destinationPrefixes)
clientInboundChannel
- the channel for receiving messages from clients (e.g. WebSocket clients)clientOutboundChannel
- 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 void setSubscriptionRegistry(SubscriptionRegistry subscriptionRegistry)
Note that when a custom PathMatcher is configured via
setPathMatcher(org.springframework.util.PathMatcher)
, if the custom registry is not an instance of
DefaultSubscriptionRegistry
, the provided PathMatcher is not used
and must be configured directly on the custom registry.
public SubscriptionRegistry getSubscriptionRegistry()
public void setPathMatcher(@Nullable PathMatcher pathMatcher)
Default is a standard AntPathMatcher
.
public void setCacheLimit(@Nullable java.lang.Integer cacheLimit)
With a standard DefaultSubscriptionRegistry
, the default
cache limit is 1024.
public void setSelectorHeaderName(@Nullable java.lang.String selectorHeaderName)
For example:
headers.foo == 'bar'
By default this is set to "selector". You can set it to a different
name, or to null
to turn off support for a selector header.
selectorHeaderName
- the name to use for a selector headersetSubscriptionRegistry(org.springframework.messaging.simp.broker.SubscriptionRegistry)
,
DefaultSubscriptionRegistry.setSelectorHeaderName(String)
public void setTaskScheduler(@Nullable TaskScheduler taskScheduler)
TaskScheduler
to
use for providing heartbeat support. Setting this property also sets the
heartbeatValue
to "10000, 10000".
By default this is not set.
@Nullable public TaskScheduler getTaskScheduler()
public void setHeartbeatValue(@Nullable long[] heartbeat)
By default this is set to "0, 0" unless the taskScheduler
in which case the default becomes "10000,10000"
(in milliseconds).
@Nullable public long[] getHeartbeatValue()
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer)
MessageHeaderInitializer
to apply to the headers
of all messages sent to the client outbound channel.
By default this property is not set.
@Nullable public MessageHeaderInitializer getHeaderInitializer()
public void startInternal()
startInternal
in class AbstractBrokerMessageHandler
public void stopInternal()
stopInternal
in class AbstractBrokerMessageHandler
protected void handleMessageInternal(Message<?> message)
handleMessageInternal
in class AbstractBrokerMessageHandler
protected void sendMessageToSubscribers(@Nullable java.lang.String destination, Message<?> message)
public java.lang.String toString()
toString
in class java.lang.Object