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

public abstract Class AbstractMessageBrokerConfiguration

extends Object
implements ApplicationContextAware
Class Inheritance
All Implemented Interfaces
org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.Aware
Imports
java.util.ArrayList, .Collection, .HashMap, .List, .Map, java.util.function.Supplier, org.springframework.beans.factory.BeanInitializationException, org.springframework.beans.factory.annotation.Qualifier, org.springframework.context.ApplicationContext, .ApplicationContextAware, .SmartLifecycle, org.springframework.context.annotation.Bean, org.springframework.context.event.SmartApplicationListener, org.springframework.core.task.TaskExecutor, org.springframework.lang.Nullable, org.springframework.messaging.MessageHandler, org.springframework.messaging.converter.ByteArrayMessageConverter, .CompositeMessageConverter, .DefaultContentTypeResolver, .GsonMessageConverter, .JsonbMessageConverter, .KotlinSerializationJsonMessageConverter, .MappingJackson2MessageConverter, .MessageConverter, .StringMessageConverter, org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver, .HandlerMethodReturnValueHandler, org.springframework.messaging.simp.SimpLogging, .SimpMessagingTemplate, org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler, org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler, .SimpleBrokerMessageHandler, org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler, org.springframework.messaging.simp.user.DefaultUserDestinationResolver, .MultiServerUserRegistry, .SimpUserRegistry, .UserDestinationMessageHandler, .UserDestinationResolver, .UserRegistryMessageHandler, org.springframework.messaging.support.AbstractSubscribableChannel, .ExecutorSubscribableChannel, .ImmutableMessageChannelInterceptor, org.springframework.scheduling.TaskScheduler, org.springframework.scheduling.concurrent.ExecutorConfigurationSupport, .ThreadPoolTaskExecutor, .ThreadPoolTaskScheduler, org.springframework.util.Assert, .ClassUtils, .CustomizableThreadCreator, .MimeTypeUtils, .PathMatcher, .StringUtils, org.springframework.validation.Errors, .Validator, org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean

Provides essential configuration for handling messages with simple messaging protocols such as STOMP.

clientInboundChannel and clientOutboundChannel deliver messages to and from remote clients to several message handlers such as the following.

brokerChannel delivers messages from within the application to the respective message handlers. brokerMessagingTemplate can be injected into any application component to send messages.

Subclasses are responsible for the parts of the configuration that feed messages to and from the client inbound/outbound channels (e.g. STOMP over WebSocket).

Authors
Rossen Stoyanchev, Brian Clozel, Sebastien Deleuze
Since
4.0

Field Summary

Modifier and TypeField and Description
private ApplicationContext
private MessageBrokerRegistry
private ChannelRegistration
private ChannelRegistration
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final String
private Integer

Constructor Summary

AccessConstructor and Description
protected
AbstractMessageBrokerConfiguration()

Protected constructor.

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
public AbstractSubscribableChannel
brokerChannel(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, TaskExecutor executor)

public TaskExecutor
public CompositeMessageConverter
public SimpMessagingTemplate
brokerMessagingTemplate(AbstractSubscribableChannel brokerChannel, AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, CompositeMessageConverter brokerMessageConverter)

public AbstractSubscribableChannel
public TaskExecutor
public AbstractSubscribableChannel
public TaskExecutor
protected void
configureClientInboundChannel(ChannelRegistration registration)

A hook for subclasses to customize the message channel for inbound messages from WebSocket clients.

protected void
configureClientOutboundChannel(ChannelRegistration registration)

A hook for subclasses to customize the message channel for messages from the application or message broker to WebSocket clients.

protected void
configureMessageBroker(MessageBrokerRegistry registry)

A hook for subclasses to customize message broker configuration through the provided MessageBrokerRegistry instance.

protected boolean

Returns:

true if default message converters should be added to list, false if no more converters should be added
configureMessageConverters
(List<MessageConverter>
the list to add converters to, initially empty
messageConverters
)

Override this method to add custom message converters.

protected SimpAnnotationMethodMessageHandler
createAnnotationMethodMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, SimpMessagingTemplate brokerMessagingTemplate)

Protected method for plugging in a custom subclass of SimpAnnotationMethodMessageHandler.

protected MappingJackson2MessageConverter
protected abstract SimpUserRegistry
createLocalUserRegistry(Integer
the order to use as a SmartApplicationListener.
order
)

Create the user registry that provides access to local users.

private TaskExecutor
public ApplicationContext
protected final MessageBrokerRegistry
getBrokerRegistry(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel)

An accessor for the MessageBrokerRegistry that ensures its one-time creation and initialization through configureMessageBroker(MessageBrokerRegistry).

protected final ChannelRegistration
protected final ChannelRegistration
public final PathMatcher
getPathMatcher(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel)

Provide access to the configured PatchMatcher for access from other configuration classes.

