public class RSocketMessageHandler extends MessageMappingMessageHandler
MessageMappingMessageHandler for use in RSocket as a
responder that handles requests with @ConnectMapping
and @MessageMapping methods.
For RSocket servers use serverResponder() to obtain a
SocketAcceptor to register with
ServerRSocketFactory.
For RSocket clients use clientResponder() to obtain an adapter
to register with
ClientRSocketFactory,
or use the static shortcut
clientResponder(RSocketStrategies, Object...) to obtain a configurer
for RSocketRequester.Builder#rsocketFactory.
logger| Constructor and Description |
|---|
RSocketMessageHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
BiFunction<io.rsocket.ConnectionSetupPayload,io.rsocket.RSocket,io.rsocket.RSocket> |
clientResponder()
Return an adapter for a client side responder that can be used to set
RSocketFactory.ClientRSocketFactory.acceptor(Function). |
static ClientRSocketFactoryConfigurer |
clientResponder(RSocketStrategies strategies,
Object... candidateHandlers)
Static factory method for a configurer of a client side responder with
annotated handler methods.
|
protected CompositeMessageCondition |
getCondition(AnnotatedElement element)
Determine the mapping condition for the given annotated element.
|
org.springframework.util.MimeType |
getDefaultDataMimeType()
Return the configured
defaultDataMimeType, or null. |
org.springframework.util.MimeType |
getDefaultMetadataMimeType()
Return the configured
defaultMetadataMimeType. |
List<? extends org.springframework.core.codec.Encoder<?>> |
getEncoders()
Return the configured
encoders. |
MetadataExtractor |
getMetadataExtractor()
Return the configured
MetadataExtractor. |
RSocketStrategies |
getRSocketStrategies()
Return the
configured RSocketStrategies. |
protected void |
handleNoMatch(org.springframework.util.RouteMatcher.Route destination,
Message<?> message)
Invoked when no matching handler is found.
|
protected List<? extends HandlerMethodReturnValueHandler> |
initReturnValueHandlers()
Return the list of return value handlers to use.
|
io.rsocket.SocketAcceptor |
serverResponder()
Return an adapter for a server side
acceptor that delegate to this RSocketMessageHandler for
handling. |
void |
setDecoders(List<? extends org.springframework.core.codec.Decoder<?>> decoders)
Configure the decoders to use for incoming payloads.
|
void |
setDefaultDataMimeType(org.springframework.util.MimeType mimeType)
Configure the default content type to use for data payloads if the
SETUP frame did not specify one. |
void |
setDefaultMetadataMimeType(org.springframework.util.MimeType mimeType)
Configure the default
MimeType for payload data if the
SETUP frame did not specify one. |
void |
setEncoders(List<? extends org.springframework.core.codec.Encoder<?>> encoders)
Configure the encoders to use for encoding handler method return values.
|
void |
setMetadataExtractor(MetadataExtractor extractor)
Configure a
MetadataExtractor to extract the route along with
other metadata. |
void |
setReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry registry)
Configure the registry for adapting various reactive types.
|
void |
setRouteMatcher(org.springframework.util.RouteMatcher routeMatcher)
Set the
RouteMatcher to use for mapping messages to handlers
based on the route patterns they're configured with. |
void |
setRSocketStrategies(RSocketStrategies rsocketStrategies)
Configure this handler through an
RSocketStrategies instance which
can be re-used to initialize a client-side RSocketRequester. |
createExceptionMethodResolverFor, getConversionService, getDecoders, getDestination, getDirectLookupMappings, getMappingComparator, getMappingForMethod, getMatchingMapping, getRouteMatcher, getValidator, handleMatch, initArgumentResolvers, obtainRouteMatcher, processDestinations, setConversionService, setEmbeddedValueResolver, setValidatordetectHandlerMethods, getApplicationContext, getArgumentResolverConfigurer, getBeanName, getDestinationLookup, getHandlerMethods, getHandlerPredicate, getReactiveAdapterRegistry, getReturnValueHandlerConfigurer, handleMessage, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolverConfigurer, setBeanName, setHandlerPredicate, setHandlers, setReturnValueHandlerConfigurerpublic void setEncoders(List<? extends org.springframework.core.codec.Encoder<?>> encoders)
When rsocketStrategies
is set, this property is re-initialized with the encoders in it, and
likewise when this property is set the RSocketStrategies are
mutated to change the encoders in it.
By default this is set to the
defaults from
RSocketStrategies.
public List<? extends org.springframework.core.codec.Encoder<?>> getEncoders()
encoders.public void setDecoders(List<? extends org.springframework.core.codec.Decoder<?>> decoders)
When rsocketStrategies
is set, this property is re-initialized with the decoders in it, and
likewise when this property is set the RSocketStrategies are
mutated to change the decoders in them.
By default this is set to the
defaults from
RSocketStrategies.
setDecoders in class MessageMappingMessageHandlerpublic void setRouteMatcher(@Nullable
org.springframework.util.RouteMatcher routeMatcher)
RouteMatcher to use for mapping messages to handlers
based on the route patterns they're configured with.
By default, SimpleRouteMatcher is used, backed by
AntPathMatcher with "." as separator. For greater
efficiency consider using the PathPatternRouteMatcher from
spring-web instead.
When rsocketStrategies
is set, this property is re-initialized with the route matcher in it, and
likewise when this property is set the RSocketStrategies are
mutated to change the matcher in it.
By default this is set to the
defaults
from RSocketStrategies.
setRouteMatcher in class MessageMappingMessageHandlerpublic void setReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry registry)
When rsocketStrategies
is set, this property is re-initialized with the registry in it, and
likewise when this property is set the RSocketStrategies are
mutated to change the registry in it.
By default this is set to the
defaults
from RSocketStrategies.
setReactiveAdapterRegistry in class AbstractMethodMessageHandler<CompositeMessageCondition>public void setMetadataExtractor(MetadataExtractor extractor)
MetadataExtractor to extract the route along with
other metadata.
When rsocketStrategies
is set, this property is re-initialized with the extractor in it, and
likewise when this property is set the RSocketStrategies are
mutated to change the extractor in it.
By default this is set to the
RSocketStrategies.Builder#metadataExtractor(MetadataExtractor) defaults}
from RSocketStrategies.
extractor - the extractor to usepublic MetadataExtractor getMetadataExtractor()
MetadataExtractor.public void setRSocketStrategies(RSocketStrategies rsocketStrategies)
RSocketStrategies instance which
can be re-used to initialize a client-side RSocketRequester.
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.
public RSocketStrategies getRSocketStrategies()
configured RSocketStrategies.public void setDefaultDataMimeType(@Nullable
org.springframework.util.MimeType mimeType)
SETUP frame did not specify one.
By default this is not set.
mimeType - the MimeType to use@Nullable public org.springframework.util.MimeType getDefaultDataMimeType()
defaultDataMimeType, or null.public void setDefaultMetadataMimeType(org.springframework.util.MimeType mimeType)
MimeType for payload data if the
SETUP frame did not specify one.
By default this is set to "message/x.rsocket.composite-metadata.v0"
mimeType - the MimeType to usepublic org.springframework.util.MimeType getDefaultMetadataMimeType()
defaultMetadataMimeType.public void afterPropertiesSet()
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanafterPropertiesSet in class MessageMappingMessageHandlerprotected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers()
AbstractMethodMessageHandlerSubclasses should also take into account custom return value types configured
via AbstractMethodMessageHandler.setReturnValueHandlerConfigurer(org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer).
initReturnValueHandlers in class MessageMappingMessageHandler@Nullable protected CompositeMessageCondition getCondition(AnnotatedElement element)
MessageMappingMessageHandlergetCondition in class MessageMappingMessageHandlerelement - the element to checknullprotected void handleNoMatch(@Nullable
org.springframework.util.RouteMatcher.Route destination,
Message<?> message)
AbstractMethodMessageHandlerhandleNoMatch in class AbstractMethodMessageHandler<CompositeMessageCondition>destination - the destinationmessage - the messagepublic io.rsocket.SocketAcceptor serverResponder()
acceptor that delegate to this RSocketMessageHandler for
handling.
The initial ConnectionSetupPayload can be handled with a
@ConnectionMapping method which can be asynchronous
and return Mono<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
MessageMapping methods.
public BiFunction<io.rsocket.ConnectionSetupPayload,io.rsocket.RSocket,io.rsocket.RSocket> clientResponder()
RSocketFactory.ClientRSocketFactory.acceptor(Function).
The responder delegates requests to this RSocketMessageHandler
for handling via @MessageMapping methods.
The initial ConnectionSetupPayload can be accessed through a
@ConnectionMapping method, but such a method is
only a callback just before the connection is made and cannot "accept"
or prevent the connection. Such a method can also start requests to the
server but must do so decoupled from handling and the current thread.
public static ClientRSocketFactoryConfigurer clientResponder(RSocketStrategies strategies, Object... candidateHandlers)
RSocketRequester.Builder#rsocketFactory(ClientRSocketFactoryConfigurer).
In effect a shortcut to create and initialize
RSocketMessageHandler with the given strategies and handlers,
and use clientResponder() to obtain the responder.
For more advanced scenarios, e.g. discovering handlers through a custom
stereotype annotation, consider declaring RSocketMessageHandler
as a bean, and then obtain the responder from it.
strategies - the strategies to set on the created
RSocketMessageHandlercandidateHandlers - a list of Objects and/or Classes with annotated
handler methods; used to call AbstractMethodMessageHandler.setHandlers(List) with
on the created RSocketMessageHandlerRSocketRequester.Builder#rsocketFactory(ClientRSocketFactoryConfigurer)