public class SubscriptionMethodReturnValueHandler extends java.lang.Object implements HandlerMethodReturnValueHandler
HandlerMethodReturnValueHandler for replying directly to a
subscription. It is supported on methods annotated with
SubscribeMapping 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 the SendTo or SendToUser annotations in which case a
message is prepared and sent to the broker instead.
| Constructor and Description |
|---|
SubscriptionMethodReturnValueHandler(MessageSendingOperations<java.lang.String> template)
Construct a new SubscriptionMethodReturnValueHandler.
|
| Modifier and Type | Method and Description |
|---|---|
MessageHeaderInitializer |
getHeaderInitializer()
Return the configured header initializer.
|
void |
handleReturnValue(java.lang.Object returnValue,
MethodParameter returnType,
Message<?> message)
Handle the given return value.
|
void |
setHeaderInitializer(MessageHeaderInitializer headerInitializer)
Configure a
MessageHeaderInitializer 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.
|
public SubscriptionMethodReturnValueHandler(MessageSendingOperations<java.lang.String> template)
template - a messaging template to send messages to,
most likely the "clientOutboundChannel" (must not be null)public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer)
MessageHeaderInitializer to apply to the headers of all
messages sent to the client outbound channel.
By default this property is not set.
@Nullable public MessageHeaderInitializer getHeaderInitializer()
public boolean supportsReturnType(MethodParameter returnType)
HandlerMethodReturnValueHandlersupportsReturnType in interface HandlerMethodReturnValueHandlerreturnType - the method return type to checktrue if this handler supports the supplied return type;
false otherwisepublic void handleReturnValue(@Nullable java.lang.Object returnValue, MethodParameter returnType, Message<?> message) throws java.lang.Exception
HandlerMethodReturnValueHandlerhandleReturnValue in interface HandlerMethodReturnValueHandlerreturnValue - the value returned from the handler methodreturnType - the type of the return value. This type must have previously
been passed to HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
and it must have returned true.message - the message that caused this method to be calledjava.lang.Exception - if the return value handling results in an error