protected final int
private static TaskExecutor
getTaskExecutor(ChannelRegistration registration, String threadNamePrefix, Supplier<TaskExecutor> fallback)

public Validator
getValidator()

Override this method to provide a custom Validator.

protected int
public TaskScheduler
public void
setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object
applicationContext
)

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.
private static void
public SimpAnnotationMethodMessageHandler
simpAnnotationMethodMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, SimpMessagingTemplate brokerMessagingTemplate, CompositeMessageConverter brokerMessageConverter)

public AbstractBrokerMessageHandler
simpleBrokerMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, AbstractSubscribableChannel brokerChannel, UserDestinationResolver userDestinationResolver)

protected Validator
simpValidator()

Return an org.springframework.validation.Validator instance for validating @Payload method arguments.

public AbstractBrokerMessageHandler
stompBrokerRelayMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, AbstractSubscribableChannel brokerChannel, UserDestinationMessageHandler userDestinationMessageHandler, MessageHandler userRegistryMessageHandler, UserDestinationResolver userDestinationResolver)

private void
updateUserDestinationResolver(AbstractBrokerMessageHandler handler, UserDestinationResolver userDestinationResolver, String userDestinationPrefix)

public UserDestinationMessageHandler
userDestinationMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, AbstractSubscribableChannel brokerChannel, UserDestinationResolver userDestinationResolver)

public UserDestinationResolver
userDestinationResolver(SimpUserRegistry userRegistry, AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel)

public SimpUserRegistry
userRegistry(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel)

public MessageHandler
userRegistryMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, SimpUserRegistry userRegistry, SimpMessagingTemplate brokerMessagingTemplate, TaskScheduler scheduler)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

applicationContextback to summary
private ApplicationContext applicationContext
Annotations
@Nullable
brokerRegistryback to summary
private MessageBrokerRegistry brokerRegistry
Annotations
@Nullable
clientInboundChannelRegistrationback to summary
private ChannelRegistration clientInboundChannelRegistration
Annotations
@Nullable
clientOutboundChannelRegistrationback to summary
private ChannelRegistration clientOutboundChannelRegistration
Annotations
@Nullable
gsonPresentback to summary
private static final boolean gsonPresent
jackson2Presentback to summary
private static final boolean jackson2Present
jsonbPresentback to summary
private static final boolean jsonbPresent
kotlinSerializationJsonPresentback to summary
private static final boolean kotlinSerializationJsonPresent
MVC_VALIDATOR_NAMEback to summary
private static final String MVC_VALIDATOR_NAME
phaseback to summary
private Integer phase
Annotations
@Nullable

Constructor Detail

AbstractMessageBrokerConfigurationback to summary
protected AbstractMessageBrokerConfiguration()

Protected constructor.

Method Detail

addArgumentResolversback to summary
protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)
addReturnValueHandlersback to summary
protected void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)
brokerChannelback to summary
public AbstractSubscribableChannel brokerChannel(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, TaskExecutor executor)
Annotations
@Bean
brokerChannelExecutorback to summary
public TaskExecutor brokerChannelExecutor(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel)
Annotations
@Bean
brokerMessageConverterback to summary
public CompositeMessageConverter brokerMessageConverter()
Annotations
@Bean
brokerMessagingTemplateback to summary
public SimpMessagingTemplate brokerMessagingTemplate(AbstractSubscribableChannel brokerChannel, AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, CompositeMessageConverter brokerMessageConverter)
Annotations
@Bean
clientInboundChannelback to summary
public AbstractSubscribableChannel clientInboundChannel(TaskExecutor executor)
Annotations
@Bean
clientInboundChannelExecutorback to summary
public TaskExecutor clientInboundChannelExecutor()
Annotations
@Bean
clientOutboundChannelback to summary
public AbstractSubscribableChannel clientOutboundChannel(TaskExecutor executor)
Annotations
@Bean
clientOutboundChannelExecutorback to summary
public TaskExecutor clientOutboundChannelExecutor()
Annotations
@Bean
configureClientInboundChannelback to summary
protected void configureClientInboundChannel(ChannelRegistration registration)

A hook for subclasses to customize the message channel for inbound messages from WebSocket clients.

configureClientOutboundChannelback to summary
protected void configureClientOutboundChannel(ChannelRegistration registration)

A hook for subclasses to customize the message channel for messages from the application or message broker to WebSocket clients.

configureMessageBrokerback to summary
protected void configureMessageBroker(MessageBrokerRegistry registry)

A hook for subclasses to customize message broker configuration through the provided MessageBrokerRegistry instance.

configureMessageConvertersback to summary
protected boolean configureMessageConverters(List<MessageConverter> messageConverters)

Override this method to add custom message converters.

Parameters
messageConverters:List<MessageConverter>

the list to add converters to, initially empty

Returns:boolean

true if default message converters should be added to list, false if no more converters should be added

