|
4 | 4 | import reactor.core.Disposable;
|
5 | 5 | import reactor.core.publisher.Flux;
|
6 | 6 | import reactor.core.publisher.Mono;
|
| 7 | +import reactor.util.retry.Retry; |
7 | 8 |
|
8 | 9 | /**
|
9 |
| - * A client-side interface to simplify interactions with the {@link |
10 |
| - * io.rsocket.core.RSocketConnector}. This interface represents logical communication over {@link |
11 |
| - * RSocket}, hiding the complexity of {@code Mono<RSocket>} resolution. Also, in opposite to {@link |
12 |
| - * RSocket} , {@link RSocketClient} supports multi-subscription on the same {@link Publisher} from |
13 |
| - * the interaction in the way of accepting input as {@link Publisher} like {@link Mono} or {@link |
14 |
| - * Flux} Despite, {@link RSocket} interface, {@link RSocketClient} does not coupled with a single |
15 |
| - * connection, hence disposal of the {@link #source()} {@link RSocket} will affect the {@link |
16 |
| - * RSocketClient} it selves. In such a case, a new request will cause automatic reconnection if |
17 |
| - * necessary. |
| 10 | + * Contract to perform RSocket requests from client to server, transparently connecting and ensuring |
| 11 | + * a single, shared connection to make requests with. |
| 12 | + * |
| 13 | + * <p>{@code RSocketClient} contains a {@code Mono<RSocket>} {@link #source() source}. It uses it to |
| 14 | + * obtain a live, shared {@link RSocket} connection on the first request and on subsequent requests |
| 15 | + * if the connection is lost. This eliminates the need to obtain a connection first, and makes it |
| 16 | + * easy to pass a single {@code RSocketClient} to use from multiple places. |
| 17 | + * |
| 18 | + * <p>Request methods of {@code RSocketClient} allow multiple subscriptions with each subscription |
| 19 | + * performing a new request. Therefore request methods accept {@code Mono<Payload>} rather than |
| 20 | + * {@code Payload} as on {@link RSocket}. By contrast, {@link RSocket} request methods cannot be |
| 21 | + * subscribed to more than once. |
| 22 | + * |
| 23 | + * <p>Use {@link io.rsocket.core.RSocketConnector RSocketConnector} to create a client: |
| 24 | + * |
| 25 | + * <pre class="code">{@code |
| 26 | + * RSocketClient client = |
| 27 | + * RSocketConnector.create() |
| 28 | + * .metadataMimeType("message/x.rsocket.composite-metadata.v0") |
| 29 | + * .dataMimeType("application/cbor") |
| 30 | + * .toRSocketClient(TcpClientTransport.create("localhost", 7000)); |
| 31 | + * }</pre> |
| 32 | + * |
| 33 | + * <p>Use the {@link io.rsocket.core.RSocketConnector#reconnect(Retry) RSocketConnector#reconnect} |
| 34 | + * method to configure the retry logic to use whenever a shared {@code RSocket} connection needs to |
| 35 | + * be obtained: |
| 36 | + * |
| 37 | + * <pre class="code">{@code |
| 38 | + * RSocketClient client = |
| 39 | + * RSocketConnector.create() |
| 40 | + * .metadataMimeType("message/x.rsocket.composite-metadata.v0") |
| 41 | + * .dataMimeType("application/cbor") |
| 42 | + * .reconnect(Retry.fixedDelay(3, Duration.ofSeconds(1))) |
| 43 | + * .toRSocketClient(TcpClientTransport.create("localhost", 7000)); |
| 44 | + * }</pre> |
18 | 45 | *
|
19 | 46 | * @since 1.0.1
|
20 | 47 | */
|
21 | 48 | public interface RSocketClient extends Disposable {
|
22 | 49 |
|
23 |
| - /** |
24 |
| - * Provides access to the source {@link RSocket} used by this {@link RSocketClient} |
25 |
| - * |
26 |
| - * @return returns a {@link Mono} which returns the source {@link RSocket} |
27 |
| - */ |
| 50 | + /** Return the underlying source used to obtain a shared {@link RSocket} connection. */ |
28 | 51 | Mono<RSocket> source();
|
29 | 52 |
|
30 | 53 | /**
|
31 |
| - * Fire and Forget interaction model of {@link RSocketClient}. |
32 |
| - * |
33 |
| - * @param payloadMono Request payload as {@link Mono}. |
34 |
| - * @return {@code Publisher} that completes when the passed {@code payload} is successfully |
35 |
| - * handled, otherwise errors. |
| 54 | + * Perform a Fire-and-Forget interaction via {@link RSocket#fireAndForget(Payload)}. Allows |
| 55 | + * multiple subscriptions and performs a request per subscriber. |
36 | 56 | */
|
37 | 57 | Mono<Void> fireAndForget(Mono<Payload> payloadMono);
|
38 | 58 |
|
39 | 59 | /**
|
40 |
| - * Request-Response interaction model of {@link RSocketClient}. |
41 |
| - * |
42 |
| - * @param payloadMono Request payload as {@link Mono}. |
43 |
| - * @return {@code Publisher} containing at most a single {@code Payload} representing the |
44 |
| - * response. |
| 60 | + * Perform a Request-Response interaction via {@link RSocket#requestResponse(Payload)}. Allows |
| 61 | + * multiple subscriptions and performs a request per subscriber. |
45 | 62 | */
|
46 | 63 | Mono<Payload> requestResponse(Mono<Payload> payloadMono);
|
47 | 64 |
|
48 | 65 | /**
|
49 |
| - * Request-Stream interaction model of {@link RSocketClient}. |
50 |
| - * |
51 |
| - * @param payloadMono Request payload as {@link Mono}. |
52 |
| - * @return {@code Publisher} containing the stream of {@code Payload}s representing the response. |
| 66 | + * Perform a Request-Stream interaction via {@link RSocket#requestStream(Payload)}. Allows |
| 67 | + * multiple subscriptions and performs a request per subscriber. |
53 | 68 | */
|
54 | 69 | Flux<Payload> requestStream(Mono<Payload> payloadMono);
|
55 | 70 |
|
56 | 71 | /**
|
57 |
| - * Request-Channel interaction model of {@link RSocketClient}. |
58 |
| - * |
59 |
| - * @param payloads Stream of request payloads. |
60 |
| - * @return Stream of response payloads. |
| 72 | + * Perform a Request-Channel interaction via {@link RSocket#requestChannel(Publisher)}. Allows |
| 73 | + * multiple subscriptions and performs a request per subscriber. |
61 | 74 | */
|
62 | 75 | Flux<Payload> requestChannel(Publisher<Payload> payloads);
|
63 | 76 |
|
64 | 77 | /**
|
65 |
| - * Metadata-Push interaction model of {@link RSocketClient}. |
66 |
| - * |
67 |
| - * @param payloadMono Request payload as {@link Mono}. |
68 |
| - * @return {@code Publisher} that completes when the passed {@code payload} is successfully |
69 |
| - * handled, otherwise errors. |
| 78 | + * Perform a Metadata Push via {@link RSocket#metadataPush(Payload)}. Allows multiple |
| 79 | + * subscriptions and performs a request per subscriber. |
70 | 80 | */
|
71 | 81 | Mono<Void> metadataPush(Mono<Payload> payloadMono);
|
72 | 82 | }
|
0 commit comments