Skip to content

Commit 5b6c127

Browse files
committed
Polishing
Closes gh-30936
1 parent 4cd9e2e commit 5b6c127

File tree

4 files changed

+58
-42
lines changed

4 files changed

+58
-42
lines changed

framework-docs/modules/ROOT/pages/rsocket.adoc

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ demonstrate its API and protocol features.
137137

138138
The `spring-messaging` module contains the following:
139139

140-
* xref:rsocket.adoc#rsocket-requester[RSocketRequester] -- fluent API to make requests through an `io.rsocket.RSocket`
141-
with data and metadata encoding/decoding.
142-
* xref:rsocket.adoc#rsocket-interface[RSocket Interfaces] -- `@RSocketExchange` annotated
143-
interfaces for making requests.
140+
* xref:rsocket.adoc#rsocket-requester[RSocketRequester] -- fluent API to make requests
141+
through an `io.rsocket.RSocket` with data and metadata encoding/decoding.
144142
* xref:rsocket.adoc#rsocket-annot-responders[Annotated Responders] -- `@MessageMapping`
145143
and `@RSocketExchange` annotated handler methods for responding.
144+
* xref:rsocket.adoc#rsocket-interface[RSocket Interface] -- RSocket service declaration
145+
as Java interface with `@RSocketExchange` methods, for use as requester or responder.
146146

147147
The `spring-web` module contains `Encoder` and `Decoder` implementations such as Jackson
148148
CBOR/JSON, and Protobuf that RSocket applications will likely need. It also contains the
@@ -864,26 +864,32 @@ interaction type(s):
864864
|===
865865

866866

867+
867868
[[rsocket-annot-rsocketexchange]]
868869
=== @RSocketExchange
869870

870-
While `@MessageMapping` is only supported for responding, `@RSocketExchange`
871-
can be used both to create an annotated responder
872-
and xref:rsocket.adoc#rsocket-interface[an RSocket Interface] that allows
873-
making requests.
871+
As an alternative to `@MessageMapping`, you can also handle requests with
872+
`@RSocketExchange` methods. Such methods are declared on an
873+
xref:rsocket-interface[RSocket Interface] and can be used as a requester via
874+
`RSocketServiceProxyFactory` or as a responder.
874875

875-
`@RSocketExchange` can be used as follows to create responder methods:
876+
For example, to handle requests as a responder:
876877

