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 AbstractBrokerMessageHandler
loggerFields inherited from interface SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionSimpleBrokerMessageHandler(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 @Nullable []The configured value for the heart-beat settings.Return the configured TaskScheduler.protected voidhandleMessageInternal(Message<?> message) protected voidsendMessageToSubscribers(@Nullable String destination, Message<?> message) voidsetCacheLimit(@Nullable Integer cacheLimit) When configured, the specified cache limit is passed down to the underlying SubscriptionRegistry, overriding any default there.voidsetHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) Configure aMessageHeaderInitializerto apply to the headers of all messages sent to the client outbound channel.voidsetHeartbeatValue(long @Nullable [] heartbeat) Configure the value for the heart-beat settings.voidsetPathMatcher(@Nullable PathMatcher pathMatcher) When configured, the given PathMatcher is passed down to the underlying SubscriptionRegistry to use for matching destination to subscriptions.voidsetSelectorHeaderName(@Nullable String selectorHeaderName) Configure the name of a header that a subscription message can have for the purpose of filtering messages matched to the subscription.voidsetSubscriptionRegistry(SubscriptionRegistry subscriptionRegistry) Configure a customSubscriptionRegistryto use for storing subscriptions.voidsetTaskScheduler(@Nullable TaskScheduler taskScheduler) Configure theTaskSchedulerto use for providing heartbeat support.voidvoidtoString()Methods inherited from class AbstractBrokerMessageHandler
checkDestinationPrefix, getApplicationEventPublisher, getBrokerChannel, getClientInboundChannel, getClientOutboundChannel, getClientOutboundChannelForSession, getDestinationPrefixes, getPhase, handleMessage, isAutoStartup, isBrokerAvailable, isPreservePublishOrder, isRunning, publishBrokerAvailableEvent, publishBrokerUnavailableEvent, setApplicationEventPublisher, setAutoStartup, setPhase, setPreservePublishOrder, setUserDestinationPredicate, start, stop, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface SmartLifecycle
isPauseable
-
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 (for example, WebSocket clients)clientOutboundChannel- the channel for sending messages to clients (for example, 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 customSubscriptionRegistryto 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.- Since:
- 4.1
- See Also:
-
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.- Since:
- 4.3.2
- See Also:
-
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
nullwhich 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, ornullor blank to disable selector header support- Since:
- 4.3.17
- See Also:
-
setTaskScheduler
Configure theTaskSchedulerto use for providing heartbeat support. Setting this property also sets theheartbeatValueto "10000, 10000".By default this is not set.
- Since:
- 4.2
-
getTaskScheduler
-
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
taskSchedulerin 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 aMessageHeaderInitializerto 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:
startInternalin classAbstractBrokerMessageHandler
-
stopInternal
public void stopInternal()- Overrides:
stopInternalin classAbstractBrokerMessageHandler
-
handleMessageInternal
- Specified by:
handleMessageInternalin classAbstractBrokerMessageHandler
-
sendMessageToSubscribers
-
toString
-