public class SubscriptionMethodReturnValueHandler extends Object implements HandlerMethodReturnValueHandler
HandlerMethodReturnValueHandler
for replying directly to a subscription.
It is supported on methods annotated with
SubscribeMapping
unless they're also annotated with SendTo
or SendToUser
in
which case a message is sent to the broker instead.
The value returned from the method is converted, and turned to a Message
and then enriched with the sessionId, subscriptionId, and destination of the
input message. The message is then sent directly back to the connected client.
Constructor and Description |
---|
SubscriptionMethodReturnValueHandler(MessageSendingOperations<String> messagingTemplate)
Construct a new SubscriptionMethodReturnValueHandler.
|
Modifier and Type | Method and Description |
---|---|
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 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<String> messagingTemplate)
messagingTemplate
- a messaging template to send messages to,
most likely the "clientOutboundChannel" (must not be null
)public void setHeaderInitializer(MessageHeaderInitializer headerInitializer)
MessageHeaderInitializer
to apply to the headers of all
messages sent to the client outbound channel.
By default this property is not set.
public MessageHeaderInitializer getHeaderInitializer()
public boolean supportsReturnType(MethodParameter returnType)
HandlerMethodReturnValueHandler
supportsReturnType
in interface HandlerMethodReturnValueHandler
returnType
- the method return type to checktrue
if this handler supports the supplied return type;
false
otherwisepublic void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) throws Exception
HandlerMethodReturnValueHandler
handleReturnValue
in interface HandlerMethodReturnValueHandler
returnValue
- 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 calledException
- if the return value handling results in an error