Update docs on @SendTo and @SendToUser
1. Explain that both can be used on the same method 2. Better describe semantics for class vs method level 3. General improvements Issue: SPR-16336
This commit is contained in:
@@ -32,9 +32,8 @@ import org.springframework.messaging.Message;
|
||||
* convey the destination to use for the reply. In that case, that destination
|
||||
* should take precedence.
|
||||
*
|
||||
* <p>The annotation may also be placed at class-level if the provider supports
|
||||
* it to indicate that all related methods should use this destination if none
|
||||
* is specified otherwise.
|
||||
* <p>This annotation may be placed class-level in which case it is inherited by
|
||||
* methods of the class.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Stephane Nicoll
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,13 +25,17 @@ import java.lang.annotation.Target;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Annotation that indicates that the return value of a message-handling method
|
||||
* should be sent as a {@link org.springframework.messaging.Message} to the specified
|
||||
* destination(s) prepended with <code>"/user/{username}"</code> where the user name
|
||||
* Indicates the return value of a message-handling method should be sent as a
|
||||
* {@link org.springframework.messaging.Message} to the specified destination(s)
|
||||
* further prepended with <code>"/user/{username}"</code> where the user name
|
||||
* is extracted from the headers of the input message being handled.
|
||||
*
|
||||
* <p>The annotation may also be placed at class-level in which case all methods
|
||||
* in the class where the annotation applies will inherit it.
|
||||
* <p>Both {@code @SendTo} and {@code @SendToUser} may be used on the same method
|
||||
* in which case a message is sent to the destinations of both annotations.
|
||||
*
|
||||
* <p>This annotation may be placed class-level in which case it is inherited
|
||||
* by methods of the class. At the same time, method-level {@code @SendTo} or
|
||||
* {@code @SendToUser} annotations override any such at the class level.
|
||||
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
|
||||
@@ -330,15 +330,14 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>();
|
||||
|
||||
// Single-purpose return value types
|
||||
|
||||
handlers.add(new ListenableFutureReturnValueHandler());
|
||||
handlers.add(new CompletableFutureReturnValueHandler());
|
||||
|
||||
// Annotation-based return value types
|
||||
SendToMethodReturnValueHandler sendToHandler =
|
||||
new SendToMethodReturnValueHandler(this.brokerTemplate, true);
|
||||
if (this.headerInitializer != null) {
|
||||
sendToHandler.setHeaderInitializer(this.headerInitializer);
|
||||
}
|
||||
|
||||
SendToMethodReturnValueHandler sendToHandler = new SendToMethodReturnValueHandler(this.brokerTemplate, true);
|
||||
sendToHandler.setHeaderInitializer(this.headerInitializer);
|
||||
handlers.add(sendToHandler);
|
||||
|
||||
SubscriptionMethodReturnValueHandler subscriptionHandler =
|
||||
@@ -350,6 +349,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||
handlers.addAll(getCustomReturnValueHandlers());
|
||||
|
||||
// catch-all
|
||||
|
||||
sendToHandler = new SendToMethodReturnValueHandler(this.brokerTemplate, false);
|
||||
sendToHandler.setHeaderInitializer(this.headerInitializer);
|
||||
handlers.add(sendToHandler);
|
||||
|
||||
Reference in New Issue
Block a user