org.springframework.messaging.simp.broker

## Class SimpleBrokerMessageHandler

- java.lang.Object
- - org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler
  - - org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler

All Implemented Interfaces:
  org.springframework.beans.factory.Aware, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, MessageHandler

    public class SimpleBrokerMessageHandler
    extends AbstractBrokerMessageHandler

A "simple" message broker that recognizes the message types defined in `SimpMessageType`, keeps track of subscriptions with the help of a `SubscriptionRegistry` and sends messages to subscribers.

Since:
  4.0
Author:
  Rossen Stoyanchev, Juergen Hoeller

### 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

Constructors
Constructor and Description
`SimpleBrokerMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes)` Create a SimpleBrokerMessageHandler instance with the given message channels and destination prefixes.

### Method Summary

All Methods Instance Methods Concrete Methods
`MessageHeaderInitializer` `getHeaderInitializer()` Return the configured header initializer.
`long[]` `getHeartbeatValue()` The configured value for the heart-beat settings.
`SubscriptionRegistry` `getSubscriptionRegistry()`
`org.springframework.scheduling.TaskScheduler` `getTaskScheduler()` 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 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(org.springframework.util.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 custom SubscriptionRegistry to use for storing subscriptions.
`void` `setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler)` Configure the `TaskScheduler` to use for providing heartbeat support.
`void` `startInternal()`
`void` `stopInternal()`
`String` `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, 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 Detail

#### 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 broker
  `destinationPrefixes` - prefixes to use to filter out messages

### Method Detail

#### 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 of `DefaultSubscriptionRegistry`, the provided PathMatcher is not used and must be configured directly on the custom registry.

#### getSubscriptionRegistry

    public SubscriptionRegistry getSubscriptionRegistry()

#### setPathMatcher

    public void setPathMatcher(@Nullable
                               org.springframework.util.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`.

Since:
  4.1
See Also:
  `setSubscriptionRegistry(org.springframework.messaging.simp.broker.SubscriptionRegistry)`, `DefaultSubscriptionRegistry.setPathMatcher(org.springframework.util.PathMatcher)`, `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.

Since:
  4.3.2
See Also:
  `setSubscriptionRegistry(org.springframework.messaging.simp.broker.SubscriptionRegistry)`, `DefaultSubscriptionRegistry.setCacheLimit(int)`, `DefaultSubscriptionRegistry.DEFAULT_CACHE_LIMIT`

#### 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 `null` to turn off support for a selector header.

Parameters:
  `selectorHeaderName` - the name to use for a selector header
Since:
  4.3.17
See Also:
  `setSubscriptionRegistry(org.springframework.messaging.simp.broker.SubscriptionRegistry)`, `DefaultSubscriptionRegistry.setSelectorHeaderName(String)`

#### setTaskScheduler

    public void setTaskScheduler(@Nullable
                                 org.springframework.scheduling.TaskScheduler taskScheduler)

Configure the `TaskScheduler` to use for providing heartbeat support. Setting this property also sets the `heartbeatValue` to "10000, 10000".

By default this is not set.

Since:
  4.2

#### getTaskScheduler

    @Nullable
    public org.springframework.scheduling.TaskScheduler getTaskScheduler()

Return the configured TaskScheduler.

Since:
  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 `taskScheduler` in which case the default becomes "10000,10000" (in milliseconds).

Since:
  4.2

#### getHeartbeatValue

    @Nullable
    public long[] getHeartbeatValue()

The configured value for the heart-beat settings.

Since:
  4.2

#### setHeaderInitializer

    public void setHeaderInitializer(@Nullable
                                     MessageHeaderInitializer headerInitializer)

Configure a `MessageHeaderInitializer` 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

    @Nullable
    public MessageHeaderInitializer getHeaderInitializer()

Return the configured header initializer.

Since:
  4.1

#### startInternal

    public void startInternal()

Overrides:
  `startInternal` in class `AbstractBrokerMessageHandler`

#### stopInternal

    public void stopInternal()

Overrides:
  `stopInternal` in class `AbstractBrokerMessageHandler`

#### handleMessageInternal

    protected void handleMessageInternal(Message<?> message)

Specified by:
  `handleMessageInternal` in class `AbstractBrokerMessageHandler`

#### sendMessageToSubscribers

    protected void sendMessageToSubscribers(@Nullable
                                            String destination,
                                            Message<?> message)

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`