RSocketClient differs from RSocket in a number of ways:
RSocket represents a "live" connection that is transient and needs to be obtained
typically from a Mono<RSocket> source via flatMap or block. By contrast,
RSocketClient is a higher level layer that contains such a source
of connections and transparently obtains and re-obtains a shared connection as needed when
requests are made concurrently. That means an RSocketClient can simply be created
once, even before a connection is established, and shared as a singleton across multiple
places as you would with any other client.
RSocket accepts an instance of Payload and does not allow
more than one subscription per request because there is no way to safely re-use that input.
By contrast RSocketClient accepts Publisher<Payload> and allow
re-subscribing which repeats the request.
RSocket can be used for sending and it can also be implemented for receiving. By
contrast RSocketClient is used only for sending, typically from the client side
which allows obtaining and re-obtaining connections from a source as needed. However it can
also be used from the server side by wrapping the "live" RSocket for a given connection.
The example below shows how to create an RSocketClient:
Mono<RSocket> source =
RSocketConnector.create()
.metadataMimeType("message/x.rsocket.composite-metadata.v0")
.dataMimeType("application/cbor")
.connect(TcpClientTransport.create("localhost", 7000));
RSocketClient client = RSocketClient.from(source);
The below configures retry logic to use when a shared RSocket connection is obtained:
Mono<RSocket> source =
RSocketConnector.create()
.metadataMimeType("message/x.rsocket.composite-metadata.v0")
.dataMimeType("application/cbor")
.reconnect(Retry.fixedDelay(3, Duration.ofSeconds(1)))
.connect(TcpClientTransport.create("localhost", 7000));
RSocketClient client = RSocketClient.from(source);
io.rsocket.loadbalance.LoadbalanceRSocketClient
| Modifier and Type | Method and Description |
|---|---|
| public default boolean | Returns: true if an attempt to connect was triggered or if already connected, or false if the client is terminated.Connect to the remote rsocket endpoint, if not yet connected. |
| public Mono | fireAndForget(Mono<Payload> payloadMono)
Perform a Fire-and-Forget interaction via |
| public static RSocketClient | Returns: the created client instancethe source for connections, typically prepared via source)RSocketConnector.Create an |
| public static RSocketClient | Returns: the created client instancethe rsocket)RSocket to perform requests withAdapt the given |
| public Mono | |
| public default Mono | onClose()
Implements io. Mono that terminates when the instance is terminated by any reason.
|
| public Flux | requestChannel(Publisher<Payload> payloads)
Perform a Request-Channel interaction via |
| public Mono | requestResponse(Mono<Payload> payloadMono)
Perform a Request-Response interaction via |
| public Flux | requestStream(Mono<Payload> payloadMono)
Perform a Request-Stream interaction via |
| public Mono |
| connect | back to summary |
|---|---|
| public default boolean connect() Connect to the remote rsocket endpoint, if not yet connected. This method is a shortcut for
| |
| fireAndForget | back to summary |
|---|---|
| public Mono Perform a Fire-and-Forget interaction via | |
| from | back to summary |
|---|---|
| public static RSocketClient from(Mono<RSocket> source) Create an
| |
| from | back to summary |
|---|---|
| public static RSocketClient from(RSocket rsocket) Adapt the given Note unlike an
| |
| metadataPush | back to summary |
|---|---|
| public Mono Perform a Metadata Push via | |
| onClose | back to summary |
|---|---|
| public default Mono Implements io. Doc from io. Returns a | |
| requestChannel | back to summary |
|---|---|
| public Flux Perform a Request-Channel interaction via | |
| requestResponse | back to summary |
|---|---|
| public Mono Perform a Request-Response interaction via | |
| requestStream | back to summary |
|---|---|
| public Flux Perform a Request-Stream interaction via | |
| source | back to summary |
|---|---|
| public Mono Return the underlying source used to obtain a shared | |