@@ -137,12 +137,12 @@ demonstrate its API and protocol features.
137
137
138
138
The `spring-messaging` module contains the following:
139
139
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.
144
142
* xref:rsocket.adoc#rsocket-annot-responders[Annotated Responders] -- `@MessageMapping`
145
143
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.
146
146
147
147
The `spring-web` module contains `Encoder` and `Decoder` implementations such as Jackson
148
148
CBOR/JSON, and Protobuf that RSocket applications will likely need. It also contains the
@@ -864,26 +864,32 @@ interaction type(s):
864
864
|===
865
865
866
866
867
+
867
868
[[rsocket-annot-rsocketexchange]]
868
869
=== @RSocketExchange
869
870
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 .
874
875
875
- `@RSocketExchange` can be used as follows to create responder methods :
876
+ For example, to handle requests as a responder:
876
877
877
878
[tabs]
878
879
======
879
880
Java::
880
881
+
881
882
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
882
883
----
883
- @Controller
884
- public class RadarsController {
884
+ public interface RadarsService {
885
885
886
886
@RSocketExchange("locate.radars.within")
887
+ Flux<AirportLocation> radars(MapRequest request);
888
+ }
889
+
890
+ @Controller
891
+ public class RadarsController implements RadarsService {
892
+
887
893
public Flux<AirportLocation> radars(MapRequest request) {
888
894
// ...
889
895
}
@@ -894,28 +900,32 @@ Kotlin::
894
900
+
895
901
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
896
902
----
897
- @Controller
898
- class RadarsController {
903
+ interface RadarsService {
899
904
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
+ }
903
915
}
904
- }
905
916
----
906
917
======
907
918
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.
913
926
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.
919
929
920
930
921
931
[[rsocket-annot-connectmapping]]
@@ -1052,12 +1062,13 @@ Kotlin::
1052
1062
[[rsocket-interface]]
1053
1063
== RSocket Interface
1054
1064
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.
1059
1070
1060
- One, declare an interface with `@RSocketExchange` methods:
1071
+ Start by creating the interface with `@RSocketExchange` methods:
1061
1072
1062
1073
[source,java,indent=0,subs="verbatim,quotes"]
1063
1074
----
@@ -1071,7 +1082,7 @@ One, declare an interface with `@RSocketExchange` methods:
1071
1082
}
1072
1083
----
1073
1084
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 :
1075
1086
1076
1087
[source,java,indent=0,subs="verbatim,quotes"]
1077
1088
----
@@ -1081,8 +1092,9 @@ Two, create a proxy that will perform the declared RSocket exchanges:
1081
1092
RepositoryService service = factory.createClient(RadarService.class);
1082
1093
----
1083
1094
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
+
1086
1098
1087
1099
1088
1100
[[rsocket-interface-method-parameters]]
0 commit comments