createAnnotationMethodMessageHandlerback to summary
protected SimpAnnotationMethodMessageHandler createAnnotationMethodMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, SimpMessagingTemplate brokerMessagingTemplate)

Protected method for plugging in a custom subclass of SimpAnnotationMethodMessageHandler.

Since
5.3.2
createJacksonConverterback to summary
protected MappingJackson2MessageConverter createJacksonConverter()
createLocalUserRegistryback to summary
protected abstract SimpUserRegistry createLocalUserRegistry(Integer order)

Create the user registry that provides access to local users.

Parameters
order:Integer

the order to use as a SmartApplicationListener.

Since
5.1
defaultTaskExecutorback to summary
private TaskExecutor defaultTaskExecutor()
getApplicationContextback to summary
public ApplicationContext getApplicationContext()
Annotations
@Nullable
getBrokerRegistryback to summary
protected final MessageBrokerRegistry getBrokerRegistry(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel)

An accessor for the MessageBrokerRegistry that ensures its one-time creation and initialization through configureMessageBroker(MessageBrokerRegistry).

getClientInboundChannelRegistrationback to summary
protected final ChannelRegistration getClientInboundChannelRegistration()
getClientOutboundChannelRegistrationback to summary
protected final ChannelRegistration getClientOutboundChannelRegistration()
getPathMatcherback to summary
public final PathMatcher getPathMatcher(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel)

Provide access to the configured PatchMatcher for access from other configuration classes.

Annotations
@Nullable
getPhaseback to summary
protected final int getPhase()
getTaskExecutorback to summary
private static TaskExecutor getTaskExecutor(ChannelRegistration registration, String threadNamePrefix, Supplier<TaskExecutor> fallback)
getValidatorback to summary
public Validator getValidator()

Override this method to provide a custom Validator.

Annotations
@Nullable
Since
4.0.1
initPhaseback to summary
protected int initPhase()
messageBrokerTaskSchedulerback to summary
public TaskScheduler messageBrokerTaskScheduler()
Annotations
@Bean
name:messageBrokerTaskScheduler, messageBrokerSockJsTaskScheduler
setApplicationContextback to summary
public void setApplicationContext(ApplicationContext applicationContext)

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Doc from org.springframework.context.ApplicationContextAware.setApplicationContext.

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Invoked after population of normal bean properties but before an init callback such as org.springframework.beans.factory.InitializingBean#afterPropertiesSet() or a custom init-method. Invoked after ResourceLoaderAware#setResourceLoader, ApplicationEventPublisherAware#setApplicationEventPublisher and MessageSourceAware, if applicable.

Parameters
applicationContext:ApplicationContext

the ApplicationContext object to be used by this object

Annotations
@Override
setThreadNamePrefixback to summary
private static void setThreadNamePrefix(TaskExecutor taskExecutor, String name)
simpAnnotationMethodMessageHandlerback to summary
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, SimpMessagingTemplate brokerMessagingTemplate, CompositeMessageConverter brokerMessageConverter)
Annotations
@Bean
simpleBrokerMessageHandlerback to summary
public AbstractBrokerMessageHandler simpleBrokerMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, AbstractSubscribableChannel brokerChannel, UserDestinationResolver userDestinationResolver)
Annotations
@Bean
@Nullable
simpValidatorback to summary
protected Validator simpValidator()

Return an org.springframework.validation.Validator instance for validating @Payload method arguments.

In order, this method tries to get a Validator instance:

  • delegating to getValidator() first
  • if none returned, getting an existing instance with its well-known name "mvcValidator", created by an MVC configuration
  • if none returned, checking the classpath for the presence of a JSR-303 implementation before creating a OptionalValidatorFactoryBean
  • returning a no-op Validator instance
stompBrokerRelayMessageHandlerback to summary
public AbstractBrokerMessageHandler stompBrokerRelayMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, AbstractSubscribableChannel brokerChannel, UserDestinationMessageHandler userDestinationMessageHandler, MessageHandler userRegistryMessageHandler, UserDestinationResolver userDestinationResolver)
Annotations
@Bean
@Nullable
updateUserDestinationResolverback to summary
private void updateUserDestinationResolver(AbstractBrokerMessageHandler handler, UserDestinationResolver userDestinationResolver, String userDestinationPrefix)
userDestinationMessageHandlerback to summary
public UserDestinationMessageHandler userDestinationMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, AbstractSubscribableChannel brokerChannel, UserDestinationResolver userDestinationResolver)
Annotations
@Bean
userDestinationResolverback to summary
public UserDestinationResolver userDestinationResolver(SimpUserRegistry userRegistry, AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel)
Annotations
@Bean
userRegistryback to summary
public SimpUserRegistry userRegistry(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel)
Annotations
@Bean
userRegistryMessageHandlerback to summary
public MessageHandler userRegistryMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, SimpUserRegistry userRegistry, SimpMessagingTemplate brokerMessagingTemplate, TaskScheduler scheduler)
Annotations
@Bean
@Nullable