Class RSocketMessageHandler
- All Implemented Interfaces:
- Aware,- BeanNameAware,- InitializingBean,- ApplicationContextAware,- EmbeddedValueResolverAware,- ReactiveMessageHandler
MessageMappingMessageHandler to handle RSocket
 requests with @MessageMapping and
 @ConnectMapping methods, also supporting use of
 @RSocketExchange.
 For server scenarios this class can be declared as a bean in Spring
 configuration and that would detect @MessageMapping methods in
 @Controller beans. What beans are checked can be changed through a
 handlerPredicate. Given an instance
 of this class, you can then use responder() to obtain a
 SocketAcceptor adapter to register with the
 RSocketServer.
 
For a client, possibly in the same process as a server, consider using the
 static factory method responder(RSocketStrategies, Object...) to
 obtain a client responder to be registered via
 RSocketRequester.Builder.
 
For @MessageMapping and @RSocketExchange methods,
 this class automatically determines the RSocket interaction type
 based on the input and output cardinality of the method. See the
 
 "Annotated Responders" section of the Spring Framework reference for more details.
- Since:
- 5.2
- Author:
- Rossen Stoyanchev, Olga Maciaszek-Sharma
- 
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 CompositeMessageConditionextendMapping(CompositeMessageCondition composite, HandlerMethod handler) This method is invoked just before mappings are added.protected CompositeMessageConditiongetCondition(AnnotatedElement element) Determine the mapping condition for the given annotated element.Return the configureddefaultDataMimeType, ornull.Return the configureddefaultMetadataMimeType.Return the configuredencoders.Return the configuredMetadataExtractor.Return theconfiguredRSocketStrategies.protected voidhandleNoMatch(RouteMatcher.Route destination, Message<?> message) Invoked when no matching handler is found.protected List<? extends HandlerMethodReturnValueHandler>Return the list of return value handlers to use.io.rsocket.SocketAcceptorReturn an RSocketSocketAcceptorbacked by thisRSocketMessageHandlerinstance that can be plugged in as aclientorserverRSocket responder.static io.rsocket.SocketAcceptorresponder(RSocketStrategies strategies, Object... candidateHandlers) Static factory method to create an RSocketSocketAcceptorbacked by handlers with annotated methods.voidsetDecoders(List<? extends Decoder<?>> decoders) Configure the decoders to use for incoming payloads.voidsetDefaultDataMimeType(MimeType mimeType) Configure the default content type to use for data payloads if theSETUPframe did not specify one.voidsetDefaultMetadataMimeType(MimeType mimeType) Configure the defaultMimeTypefor payload data if theSETUPframe did not specify one.voidsetEncoders(List<? extends Encoder<?>> encoders) Configure the encoders to use for encoding handler method return values.voidsetMetadataExtractor(MetadataExtractor extractor) Configure aMetadataExtractorto extract the route along with other metadata.voidConfigure the registry for adapting various reactive types.voidsetRouteMatcher(RouteMatcher routeMatcher) Set theRouteMatcherto use for mapping messages to handlers based on the route patterns they're configured with.voidsetRSocketStrategies(RSocketStrategies rsocketStrategies) Configure this handler through anRSocketStrategiesinstance which can be re-used to initialize a client-sideRSocketRequester.Methods inherited from class org.springframework.messaging.handler.annotation.reactive.MessageMappingMessageHandlercreateExceptionMethodResolverFor, getConversionService, getDecoders, getDestination, getDirectLookupMappings, getMappingComparator, getMappingForMethod, getMatchingMapping, getRouteMatcher, getValidator, handleMatch, initArgumentResolvers, obtainRouteMatcher, processDestinations, registerMessagingAdvice, setConversionService, setEmbeddedValueResolver, setValidatorMethods inherited from class org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandlerdetectHandlerMethods, getApplicationContext, getArgumentResolverConfigurer, getArgumentResolvers, getBeanName, getDestinationLookup, getHandlerMethods, getHandlerPredicate, getReactiveAdapterRegistry, getReturnValueHandlerConfigurer, handleMessage, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolverConfigurer, setBeanName, setHandlerPredicate, setHandlers, setReturnValueHandlerConfigurer
- 
Constructor Details- 
RSocketMessageHandlerpublic RSocketMessageHandler()
 
- 
- 
Method Details- 
setEncodersConfigure the encoders to use for encoding handler method return values.When rsocketStrategiesis set, this property is re-initialized with the encoders in it, and likewise when this property is set theRSocketStrategiesare mutated to change the encoders in it.By default this is set to the defaults from RSocketStrategies.
- 
getEncodersReturn the configuredencoders.
- 
setDecodersConfigure the decoders to use for incoming payloads.When rsocketStrategiesis set, this property is re-initialized with the decoders in it, and likewise when this property is set theRSocketStrategiesare mutated to change the decoders in them.By default this is set to the defaults from RSocketStrategies.- Overrides:
- setDecodersin class- MessageMappingMessageHandler
 
- 
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.When rsocketStrategiesis set, this property is re-initialized with the route matcher in it, and likewise when this property is set theRSocketStrategiesare mutated to change the matcher in it.By default this is set to the defaults from RSocketStrategies.- Overrides:
- setRouteMatcherin class- MessageMappingMessageHandler
 
