类 SimpleBrokerMessageHandler
- java.lang.Object
- org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler
- org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler
public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler
A "simple" message broker that recognizes the message types defined inSimpMessageType, keeps track of subscriptions with the help of aSubscriptionRegistryand sends messages to subscribers.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler
logger
从接口继承的字段 org.springframework.context.SmartLifecycle
DEFAULT_PHASE
构造器概要
构造器 构造器 说明 SimpleBrokerMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes)Create a SimpleBrokerMessageHandler instance with the given message channels and destination prefixes.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 MessageHeaderInitializergetHeaderInitializer()Return the configured header initializer.long[]getHeartbeatValue()The configured value for the heart-beat settings.SubscriptionRegistrygetSubscriptionRegistry()TaskSchedulergetTaskScheduler()Return the configured TaskScheduler.protected voidhandleMessageInternal(Message<?> message)protected voidsendMessageToSubscribers(String destination, Message<?> message)voidsetCacheLimit(Integer cacheLimit)When configured, the specified cache limit is passed down to the underlying SubscriptionRegistry, overriding any default there.voidsetHeaderInitializer(MessageHeaderInitializer headerInitializer)Configure aMessageHeaderInitializerto apply to the headers of all messages sent to the client outbound channel.voidsetHeartbeatValue(long[] heartbeat)Configure the value for the heart-beat settings.voidsetPathMatcher(PathMatcher pathMatcher)When configured, the given PathMatcher is passed down to the underlying SubscriptionRegistry to use for matching destination to subscriptions.voidsetSelectorHeaderName(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 custom SubscriptionRegistry to use for storing subscriptions.voidsetTaskScheduler(TaskScheduler taskScheduler)Configure theTaskSchedulerto use for providing heartbeat support.voidstartInternal()voidstopInternal()StringtoString()从类继承的方法 org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler
checkDestinationPrefix, getApplicationEventPublisher, getBrokerChannel, getClientInboundChannel, getClientOutboundChannel, getClientOutboundChannelForSession, getDestinationPrefixes, handleMessage, isAutoStartup, isBrokerAvailable, isPreservePublishOrder, isRunning, publishBrokerAvailableEvent, publishBrokerUnavailableEvent, setApplicationEventPublisher, setAutoStartup, setPreservePublishOrder, start, stop, stop
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
从接口继承的方法 org.springframework.context.SmartLifecycle
getPhase
构造器详细资料
SimpleBrokerMessageHandler
public SimpleBrokerMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes)
Create a SimpleBrokerMessageHandler instance with the given message channels and destination prefixes.- 参数:
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
方法详细资料
setSubscriptionRegistry
public void setSubscriptionRegistry(SubscriptionRegistry subscriptionRegistry)
Configure a custom SubscriptionRegistry to use for storing subscriptions.Note that when a custom PathMatcher is configured via
setPathMatcher(org.springframework.util.PathMatcher), if the custom registry is not an instance ofDefaultSubscriptionRegistry, the provided PathMatcher is not used and must be configured directly on the custom registry.
getSubscriptionRegistry
public SubscriptionRegistry getSubscriptionRegistry()
setPathMatcher
public void setPathMatcher(@Nullable PathMatcher pathMatcher)
When configured, the given PathMatcher is passed down to the underlying SubscriptionRegistry to use for matching destination to subscriptions.Default is a standard
AntPathMatcher.
setCacheLimit
public void setCacheLimit(@Nullable Integer cacheLimit)
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.
setSelectorHeaderName
public void setSelectorHeaderName(@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. The header value is expected to be a Spring EL boolean expression to be applied to the headers of messages matched to the subscription.For example:
headers.foo == 'bar'
By default this is set to "selector". You can set it to a different name, or to
nullto turn off support for a selector header.- 参数:
selectorHeaderName- the name to use for a selector header- 从以下版本开始:
- 4.3.17
- 另请参阅:
setSubscriptionRegistry(org.springframework.messaging.simp.broker.SubscriptionRegistry),DefaultSubscriptionRegistry.setSelectorHeaderName(String)
setTaskScheduler
public void setTaskScheduler(@Nullable TaskScheduler taskScheduler)
Configure theTaskSchedulerto use for providing heartbeat support. Setting this property also sets theheartbeatValueto "10000, 10000".By default this is not set.
- 从以下版本开始:
- 4.2
getTaskScheduler
@Nullable public TaskScheduler getTaskScheduler()
Return the configured TaskScheduler.- 从以下版本开始:
- 4.2
setHeartbeatValue
public void setHeartbeatValue(@Nullable long[] heartbeat)
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).- 从以下版本开始:
- 4.2
getHeartbeatValue
@Nullable public long[] getHeartbeatValue()
The configured value for the heart-beat settings.- 从以下版本开始:
- 4.2
setHeaderInitializer
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer)
Configure aMessageHeaderInitializerto apply to the headers of all messages sent to the client outbound channel.By default this property is not set.
- 从以下版本开始:
- 4.1
getHeaderInitializer
@Nullable public MessageHeaderInitializer getHeaderInitializer()
Return the configured header initializer.- 从以下版本开始:
- 4.1
startInternal
public void startInternal()
stopInternal
public void stopInternal()
handleMessageInternal
protected void handleMessageInternal(Message<?> message)
sendMessageToSubscribers
protected void sendMessageToSubscribers(@Nullable String destination, Message<?> message)