Top Description Fields Constructors Methods
org.springframework.messaging.simp.config

public Class MessageBrokerRegistry

extends Object
Class Inheritance
Imports
java.util.Arrays, .Collection, org.springframework.context.event.SmartApplicationListener, org.springframework.lang.Nullable, org.springframework.messaging.MessageChannel, .SubscribableChannel, org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler, org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler, org.springframework.util.Assert, .PathMatcher

A registry for configuring message broker options.
Authors
Rossen Stoyanchev, Sebastien Deleuze
Since
4.0

Field Summary

Modifier and TypeField and Description
private String[]
private final ChannelRegistration
private StompBrokerRelayRegistration
private Integer
private final SubscribableChannel
private final MessageChannel
private PathMatcher
private boolean
private SimpleBrokerRegistration
private String
private Integer

Constructor Summary

AccessConstructor and Description
public
MessageBrokerRegistry(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel)

Method Summary

Modifier and TypeMethod and Description
public ChannelRegistration
configureBrokerChannel()

Customize the channel used to send messages from the application to the message broker.

public SimpleBrokerRegistration
enableSimpleBroker(String... destinationPrefixes)

Enable a simple message broker and configure one or more prefixes to filter destinations targeting the broker (e.g. destinations prefixed with "/topic").

public StompBrokerRelayRegistration
enableStompBrokerRelay(String... destinationPrefixes)

Enable a STOMP broker relay and configure the destination prefixes supported by the message broker.

protected Collection<String>
protected ChannelRegistration
protected PathMatcher
protected SimpleBrokerMessageHandler
protected StompBrokerRelayMessageHandler
protected String
protected String
protected String
protected Integer
public MessageBrokerRegistry
setApplicationDestinationPrefixes(String... prefixes)

Configure one or more prefixes to filter destinations targeting application annotated methods.

public MessageBrokerRegistry
setCacheLimit(int cacheLimit)

Configure the cache limit to apply for registrations with the broker.

public MessageBrokerRegistry
setPathMatcher(PathMatcher pathMatcher)

Configure the PathMatcher to use to match the destinations of incoming messages to @MessageMapping and @SubscribeMapping methods.

public MessageBrokerRegistry
setPreservePublishOrder(boolean preservePublishOrder)

Whether the client must receive messages in the order of publication.

public MessageBrokerRegistry
setUserDestinationPrefix(String destinationPrefix)

Configure the prefix used to identify user destinations.

public void
setUserRegistryOrder(int
the order value
order
)

Set the order for the SimpUserRegistry to use as a SmartApplicationListener.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

applicationDestinationPrefixesback to summary
private String[] applicationDestinationPrefixes
Annotations
@Nullable
brokerChannelRegistrationback to summary
private final ChannelRegistration brokerChannelRegistration
brokerRelayRegistrationback to summary
private StompBrokerRelayRegistration brokerRelayRegistration
Annotations
@Nullable
cacheLimitback to summary
private Integer cacheLimit
Annotations
@Nullable
clientInboundChannelback to summary
private final SubscribableChannel clientInboundChannel
clientOutboundChannelback to summary
private final MessageChannel clientOutboundChannel
pathMatcherback to summary
private PathMatcher pathMatcher
Annotations
@Nullable
preservePublishOrderback to summary
private boolean preservePublishOrder
simpleBrokerRegistrationback to summary
private SimpleBrokerRegistration simpleBrokerRegistration
Annotations
@Nullable
userDestinationPrefixback to summary
private String userDestinationPrefix
Annotations
@Nullable
userRegistryOrderback to summary
private Integer userRegistryOrder
Annotations
@Nullable

Constructor Detail

MessageBrokerRegistryback to summary
public MessageBrokerRegistry(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel)

Method Detail

configureBrokerChannelback to summary
public ChannelRegistration configureBrokerChannel()

Customize the channel used to send messages from the application to the message broker. By default, messages from the application to the message broker are sent synchronously, which means application code sending a message will find out if the message cannot be sent through an exception. However, this can be changed if the broker channel is configured here with task executor properties.

enableSimpleBrokerback to summary
public SimpleBrokerRegistration enableSimpleBroker(String... destinationPrefixes)

Enable a simple message broker and configure one or more prefixes to filter destinations targeting the broker (e.g. destinations prefixed with "/topic").

