Auto-configure RSocketRequester.Builder

This commit auto-configures a prototype `RSocketRequester.Builder` bean
for building requester instances. This builder is pre-configured with
auto-detected `RSocketStrategies` (same as the server side).

Closes gh-16280
This commit is contained in:
Brian Clozel
2019-05-13 16:03:21 +02:00
parent 6544d19fbf
commit 20dfeddbb3
5 changed files with 187 additions and 13 deletions

View File

@@ -3528,6 +3528,42 @@ about customization possibilities.
Developers can create `RSocketStrategiesCustomizer` beans to add other strategies,
assuming there are `Encoder` and `Decoder` implementations available.
[[boot-features-rsocket-requester]]
=== Calling RSocket Services with `RSocketRequester`
Once the `RSocket` channel is established between server and client, any party can send or
receive requests to the other.
As a server, you can get injected an `RSocketRequester` instance on any handler method of
an RSocket `@Controller`. As a client, you need to configure and establish an RSocket
connection first. Spring Boot auto-configures an `RSocketRequester.Builder` for such cases
with the expected codecs.
The `RSocketRequester.Builder` instance is a prototype bean, meaning each injection point
will provide you with a new instance - this is done on purpose since this builder is stateful
and you shouldn't create requesters with different setups using the same instance.
The following code shows a typical example:
[source,java,indent=0]
----
@Service
public class MyService {
private final RSocketRequester rsocketRequester;
public MyService(RSocketRequester.Builder rsocketRequesterBuilder) {
this.rsocketRequester = rsocketRequesterBuilder
.connectTcp("example.org", 9090).block();
}
public Mono<User> someRSocketCall(String name) {
return this.requester.route("user").data(payload)
.retrieveMono(User.class);
}
}
----
[[boot-features-security]]