Class SimpleBrokerMessageHandler
- All Implemented Interfaces:
Aware
,ApplicationEventPublisherAware
,Lifecycle
,Phased
,SmartLifecycle
,MessageHandler
SimpMessageType
, keeps track of subscriptions with the help of a
SubscriptionRegistry
, and sends messages to subscribers.- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
-
Field Summary
Fields inherited from class org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler
logger
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionSimpleBrokerMessageHandler
(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes) Create a SimpleBrokerMessageHandler instance with the given message channels and destination prefixes. -
Method Summary
Modifier and TypeMethodDescriptionReturn the configured header initializer.long[]
The configured value for the heart-beat settings.Return the configured TaskScheduler.protected void
handleMessageInternal
(Message<?> message) protected void
sendMessageToSubscribers
(String destination, Message<?> message) void
setCacheLimit
(Integer cacheLimit) When configured, the specified cache limit is passed down to the underlying SubscriptionRegistry, overriding any default there.void
setHeaderInitializer
(MessageHeaderInitializer headerInitializer) Configure aMessageHeaderInitializer
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
(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 customSubscriptionRegistry
to use for storing subscriptions.void
setTaskScheduler
(TaskScheduler taskScheduler) Configure theTaskScheduler
to use for providing heartbeat support.void
void
toString()
Methods inherited from class org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler
checkDestinationPrefix, getApplicationEventPublisher, getBrokerChannel, getClientInboundChannel, getClientOutboundChannel, getClientOutboundChannelForSession, getDestinationPrefixes, handleMessage, isAutoStartup, isBrokerAvailable, isPreservePublishOrder, isRunning, publishBrokerAvailableEvent, publishBrokerUnavailableEvent, setApplicationEventPublisher, setAutoStartup, setPreservePublishOrder, setUserDestinationPredicate, start, stop, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.context.SmartLifecycle
getPhase
-
Constructor Details
-
SimpleBrokerMessageHandler
public SimpleBrokerMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes) Create a SimpleBrokerMessageHandler instance with the given message channels and destination prefixes.- Parameters:
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 messages
-
-
Method Details
-
setSubscriptionRegistry
Configure a customSubscriptionRegistry
to use for storing subscriptions.NOTE: If the custom registry is not an instance of
DefaultSubscriptionRegistry
, the configuredPathMatcher
, cache limit, and selector header name are not used and must be configured directly on the custom registry. -
getSubscriptionRegistry
-
setPathMatcher
When configured, the given PathMatcher is passed down to the underlying SubscriptionRegistry to use for matching destination to subscriptions.Default is a standard
AntPathMatcher
.Setting this property has no effect if the underlying SubscriptionRegistry is not an instance of
DefaultSubscriptionRegistry
. -
setCacheLimit
When configured, the specified cache limit is passed down to the underlying SubscriptionRegistry, overriding any default there.With a standard
DefaultSubscriptionRegistry
, the default cache limit is 1024.Setting this property has no effect if the underlying SubscriptionRegistry is not an instance of
DefaultSubscriptionRegistry
. -
setSelectorHeaderName
Configure the name of a header that a subscription message can have for the purpose of filtering messages matched to the subscription.The header value is expected to be a Spring Expression Language (SpEL) boolean expression to be applied to the headers of messages matched to the subscription.
For example:
headers.foo == 'bar'
By default the selector header name is set to
null
which disables this feature. You can set it to"selector"
or a different name to enable support for a selector header.Setting this property has no effect if the underlying SubscriptionRegistry is not an instance of
DefaultSubscriptionRegistry
.- Parameters:
selectorHeaderName
- the name to use for a selector header, ornull
or blank to disable selector header support- Since:
- 4.3.17
- See Also:
-
setTaskScheduler
Configure theTaskScheduler
to use for providing heartbeat support. Setting this property also sets theheartbeatValue
to "10000, 10000".By default this is not set.
- Since:
- 4.2
-
getTaskScheduler
Return the configured TaskScheduler.- Since:
- 4.2
-
setHeartbeatValue
Configure the value for the heart-beat settings. The first number represents how often the server will write or send a heartbeat. The second is how often the client should write. 0 means no heartbeats.By default this is set to "0, 0" unless the
taskScheduler
in which case the default becomes "10000,10000" (in milliseconds).- Since:
- 4.2
-
getHeartbeatValue
The configured value for the heart-beat settings.- Since:
- 4.2
-
setHeaderInitializer
Configure aMessageHeaderInitializer
to apply to the headers of all messages sent to the client outbound channel.By default this property is not set.
- Since:
- 4.1
-
getHeaderInitializer
Return the configured header initializer.- Since:
- 4.1
-
startInternal
public void startInternal()- Overrides:
startInternal
in classAbstractBrokerMessageHandler
-
stopInternal
public void stopInternal()- Overrides:
stopInternal
in classAbstractBrokerMessageHandler
-
handleMessageInternal
- Specified by:
handleMessageInternal
in classAbstractBrokerMessageHandler
-
sendMessageToSubscribers
-
toString
-