类 RSocketMessageHandler
- java.lang.Object
- org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler<CompositeMessageCondition>
- org.springframework.messaging.handler.annotation.reactive.MessageMappingMessageHandler
- org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler
- 所有已实现的接口:
Aware,BeanNameAware,InitializingBean,ApplicationContextAware,EmbeddedValueResolverAware,ReactiveMessageHandler
public class RSocketMessageHandler extends MessageMappingMessageHandler
Extension ofMessageMappingMessageHandlerfor handling RSocket requests with@ConnectMappingand@MessageMappingmethods.For server scenarios this class can be declared as a bean in Spring configuration and that would detect
@MessageMappingmethods in@Controllerbeans. What beans are checked can be changed through ahandlerPredicate. Given an instance of this class, you can then useresponder()to obtain aSocketAcceptoradapter to register with theRSocketServer.For a client, possibly in the same process as a server, consider consider using the static factory method
responder(RSocketStrategies, Object...)to obtain a client responder to be registered viaRSocketRequester.Builder.For
@MessageMappingmethods, 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.- 从以下版本开始:
- 5.2
- 作者:
- Rossen Stoyanchev
字段概要
从类继承的字段 org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler
logger
构造器概要
构造器 构造器 说明 RSocketMessageHandler()
方法概要
所有方法 静态方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.static ClientRSocketFactoryConfigurerclientResponder(RSocketStrategies strategies, Object... candidateHandlers)已过时。as of 5.2.6 following the deprecation ofRSocketFactory.ClientRSocketFactoryin RSocket 1.0 RC7.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.MimeTypegetDefaultDataMimeType()Return the configureddefaultDataMimeType, ornull.MimeTypegetDefaultMetadataMimeType()Return the configureddefaultMetadataMimeType.List<? extends Encoder<?>>getEncoders()Return the configuredencoders.MetadataExtractorgetMetadataExtractor()Return the configuredMetadataExtractor.RSocketStrategiesgetRSocketStrategies()Return theconfiguredRSocketStrategies.protected voidhandleNoMatch(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.SocketAcceptorresponder()Return 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.voidsetReactiveAdapterRegistry(ReactiveAdapterRegistry registry)Configure 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.从类继承的方法 org.springframework.messaging.handler.annotation.reactive.MessageMappingMessageHandler
createExceptionMethodResolverFor, getConversionService, getDecoders, getDestination, getDirectLookupMappings, getMappingComparator, getMappingForMethod, getMatchingMapping, getRouteMatcher, getValidator, handleMatch, initArgumentResolvers, obtainRouteMatcher, processDestinations, setConversionService, setEmbeddedValueResolver, setValidator
从类继承的方法 org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler
detectHandlerMethods, getApplicationContext, getArgumentResolverConfigurer, getArgumentResolvers, getBeanName, getDestinationLookup, getHandlerMethods, getHandlerPredicate, getReactiveAdapterRegistry, getReturnValueHandlerConfigurer, handleMessage, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolverConfigurer, setBeanName, setHandlerPredicate, setHandlers, setReturnValueHandlerConfigurer
构造器详细资料
RSocketMessageHandler
public RSocketMessageHandler()
方法详细资料
setEncoders
public void setEncoders(List<? extends Encoder<?>> encoders)
Configure 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.
getEncoders
public List<? extends Encoder<?>> getEncoders()
Return the configuredencoders.
setDecoders
public void setDecoders(List<? extends Decoder<?>> decoders)
Configure 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.
setRouteMatcher
public void setRouteMatcher(@Nullable RouteMatcher routeMatcher)
Set 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.
setReactiveAdapterRegistry
public void setReactiveAdapterRegistry(ReactiveAdapterRegistry registry)
Configure 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.
setMetadataExtractor
public void setMetadataExtractor(MetadataExtractor extractor)
Configure 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
RSocketStrategies.Builder.metadataExtractor(MetadataExtractor)defaults} fromRSocketStrategies.- 参数:
extractor- the extractor to use
getMetadataExtractor
public MetadataExtractor getMetadataExtractor()
Return the configuredMetadataExtractor.
setRSocketStrategies
public void setRSocketStrategies(RSocketStrategies rsocketStrategies)
Configure 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.
getRSocketStrategies
public RSocketStrategies getRSocketStrategies()
Return theconfiguredRSocketStrategies.
setDefaultDataMimeType
public void setDefaultDataMimeType(@Nullable MimeType mimeType)
Configure the default content type to use for data payloads if theSETUPframe did not specify one.By default this is not set.
- 参数:
mimeType- the MimeType to use
getDefaultDataMimeType
@Nullable public MimeType getDefaultDataMimeType()
Return the configureddefaultDataMimeType, ornull.
setDefaultMetadataMimeType
public void setDefaultMetadataMimeType(MimeType mimeType)
Configure the defaultMimeTypefor payload data if theSETUPframe did not specify one.By default this is set to
"message/x.rsocket.composite-metadata.v0"- 参数:
mimeType- the MimeType to use
getDefaultMetadataMimeType
public MimeType getDefaultMetadataMimeType()
Return the configureddefaultMetadataMimeType.
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明: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.
initReturnValueHandlers
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers()
从类复制的说明: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).
getCondition
@Nullable protected CompositeMessageCondition getCondition(AnnotatedElement element)
从类复制的说明:MessageMappingMessageHandlerDetermine the mapping condition for the given annotated element.- 覆盖:
getCondition在类中MessageMappingMessageHandler- 参数:
element- the element to check- 返回:
- the condition, or
null
extendMapping
protected CompositeMessageCondition extendMapping(CompositeMessageCondition composite, HandlerMethod handler)
从类复制的说明:AbstractMethodMessageHandlerThis method is invoked just before mappings are added. It allows sub-classes to update the mapping with theHandlerMethodin mind. This can be useful when the method signature is used to refine the mapping, e.g. based on the cardinality of input and output.By default this method returns the mapping that is passed in.
- 覆盖:
extendMapping在类中AbstractMethodMessageHandler<CompositeMessageCondition>- 参数:
composite- the mapping to be addedhandler- the target handler for the mapping- 返回:
- a new mapping or the same
handleNoMatch
protected void handleNoMatch(@Nullable RouteMatcher.Route destination, Message<?> message)
从类复制的说明:AbstractMethodMessageHandlerInvoked when no matching handler is found.- 覆盖:
handleNoMatch在类中AbstractMethodMessageHandler<CompositeMessageCondition>- 参数:
destination- the destinationmessage- the message
responder
public 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
MessageMappingmethods.
responder
public 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, e.g. discovering handlers through a custom stereotype annotation, consider declaringRSocketMessageHandleras a bean, and then obtain the responder from it.- 参数:
strategies- the strategies to set on the createdRSocketMessageHandlercandidateHandlers- a list of Objects and/or Classes with annotated handler methods; used to callAbstractMethodMessageHandler.setHandlers(List)with on the createdRSocketMessageHandler- 返回:
- a configurer that may be passed into
RSocketRequester.Builder.rsocketConnector(org.springframework.messaging.rsocket.RSocketConnectorConfigurer) - 从以下版本开始:
- 5.2.6
clientResponder
@Deprecated public static ClientRSocketFactoryConfigurer clientResponder(RSocketStrategies strategies, Object... candidateHandlers)
已过时。as of 5.2.6 following the deprecation ofRSocketFactory.ClientRSocketFactoryin RSocket 1.0 RC7.Static factory method for a configurer of a client side responder with annotated handler methods. This is intended to be passed intoRSocketRequester.Builder.rsocketFactory(org.springframework.messaging.rsocket.ClientRSocketFactoryConfigurer).In effect a shortcut to create and initialize
RSocketMessageHandlerwith the given strategies and handlers, useresponder()to obtain the responder, and plug that intoClientRSocketFactory. For more advanced scenarios, e.g. discovering handlers through a custom stereotype annotation, consider declaringRSocketMessageHandleras a bean, and then obtain the responder from it.- 参数:
strategies- the strategies to set on the createdRSocketMessageHandlercandidateHandlers- a list of Objects and/or Classes with annotated handler methods; used to callAbstractMethodMessageHandler.setHandlers(List)with on the createdRSocketMessageHandler- 返回:
- a configurer that may be passed into
RSocketRequester.Builder.rsocketFactory(org.springframework.messaging.rsocket.ClientRSocketFactoryConfigurer)