diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMapping.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMapping.java index 17167e049f2..f5bfc52ba02 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMapping.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -23,63 +23,60 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.messaging.Message; +import org.springframework.messaging.simp.annotation.SendToUser; /** - * Annotation for mapping a {@link Message} onto message-handling methods by matching - * to the message destination. This annotation can also be used on the type-level in - * which case it defines a common destination prefix or pattern for all method-level - * annotations including method-level - * {@link org.springframework.messaging.simp.annotation.SubscribeMapping @SubscribeMapping} - * annotations. + * Annotation for mapping a {@link Message} onto a message-handling method by + * matching the declared {@link #value() patterns} to a destination extracted + * from the message. The annotation is supported at the type-level too, as a + * way of declaring a pattern prefix (or prefixes) across all class methods. * - *
Handler methods which are annotated with this annotation are allowed to have - * flexible signatures. They may have arguments of the following types, in arbitrary - * order: + *
{@code @MessageMapping} methods support the following arguments: *
A return value will get wrapped as a message and sent to a default response - * destination or to a custom destination specified with an {@link SendTo @SendTo} - * method-level annotation. Such a response may also be provided asynchronously - * via a {@link org.springframework.util.concurrent.ListenableFuture} return type - * or a corresponding JDK 8 {@link java.util.concurrent.CompletableFuture} / - * {@link java.util.concurrent.CompletionStage} handle. + *
How the return value is handled depends on the processing scenario. + * For STOMP over WebSocket, it is turned into a message and sent to a default + * response destination or to a custom destination specified with an + * {@link SendTo @SendTo} or {@link SendToUser @SendToUser} annotation. + * For RSocket, the response is used to reply to the stream request. * - *
An {@link SendTo @SendTo} annotation is not strictly required — by default - * the message will be sent to the same destination as the incoming message but with - * an additional prefix ({@code "/topic"} by default). It is also possible to use the - * {@link org.springframework.messaging.simp.annotation.SendToUser} annotation to - * have the message directed to a specific user if connected. The return value is - * converted with a {@link org.springframework.messaging.converter.MessageConverter}. + *
Specializations of this annotation including + * {@link org.springframework.messaging.simp.annotation.SubscribeMapping @SubscribeMapping} or + * {@link org.springframework.messaging.rsocket.annotation.ConnectMapping @ConnectMapping} + * further narrow the mapping by message type. Both can be combined with a + * type-level {@code @MessageMapping} for declaring a common pattern prefix + * (or prefixes). * *
NOTE: When using controller interfaces (e.g. for AOP proxying), * make sure to consistently put all your mapping annotations - such as @@ -89,6 +86,7 @@ import org.springframework.messaging.Message; * @author Rossen Stoyanchev * @since 4.0 * @see org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler + * @see org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler */ @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @@ -97,10 +95,15 @@ public @interface MessageMapping { /** * Destination-based mapping expressed by this annotation. - *
For STOMP over WebSocket messages: this is the destination of the
- * STOMP message (e.g. {@code "/positions"}). Ant-style path patterns
- * (e.g. {@code "/price.stock.*"}) and path template variables (e.g.
- * "/price.stock.{ticker}") are also supported.
+ *
For STOMP over WebSocket messages this is + * {@link org.springframework.util.AntPathMatcher AntPathMatcher}-style + * patterns matched against the STOMP destination of the message. + *
for RSocket this is either + * {@link org.springframework.util.AntPathMatcher AntPathMatcher} or + * {@link org.springframework.web.util.pattern.PathPattern PathPattern} + * based pattern, depending on which is configured, matched to the route of + * the stream request. + *
If no patterns are configured, the mapping matches all destinations. */ String[] value() default {}; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/ConnectMapping.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/ConnectMapping.java index 4270186b865..0ad3172ddc0 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/ConnectMapping.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/ConnectMapping.java @@ -59,7 +59,7 @@ public @interface ConnectMapping { *
Depending on the configured * {@link org.springframework.util.RouteMatcher RouteMatcher} the pattern may be * {@link org.springframework.util.AntPathMatcher AntPathMatcher} or - * {@link org.springframework.web.util.pattern.PathPattern PathPattern} based + * {@link org.springframework.web.util.pattern.PathPattern PathPattern} based. * *
By default this is an empty array in which case it matches all * {@link ConnectionSetupPayload} and metadata pushes.