- 
setReactiveAdapterRegistryConfigure the registry for adapting various reactive types.When rsocketStrategiesis set, this property is re-initialized with the registry in it, and likewise when this property is set theRSocketStrategiesare mutated to change the registry in it.By default this is set to the defaultsfromRSocketStrategies.- Overrides:
- setReactiveAdapterRegistryin class- AbstractMethodMessageHandler<CompositeMessageCondition>
 
- 
setMetadataExtractorConfigure aMetadataExtractorto extract the route along with other metadata.When rsocketStrategiesis set, this property is re-initialized with the extractor in it, and likewise when this property is set theRSocketStrategiesare mutated to change the extractor in it.By default this is set to the defaultsfromRSocketStrategies.- Parameters:
- extractor- the extractor to use
 
- 
getMetadataExtractorReturn the configuredMetadataExtractor.
- 
setRSocketStrategiesConfigure this handler through anRSocketStrategiesinstance which can be re-used to initialize a client-sideRSocketRequester.When this property is set, in turn it sets the following: - setDecoders(List)
- setEncoders(List)
- setRouteMatcher(RouteMatcher)
- setMetadataExtractor(MetadataExtractor)
- setReactiveAdapterRegistry(ReactiveAdapterRegistry)
 By default this is set to RSocketStrategies.create()which in turn sets default settings for all related properties.
- 
getRSocketStrategiesReturn theconfiguredRSocketStrategies.
- 
setDefaultDataMimeTypeConfigure the default content type to use for data payloads if theSETUPframe did not specify one.By default this is not set. - Parameters:
- mimeType- the MimeType to use
 
- 
getDefaultDataMimeTypeReturn the configureddefaultDataMimeType, ornull.
- 
setDefaultMetadataMimeTypeConfigure the defaultMimeTypefor payload data if theSETUPframe did not specify one.By default this is set to "message/x.rsocket.composite-metadata.v0"- Parameters:
- mimeType- the MimeType to use
 
- 
getDefaultMetadataMimeTypeReturn the configureddefaultMetadataMimeType.
- 
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- MessageMappingMessageHandler
 
- 
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).- Overrides:
- initReturnValueHandlersin class- MessageMappingMessageHandler
 
- 
getConditionDescription copied from class:MessageMappingMessageHandlerDetermine the mapping condition for the given annotated element.- Overrides:
- getConditionin class- MessageMappingMessageHandler
- Parameters:
- element- the element to check
- Returns:
- the condition, or null
 
- 
extendMappingprotected CompositeMessageCondition extendMapping(CompositeMessageCondition composite, HandlerMethod handler) Description copied from class:AbstractMethodMessageHandlerThis method is invoked just before mappings are added. It allows subclasses to update the mapping with theHandlerMethodin mind. This can be useful when the method signature is used to refine the mapping, for example, based on the cardinality of input and output.By default this method returns the mapping that is passed in. - Overrides:
- extendMappingin class- AbstractMethodMessageHandler<CompositeMessageCondition>
- Parameters:
- composite- the mapping to be added
- handler- the target handler for the mapping
- Returns:
- a new mapping or the same
 
- 
handleNoMatchDescription copied from class:AbstractMethodMessageHandlerInvoked when no matching handler is found.- Overrides:
- handleNoMatchin class- AbstractMethodMessageHandler<CompositeMessageCondition>
- Parameters:
- destination- the destination
- message- the message
 
- 
responderpublic io.rsocket.SocketAcceptor responder()Return an RSocketSocketAcceptorbacked by thisRSocketMessageHandlerinstance that can be plugged in as aclientorserverRSocket responder.The initial ConnectionSetupPayloadis handled through@ConnectionMappingmethods that can be asynchronous and returnMono<Void>with an error signal preventing the connection. Such a method can also start requests to the client but that must be done decoupled from handling and from the current thread.Subsequent requests on the connection can be handled with MessageMappingandRSocketExchangemethods.
- 
responderpublic static io.rsocket.SocketAcceptor responder(RSocketStrategies strategies, Object... candidateHandlers) Static factory method to create an RSocketSocketAcceptorbacked by handlers with annotated methods. Effectively a shortcut for:RSocketMessageHandler handler = new RSocketMessageHandler(); handler.setHandlers(handlers); handler.setRSocketStrategies(strategies); handler.afterPropertiesSet(); SocketAcceptor acceptor = handler.responder(); This is intended for programmatic creation and registration of a client-side responder. For example: SocketAcceptor responder = RSocketMessageHandler.responder(strategies, new ClientHandler()); RSocketRequester.builder() .rsocketConnector(connector -> connector.acceptor(responder)) .connectTcp("localhost", server.address().getPort());Note that the given handlers do not need to have any stereotype annotations such as @Controllerwhich helps to avoid overlap with server side handlers that may be used in the same application. However, for more advanced scenarios, for example, discovering handlers through a custom stereotype annotation, consider declaringRSocketMessageHandleras a bean, and then obtain the responder from it.- Parameters:
- strategies- the strategies to set on the created- RSocketMessageHandler
- candidateHandlers- a list of Objects and/or Classes with annotated handler methods; used to call- AbstractMethodMessageHandler.setHandlers(List)with on the created- RSocketMessageHandler
- Returns:
- a configurer that may be passed into
 RSocketRequester.Builder.rsocketConnector(org.springframework.messaging.rsocket.RSocketConnectorConfigurer)
- Since:
- 5.2.6
 
 
-