Class MessageMappingMessageHandler
- All Implemented Interfaces:
- Aware,- BeanNameAware,- InitializingBean,- ApplicationContextAware,- EmbeddedValueResolverAware,- ReactiveMessageHandler
- Direct Known Subclasses:
- RSocketMessageHandler
AbstractMethodMessageHandler for reactive, non-blocking
 handling of messages via @MessageMapping methods.
 By default, such methods are detected in @Controller Spring beans but
 that can be changed via AbstractMethodMessageHandler.setHandlerPredicate(Predicate).
 Payloads for incoming messages are decoded through the configured
 setDecoders(List) decoders, with the help of
 PayloadMethodArgumentResolver.
 
There is no default handling for return values but
 AbstractMethodMessageHandler.setReturnValueHandlerConfigurer(org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer) can be used to configure custom
 return value handlers. Subclasses may also override
 initReturnValueHandlers() to set up default return value handlers.
- Since:
- 5.2
- Author:
- Rossen Stoyanchev
- See Also:
- 
Field SummaryFields inherited from class org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandlerlogger
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected AbstractExceptionHandlerMethodResolvercreateExceptionMethodResolverFor(Class<?> beanType) Create a concrete instance ofAbstractExceptionHandlerMethodResolverthat finds exception handling methods based on some criteria, for example, based on the presence of@MessageExceptionHandler.protected CompositeMessageConditiongetCondition(AnnotatedElement element) Determine the mapping condition for the given annotated element.Return the configured ConversionService.Return the configured decoders.protected RouteMatcher.RoutegetDestination(Message<?> message) Extract the destination from the given message.Return String-based destinations for the given mapping, if any, that can be used to find matches with a direct lookup (i.e.protected Comparator<CompositeMessageCondition>getMappingComparator(Message<?> message) Return a comparator for sorting matching mappings.protected CompositeMessageConditiongetMappingForMethod(Method method, Class<?> handlerType) Obtain the mapping for the given method, if any.protected CompositeMessageConditiongetMatchingMapping(CompositeMessageCondition mapping, Message<?> message) Check if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.Return theRouteMatcherused to map messages to handlers.Return the configured Validator instance.protected reactor.core.publisher.Mono<Void>handleMatch(CompositeMessageCondition mapping, HandlerMethod handlerMethod, Message<?> message) protected List<? extends HandlerMethodArgumentResolver>Return the list of argument resolvers to use.protected List<? extends HandlerMethodReturnValueHandler>Return the list of return value handlers to use.protected RouteMatcherObtain theRouteMatcherfor actual use.protected String[]processDestinations(String[] destinations) Resolve placeholders in the given destinations.voidUse this method to register aMessagingAdviceBeanthat may contain globally applicable@MessageExceptionHandlermethods.voidsetConversionService(ConversionService conversionService) Configure aConversionServiceto use for type conversion of String based values, for example, in destination variables or headers.voidsetDecoders(List<? extends Decoder<?>> decoders) Configure the decoders to use for incoming payloads.voidsetEmbeddedValueResolver(StringValueResolver resolver) Set the StringValueResolver to use for resolving embedded definition values.voidsetRouteMatcher(RouteMatcher routeMatcher) Set theRouteMatcherto use for mapping messages to handlers based on the route patterns they're configured with.voidsetValidator(Validator validator) Set the Validator instance used for validating@Payloadarguments.Methods inherited from class org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandlerdetectHandlerMethods, extendMapping, getApplicationContext, getArgumentResolverConfigurer, getArgumentResolvers, getBeanName, getDestinationLookup, getHandlerMethods, getHandlerPredicate, getReactiveAdapterRegistry, getReturnValueHandlerConfigurer, handleMessage, handleNoMatch, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolverConfigurer, setBeanName, setHandlerPredicate, setHandlers, setReactiveAdapterRegistry, setReturnValueHandlerConfigurer
- 
Constructor Details- 
MessageMappingMessageHandlerpublic MessageMappingMessageHandler()
 
- 
- 
Method Details- 
setDecodersConfigure the decoders to use for incoming payloads.
- 
getDecodersReturn the configured decoders.
- 
setValidatorSet the Validator instance used for validating@Payloadarguments.- See Also:
 
- 
getValidatorReturn the configured Validator instance.
- 
setRouteMatcherSet theRouteMatcherto use for mapping messages to handlers based on the route patterns they're configured with.By default, SimpleRouteMatcheris used, backed byAntPathMatcherwith "." as separator. For greater efficiency consider using thePathPatternRouteMatcherfromspring-webinstead.
- 
getRouteMatcherReturn theRouteMatcherused to map messages to handlers. May benullbefore the component is initialized.
- 
obtainRouteMatcherObtain theRouteMatcherfor actual use.- Returns:
- the RouteMatcher (never null)
- Throws:
- IllegalStateException- in case of no RouteMatcher set
- Since:
- 5.0
 
- 
setConversionServiceConfigure aConversionServiceto use for type conversion of String based values, for example, in destination variables or headers.By default DefaultFormattingConversionServiceis used.- Parameters:
- conversionService- the conversion service to use
 
- 
getConversionServiceReturn the configured ConversionService.
- 
setEmbeddedValueResolverDescription copied from interface:EmbeddedValueResolverAwareSet the StringValueResolver to use for resolving embedded definition values.- Specified by:
- setEmbeddedValueResolverin interface- EmbeddedValueResolverAware
 
- 
registerMessagingAdviceUse this method to register aMessagingAdviceBeanthat may contain globally applicable@MessageExceptionHandlermethods.Note: spring-messaging does not depend on spring-web and therefore it is not possible to explicitly support the registration of a @ControllerAdvicebean. You can use the following adapter code to register@ControllerAdvicebeans here:ControllerAdviceBean.findAnnotatedBeans(context).forEach(bean -> messageHandler.registerMessagingAdvice(new ControllerAdviceWrapper(bean)); public class ControllerAdviceWrapper implements MessagingAdviceBean { private final ControllerAdviceBean delegate; // delegate all methods }- Parameters:
- bean- the bean to check for- @MessageExceptionHandlermethods
- Since:
- 5.3.5
 
- 
afterPropertiesSetpublic void afterPropertiesSet()Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. - Specified by:
- afterPropertiesSetin interface- InitializingBean
- Overrides:
- afterPropertiesSetin class- AbstractMethodMessageHandler<CompositeMessageCondition>
 
- 
initArgumentResolversDescription copied from class:AbstractMethodMessageHandlerReturn the list of argument resolvers to use.Subclasses should also take into account custom argument types configured via AbstractMethodMessageHandler.setArgumentResolverConfigurer(org.springframework.messaging.handler.invocation.reactive.ArgumentResolverConfigurer).- Specified by:
- initArgumentResolversin class- AbstractMethodMessageHandler<CompositeMessageCondition>
 
- 
initReturnValueHandlersDescription copied from class:AbstractMethodMessageHandlerReturn the list of return value handlers to use.Subclasses should also take into account custom return value types configured via AbstractMethodMessageHandler.setReturnValueHandlerConfigurer(org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer).- Specified by:
- initReturnValueHandlersin class- AbstractMethodMessageHandler<CompositeMessageCondition>
 
- 
getMappingForMethod@Nullable protected CompositeMessageCondition getMappingForMethod(Method method, Class<?> handlerType) Description copied from class:AbstractMethodMessageHandlerObtain the mapping for the given method, if any.- Specified by:
- getMappingForMethodin class- AbstractMethodMessageHandler<CompositeMessageCondition>
- Parameters:
- method- the method to check
- handlerType- the handler type, possibly a subtype of the method's declaring class
- Returns:
- the mapping, or nullif the method is not mapped
 
- 
getConditionDetermine the mapping condition for the given annotated element.- Parameters:
- element- the element to check
- Returns:
- the condition, or null
 
- 
processDestinationsResolve placeholders in the given destinations.- Parameters:
- destinations- the destinations
- Returns:
- new array with the processed destinations or the same array
 
- 
getDirectLookupMappingsDescription copied from class:AbstractMethodMessageHandlerReturn String-based destinations for the given mapping, if any, that can be used to find matches with a direct lookup (i.e. non-patterns).Note: This is completely optional. The mapping metadata for a subclass may support neither direct lookups, nor String based destinations. - Specified by:
- getDirectLookupMappingsin class- AbstractMethodMessageHandler<CompositeMessageCondition>
 
- 
getDestinationDescription copied from class:AbstractMethodMessageHandlerExtract the destination from the given message.- Specified by:
- getDestinationin class- AbstractMethodMessageHandler<CompositeMessageCondition>
- See Also:
 
- 
getMatchingMapping@Nullable protected CompositeMessageCondition getMatchingMapping(CompositeMessageCondition mapping, Message<?> message) Description copied from class:AbstractMethodMessageHandlerCheck if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.- Specified by:
- getMatchingMappingin class- AbstractMethodMessageHandler<CompositeMessageCondition>
- Parameters:
- mapping- the mapping to get a match for
- message- the message being handled
- Returns:
- the match or nullif there is no match
 
- 
getMappingComparatorDescription copied from class:AbstractMethodMessageHandlerReturn a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.- Specified by:
- getMappingComparatorin class- AbstractMethodMessageHandler<CompositeMessageCondition>
- Parameters:
- message- the current Message
- Returns:
- the comparator, never null
 
- 
createExceptionMethodResolverForprotected AbstractExceptionHandlerMethodResolver createExceptionMethodResolverFor(Class<?> beanType) Description copied from class:AbstractMethodMessageHandlerCreate a concrete instance ofAbstractExceptionHandlerMethodResolverthat finds exception handling methods based on some criteria, for example, based on the presence of@MessageExceptionHandler.- Specified by:
- createExceptionMethodResolverForin class- AbstractMethodMessageHandler<CompositeMessageCondition>
- Parameters:
- beanType- the class in which an exception occurred during handling
- Returns:
- the resolver to use
 
- 
handleMatchprotected reactor.core.publisher.Mono<Void> handleMatch(CompositeMessageCondition mapping, HandlerMethod handlerMethod, Message<?> message) - Overrides:
- handleMatchin class- AbstractMethodMessageHandler<CompositeMessageCondition>
 
 
-