877878
[tabs]
878879
======
879880
Java::
880881
+
881882
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
882883
----
883-
@Controller
884-
public class RadarsController {
884+
public interface RadarsService {
885885
886886
@RSocketExchange("locate.radars.within")
887+
Flux<AirportLocation> radars(MapRequest request);
888+
}
889+
890+
@Controller
891+
public class RadarsController implements RadarsService {
892+
887893
public Flux<AirportLocation> radars(MapRequest request) {
888894
// ...
889895
}
@@ -894,28 +900,32 @@ Kotlin::
894900
+
895901
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
896902
----
897-
@Controller
898-
class RadarsController {
903+
interface RadarsService {
899904
900-
@RSocketExchange("locate.radars.within")
901-
fun radars(request: MapRequest): Flow<AirportLocation> {
902-
// ...
905+
@RSocketExchange("locate.radars.within")
906+
fun radars(request: MapRequest): Flow<AirportLocation>
907+
}
908+
909+
@Controller
910+
class RadarsController : RadarsService {
911+
912+
override fun radars(request: MapRequest): Flow<AirportLocation> {
913+
// ...
914+
}
903915
}
904-
}
905916
----
906917
======
907918

908-
`@RSocketExhange` supports a very similar method signature to `@MessageMapping`,
909-
however, since it needs to be suitable both for requester and responder use,
910-
there are slight differences. Notably, while `@MessageMapping` accepts
911-
a `String` array as its `value` parameter, only a single `String` can be passed
912-
as the `value` of `@RSocketExchange`.
919+
There some differences between `@RSocketExhange` and `@MessageMapping` since the
920+
former needs to remain suitable for requester and responder use. For example, while
921+
`@MessageMapping` can be declared to handle any number of routes and each route can
922+
be a pattern, `@RSocketExchange` must be declared with a single, concrete route. There are
923+
also small differences in the supported method parameters related to metadata, see
924+
xref:rsocket-annot-messagemapping[@MessageMapping] and
925+
xref:rsocket-interface[RSocket Interface] for a list of supported parameters.
913926

914-
When it comes to possible return values and the way we establish supported
915-
RSocket interaction types, it works in the same way as with `@MessageMapping`.
916-
917-
Similarly to `@MessageMapping`, `@RSocketExchange` can also be used at class
918-
level to specify a common prefix for all the method routes within the class.
927+
`@RSocketExchange` can be used at the type level to specify a common prefix for all routes
928+
for a given RSocket service interface.
919929

920930

921931
[[rsocket-annot-connectmapping]]
@@ -1052,12 +1062,13 @@ Kotlin::
10521062
[[rsocket-interface]]
10531063
== RSocket Interface
10541064

1055-
The Spring Framework lets you define an RSocket service as a Java interface with annotated
1056-
methods for RSocket exchanges. You can then generate a proxy that implements this interface
1057-
and performs the exchanges. This helps to simplify RSocket remote access by wrapping the
1058-
use of the underlying xref:rsocket.adoc#rsocket-requester[RSocketRequester].
1065+
The Spring Framework lets you define an RSocket service as a Java interface with
1066+
`@RSocketExchange` methods. You can pass such an interface to `RSocketServiceProxyFactory`
1067+
to create a proxy which performs requests through an
1068+
xref:rsocket.adoc#rsocket-requester[RSocketRequester]. You can also implement the
1069+
interface as a responder that handles requests.
10591070

1060-
One, declare an interface with `@RSocketExchange` methods:
1071+
Start by creating the interface with `@RSocketExchange` methods:
10611072

10621073
[source,java,indent=0,subs="verbatim,quotes"]
10631074
----
@@ -1071,7 +1082,7 @@ One, declare an interface with `@RSocketExchange` methods:
10711082
}
10721083
----
10731084

1074-
Two, create a proxy that will perform the declared RSocket exchanges:
1085+
Now you can create a proxy that performs requests when methods are called:
10751086

10761087
[source,java,indent=0,subs="verbatim,quotes"]
10771088
----
@@ -1081,8 +1092,9 @@ Two, create a proxy that will perform the declared RSocket exchanges:
10811092
RepositoryService service = factory.createClient(RadarService.class);
10821093
----
10831094

1084-
NOTE: Apart from RSocket interface services, `@RSocketExchange` can also
1085-
be used to create xref:rsocket.adoc#rsocket-annot-rsocketexchange[annotated responders].
1095+
You can also implement the interface to handle requests as a responder.
1096+
See xref:rsocket.adoc#rsocket-annot-rsocketexchange[Annotated Responders].
1097+
10861098

10871099

10881100
[[rsocket-interface-method-parameters]]

spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketMessageHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@
6060
import org.springframework.util.StringUtils;
6161

6262
/**
63-
* Extension of {@link MessageMappingMessageHandler} for handling RSocket
64-
* requests with {@link ConnectMapping @ConnectMapping},
65-
* {@link MessageMapping @MessageMapping}
66-
* and {@link RSocketExchange @RSocketExchange} methods.
63+
* Extension of {@link MessageMappingMessageHandler} to handle RSocket
64+
* requests with {@link MessageMapping @MessageMapping} and
65+
* {@link ConnectMapping @ConnectMapping} methods, also supporting use of
66+
* {@link RSocketExchange @RSocketExchange}.
6767
*
6868
* <p>For server scenarios this class can be declared as a bean in Spring
6969
* configuration and that would detect {@code @MessageMapping} methods in

spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketExchange.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
import org.springframework.aot.hint.annotation.Reflective;
2626

2727
/**
28-
* Annotation to declare a method on an RSocket service interface as an RSocket
29-
* endpoint. The endpoint route is determined through the annotation attribute,
28+
* Annotation to declare an RSocket endpoint on an RSocket service interface.
29+
* Supported for use as an RSocket requester via
30+
* {@link RSocketServiceProxyFactory}, and as a responder by implementing the
31+
* interface to handle requests.
32+
*
33+
* <p>The endpoint route is determined through the annotation attribute,
3034
* and through the method arguments.
3135
*
3236
* <p>The annotation is supported at the type level to express a common route,

spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceProxyFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import org.springframework.util.StringValueResolver;
4040

4141
/**
42-
* Factory for creating a client proxy given an RSocket service interface with
42+
* Factory to create a client proxy from an RSocket service interface with
4343
* {@link RSocketExchange @RSocketExchange} methods.
4444
*
4545
* <p>To create an instance, use static methods to obtain a

0 commit comments

Comments
 (0)