public interface RSocketClient extends Disposable
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);
LoadbalanceRSocketClient
Disposable.Composite, Disposable.Swap
Modifier and Type | Method and Description |
---|---|
Mono<Void> |
fireAndForget(Mono<Payload> payloadMono)
Perform a Fire-and-Forget interaction via
RSocket.fireAndForget(Payload) . |
static RSocketClient |
from(Mono<RSocket> source)
Create an
RSocketClient that obtains shared connections as needed, when requests are
made, from the given Mono<RSocket> source. |
static RSocketClient |
from(RSocket rsocket)
Adapt the given
RSocket to use as RSocketClient . |
Mono<Void> |
metadataPush(Mono<Payload> payloadMono)
Perform a Metadata Push via
RSocket.metadataPush(Payload) . |
Flux<Payload> |
requestChannel(org.reactivestreams.Publisher<Payload> payloads)
Perform a Request-Channel interaction via
RSocket.requestChannel(Publisher) . |
Mono<Payload> |
requestResponse(Mono<Payload> payloadMono)
Perform a Request-Response interaction via
RSocket.requestResponse(Payload) . |
Flux<Payload> |
requestStream(Mono<Payload> payloadMono)
Perform a Request-Stream interaction via
RSocket.requestStream(Payload) . |
Mono<RSocket> |
source()
Return the underlying source used to obtain a shared
RSocket connection. |
dispose, isDisposed
Mono<RSocket> source()
RSocket
connection.Mono<Void> fireAndForget(Mono<Payload> payloadMono)
RSocket.fireAndForget(Payload)
. Allows
multiple subscriptions and performs a request per subscriber.Mono<Payload> requestResponse(Mono<Payload> payloadMono)
RSocket.requestResponse(Payload)
. Allows
multiple subscriptions and performs a request per subscriber.Flux<Payload> requestStream(Mono<Payload> payloadMono)
RSocket.requestStream(Payload)
. Allows
multiple subscriptions and performs a request per subscriber.Flux<Payload> requestChannel(org.reactivestreams.Publisher<Payload> payloads)
RSocket.requestChannel(Publisher)
. Allows
multiple subscriptions and performs a request per subscriber.Mono<Void> metadataPush(Mono<Payload> payloadMono)
RSocket.metadataPush(Payload)
. Allows multiple
subscriptions and performs a request per subscriber.static RSocketClient from(Mono<RSocket> source)
RSocketClient
that obtains shared connections as needed, when requests are
made, from the given Mono<RSocket>
source.source
- the source for connections, typically prepared via RSocketConnector
.static RSocketClient from(RSocket rsocket)
RSocket
to use as RSocketClient
. This is useful to wrap the
sending RSocket
in a server.
Note: unlike an RSocketClient
created via from(Mono)
, the instance returned from this factory method can only perform
requests for as long as the given RSocket
remains "live".
rsocket
- the RSocket
to perform requests with