类 SubscriptionMethodReturnValueHandler
- java.lang.Object
- org.springframework.messaging.simp.annotation.support.SubscriptionMethodReturnValueHandler
- 所有已实现的接口:
HandlerMethodReturnValueHandler
public class SubscriptionMethodReturnValueHandler extends Object implements HandlerMethodReturnValueHandler
HandlerMethodReturnValueHandler
for replying directly to a subscription. It is supported on methods annotated withSubscribeMapping
such that the return value is treated as a response to be sent directly back on the session. This allows a client to implement a request-response pattern and use it for example to obtain some data upon initialization.The value returned from the method is converted and turned into a
Message
that is then enriched with the sessionId, subscriptionId, and destination of the input message.Note: this default behavior for interpreting the return value from an
@SubscribeMapping
method can be overridden through use of theSendTo
orSendToUser
annotations in which case a message is prepared and sent to the broker instead.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Sebastien Deleuze
构造器概要
构造器 构造器 说明 SubscriptionMethodReturnValueHandler(MessageSendingOperations<String> template)
Construct a new SubscriptionMethodReturnValueHandler.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 MessageHeaderInitializer
getHeaderInitializer()
Return the configured header initializer.void
handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message)
Handle the given return value.void
setHeaderInitializer(MessageHeaderInitializer headerInitializer)
Configure aMessageHeaderInitializer
to apply to the headers of all messages sent to the client outbound channel.boolean
supportsReturnType(MethodParameter returnType)
Whether the given method return type is supported by this handler.
构造器详细资料
SubscriptionMethodReturnValueHandler
public SubscriptionMethodReturnValueHandler(MessageSendingOperations<String> template)
Construct a new SubscriptionMethodReturnValueHandler.- 参数:
template
- a messaging template to send messages to, most likely the "clientOutboundChannel" (must not benull
)
方法详细资料
setHeaderInitializer
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer)
Configure aMessageHeaderInitializer
to apply to the headers of all messages sent to the client outbound channel.By default this property is not set.
getHeaderInitializer
public MessageHeaderInitializer getHeaderInitializer()
Return the configured header initializer.
supportsReturnType
public boolean supportsReturnType(MethodParameter returnType)
从接口复制的说明:HandlerMethodReturnValueHandler
Whether the given method return type is supported by this handler.- 指定者:
supportsReturnType
在接口中HandlerMethodReturnValueHandler
- 参数:
returnType
- the method return type to check- 返回:
true
if this handler supports the supplied return type;false
otherwise
handleReturnValue
public void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) throws Exception
从接口复制的说明:HandlerMethodReturnValueHandler
Handle the given return value.- 指定者:
handleReturnValue
在接口中HandlerMethodReturnValueHandler
- 参数:
returnValue
- the value returned from the handler methodreturnType
- the type of the return value. This type must have previously been passed toHandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
and it must have returnedtrue
.message
- the message that caused this method to be called- 抛出:
Exception
- if the return value handling results in an error