enableStompBrokerRelayback to summary
public StompBrokerRelayRegistration enableStompBrokerRelay(String... destinationPrefixes)

Enable a STOMP broker relay and configure the destination prefixes supported by the message broker. Check the STOMP documentation of the message broker for supported destinations.

getApplicationDestinationPrefixesback to summary
protected Collection<String> getApplicationDestinationPrefixes()
Annotations
@Nullable
getBrokerChannelRegistrationback to summary
protected ChannelRegistration getBrokerChannelRegistration()
getPathMatcherback to summary
protected PathMatcher getPathMatcher()
Annotations
@Nullable
getSimpleBrokerback to summary
protected SimpleBrokerMessageHandler getSimpleBroker(SubscribableChannel brokerChannel)
Annotations
@Nullable
getStompBrokerRelayback to summary
protected StompBrokerRelayMessageHandler getStompBrokerRelay(SubscribableChannel brokerChannel)
Annotations
@Nullable
getUserDestinationBroadcastback to summary
protected String getUserDestinationBroadcast()
Annotations
@Nullable
getUserDestinationPrefixback to summary
protected String getUserDestinationPrefix()
Annotations
@Nullable
getUserRegistryBroadcastback to summary
protected String getUserRegistryBroadcast()
Annotations
@Nullable
getUserRegistryOrderback to summary
protected Integer getUserRegistryOrder()
Annotations
@Nullable
setApplicationDestinationPrefixesback to summary
public MessageBrokerRegistry setApplicationDestinationPrefixes(String... prefixes)

Configure one or more prefixes to filter destinations targeting application annotated methods. For example destinations prefixed with "/app" may be processed by annotated methods while other destinations may target the message broker (e.g. "/topic", "/queue").

When messages are processed, the matching prefix is removed from the destination in order to form the lookup path. This means annotations should not contain the destination prefix.

Prefixes that do not have a trailing slash will have one automatically appended.

setCacheLimitback to summary
public MessageBrokerRegistry setCacheLimit(int cacheLimit)

Configure the cache limit to apply for registrations with the broker.

This is currently only applied for the destination cache in the subscription registry. The default cache limit there is 1024.

Since
4.3.2
See Also
org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry#setCacheLimit
setPathMatcherback to summary
public MessageBrokerRegistry setPathMatcher(PathMatcher pathMatcher)

Configure the PathMatcher to use to match the destinations of incoming messages to @MessageMapping and @SubscribeMapping methods.

By default org.springframework.util.AntPathMatcher is configured. However applications may provide an AntPathMatcher instance customized to use "." (commonly used in messaging) instead of "/" as path separator or provide a completely different PathMatcher implementation.

Note that the configured PathMatcher is only used for matching the portion of the destination after the configured prefix. For example given application destination prefix "/app" and destination "/app/price.stock.**", the message might be mapped to a controller with "price" and "stock.**" as its type and method-level mappings respectively.

When the simple broker is enabled, the PathMatcher configured here is also used to match message destinations when brokering messages.

Since
4.1
See Also
org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry#setPathMatcher
setPreservePublishOrderback to summary
public MessageBrokerRegistry setPreservePublishOrder(boolean preservePublishOrder)

Whether the client must receive messages in the order of publication.

By default messages sent to the "clientOutboundChannel" may not be processed in the same order because the channel is backed by a ThreadPoolExecutor that in turn does not guarantee processing in order.

When this flag is set to true messages within the same session will be sent to the "clientOutboundChannel" one at a time in order to preserve the order of publication.

Since
5.1
setUserDestinationPrefixback to summary
public MessageBrokerRegistry setUserDestinationPrefix(String destinationPrefix)

Configure the prefix used to identify user destinations. User destinations provide the ability for a user to subscribe to queue names unique to their session as well as for others to send messages to those unique, user-specific queues.

For example when a user attempts to subscribe to "/user/queue/position-updates", the destination may be translated to "/queue/position-updatesi9oqdfzo" yielding a unique queue name that does not collide with any other user attempting to do the same. Subsequently when messages are sent to "/user/{username}/queue/position-updates", the destination is translated to "/queue/position-updatesi9oqdfzo".

The default prefix used to identify such destinations is "/user/".

setUserRegistryOrderback to summary
public void setUserRegistryOrder(int order)

Set the order for the SimpUserRegistry to use as a SmartApplicationListener.

Parameters
order:int

the order value

Since
5.0.8