|
|
@ -137,12 +137,12 @@ demonstrate its API and protocol features. |
|
|
|
|
|
|
|
|
|
|
|
The `spring-messaging` module contains the following: |
|
|
|
The `spring-messaging` module contains the following: |
|
|
|
|
|
|
|
|
|
|
|
* xref:rsocket.adoc#rsocket-requester[RSocketRequester] -- fluent API to make requests through an `io.rsocket.RSocket` |
|
|
|
* xref:rsocket.adoc#rsocket-requester[RSocketRequester] -- fluent API to make requests |
|
|
|
with data and metadata encoding/decoding. |
|
|
|
through an `io.rsocket.RSocket` with data and metadata encoding/decoding. |
|
|
|
* xref:rsocket.adoc#rsocket-interface[RSocket Interfaces] -- `@RSocketExchange` annotated |
|
|
|
|
|
|
|
interfaces for making requests. |
|
|
|
|
|
|
|
* xref:rsocket.adoc#rsocket-annot-responders[Annotated Responders] -- `@MessageMapping` |
|
|
|
* xref:rsocket.adoc#rsocket-annot-responders[Annotated Responders] -- `@MessageMapping` |
|
|
|
and `@RSocketExchange` annotated handler methods for responding. |
|
|
|
and `@RSocketExchange` annotated handler methods for responding. |
|
|
|
|
|
|
|
* xref:rsocket.adoc#rsocket-interface[RSocket Interface] -- RSocket service declaration |
|
|
|
|
|
|
|
as Java interface with `@RSocketExchange` methods, for use as requester or responder. |
|
|
|
|
|
|
|
|
|
|
|
The `spring-web` module contains `Encoder` and `Decoder` implementations such as Jackson |
|
|
|
The `spring-web` module contains `Encoder` and `Decoder` implementations such as Jackson |
|
|
|
CBOR/JSON, and Protobuf that RSocket applications will likely need. It also contains the |
|
|
|
CBOR/JSON, and Protobuf that RSocket applications will likely need. It also contains the |
|
|
@ -864,15 +864,16 @@ interaction type(s): |
|
|
|
|=== |
|
|
|
|=== |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[rsocket-annot-rsocketexchange]] |
|
|
|
[[rsocket-annot-rsocketexchange]] |
|
|
|
=== @RSocketExchange |
|
|
|
=== @RSocketExchange |
|
|
|
|
|
|
|
|
|
|
|
While `@MessageMapping` is only supported for responding, `@RSocketExchange` |
|
|
|
As an alternative to `@MessageMapping`, you can also handle requests with |
|
|
|
can be used both to create an annotated responder |
|
|
|
`@RSocketExchange` methods. Such methods are declared on an |
|
|
|
and xref:rsocket.adoc#rsocket-interface[an RSocket Interface] that allows |
|
|
|
xref:rsocket-interface[RSocket Interface] and can be used as a requester via |
|
|
|
making requests. |
|
|
|
`RSocketServiceProxyFactory` or as a responder. |
|
|
|
|
|
|
|
|
|
|
|
`@RSocketExchange` can be used as follows to create responder methods: |
|
|
|
For example, to handle requests as a responder: |
|
|
|
|
|
|
|
|
|
|
|
[tabs] |
|
|
|
[tabs] |
|
|
|
====== |
|
|
|
====== |
|
|
@ -880,10 +881,15 @@ Java:: |
|
|
|
+ |
|
|
|
+ |
|
|
|
[source,java,indent=0,subs="verbatim,quotes",role="primary"] |
|
|
|
[source,java,indent=0,subs="verbatim,quotes",role="primary"] |
|
|
|
---- |
|
|
|
---- |
|
|
|
@Controller |
|
|
|
public interface RadarsService { |
|
|
|
public class RadarsController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RSocketExchange("locate.radars.within") |
|
|
|
@RSocketExchange("locate.radars.within") |
|
|
|
|
|
|
|
Flux<AirportLocation> radars(MapRequest request); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
|
|
|
public class RadarsController implements RadarsService { |
|
|
|
|
|
|
|
|
|
|
|
public Flux<AirportLocation> radars(MapRequest request) { |
|
|
|
public Flux<AirportLocation> radars(MapRequest request) { |
|
|
|
// ... |
|
|
|
// ... |
|
|
|
} |
|
|
|
} |
|
|
@ -894,28 +900,32 @@ Kotlin:: |
|
|
|
+ |
|
|
|
+ |
|
|
|
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] |
|
|
|
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] |
|
|
|
---- |
|
|
|
---- |
|
|
|
@Controller |
|
|
|
interface RadarsService { |
|
|
|
class RadarsController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RSocketExchange("locate.radars.within") |
|
|
|
@RSocketExchange("locate.radars.within") |
|
|
|
fun radars(request: MapRequest): Flow<AirportLocation> { |
|
|
|
fun radars(request: MapRequest): Flow<AirportLocation> |
|
|
|
// ... |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
|
|
|
class RadarsController : RadarsService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun radars(request: MapRequest): Flow<AirportLocation> { |
|
|
|
|
|
|
|
// ... |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
---- |
|
|
|
---- |
|
|
|
====== |
|
|
|
====== |
|
|
|
|
|
|
|
|
|
|
|
`@RSocketExhange` supports a very similar method signature to `@MessageMapping`, |
|
|
|
There some differences between `@RSocketExhange` and `@MessageMapping` since the |
|
|
|
however, since it needs to be suitable both for requester and responder use, |
|
|
|
former needs to remain suitable for requester and responder use. For example, while |
|
|
|
there are slight differences. Notably, while `@MessageMapping` accepts |
|
|
|
`@MessageMapping` can be declared to handle any number of routes and each route can |
|
|
|
a `String` array as its `value` parameter, only a single `String` can be passed |
|
|
|
be a pattern, `@RSocketExchange` must be declared with a single, concrete route. There are |
|
|
|
as the `value` of `@RSocketExchange`. |
|
|
|
also small differences in the supported method parameters related to metadata, see |
|
|
|
|
|
|
|
xref:rsocket-annot-messagemapping[@MessageMapping] and |
|
|
|
|
|
|
|
xref:rsocket-interface[RSocket Interface] for a list of supported parameters. |
|
|
|
|
|
|
|
|
|
|
|
When it comes to possible return values and the way we establish supported |
|
|
|
`@RSocketExchange` can be used at the type level to specify a common prefix for all routes |
|
|
|
RSocket interaction types, it works in the same way as with `@MessageMapping`. |
|
|
|
for a given RSocket service interface. |
|
|
|
|
|
|
|
|
|
|
|
Similarly to `@MessageMapping`, `@RSocketExchange` can also be used at class |
|
|
|
|
|
|
|
level to specify a common prefix for all the method routes within the class. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[rsocket-annot-connectmapping]] |
|
|
|
[[rsocket-annot-connectmapping]] |
|
|
@ -1052,12 +1062,13 @@ Kotlin:: |
|
|
|
[[rsocket-interface]] |
|
|
|
[[rsocket-interface]] |
|
|
|
== RSocket Interface |
|
|
|
== RSocket Interface |
|
|
|
|
|
|
|
|
|
|
|
The Spring Framework lets you define an RSocket service as a Java interface with annotated |
|
|
|
The Spring Framework lets you define an RSocket service as a Java interface with |
|
|
|
methods for RSocket exchanges. You can then generate a proxy that implements this interface |
|
|
|
`@RSocketExchange` methods. You can pass such an interface to `RSocketServiceProxyFactory` |
|
|
|
and performs the exchanges. This helps to simplify RSocket remote access by wrapping the |
|
|
|
to create a proxy which performs requests through an |
|
|
|
use of the underlying xref:rsocket.adoc#rsocket-requester[RSocketRequester]. |
|
|
|
xref:rsocket.adoc#rsocket-requester[RSocketRequester]. You can also implement the |
|
|
|
|
|
|
|
interface as a responder that handles requests. |
|
|
|
|
|
|
|
|
|
|
|
One, declare an interface with `@RSocketExchange` methods: |
|
|
|
Start by creating the interface with `@RSocketExchange` methods: |
|
|
|
|
|
|
|
|
|
|
|
[source,java,indent=0,subs="verbatim,quotes"] |
|
|
|
[source,java,indent=0,subs="verbatim,quotes"] |
|
|
|
---- |
|
|
|
---- |
|
|
@ -1071,7 +1082,7 @@ One, declare an interface with `@RSocketExchange` methods: |
|
|
|
} |
|
|
|
} |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
Two, create a proxy that will perform the declared RSocket exchanges: |
|
|
|
Now you can create a proxy that performs requests when methods are called: |
|
|
|
|
|
|
|
|
|
|
|
[source,java,indent=0,subs="verbatim,quotes"] |
|
|
|
[source,java,indent=0,subs="verbatim,quotes"] |
|
|
|
---- |
|
|
|
---- |
|
|
@ -1081,8 +1092,9 @@ Two, create a proxy that will perform the declared RSocket exchanges: |
|
|
|
RepositoryService service = factory.createClient(RadarService.class); |
|
|
|
RepositoryService service = factory.createClient(RadarService.class); |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
NOTE: Apart from RSocket interface services, `@RSocketExchange` can also |
|
|
|
You can also implement the interface to handle requests as a responder. |
|
|
|
be used to create xref:rsocket.adoc#rsocket-annot-rsocketexchange[annotated responders]. |
|
|
|
See xref:rsocket.adoc#rsocket-annot-rsocketexchange[Annotated Responders]. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[rsocket-interface-method-parameters]] |
|
|
|
[[rsocket-interface-method-parameters]] |
|
|
|