|
17 | 17 | package org.springframework.messaging.rsocket;
|
18 | 18 |
|
19 | 19 | import java.net.URI;
|
| 20 | +import java.util.List; |
20 | 21 | import java.util.function.Consumer;
|
21 | 22 |
|
22 | 23 | import io.rsocket.ConnectionSetupPayload;
|
23 | 24 | import io.rsocket.Payload;
|
24 | 25 | import io.rsocket.RSocket;
|
25 | 26 | import io.rsocket.core.RSocketClient;
|
| 27 | +import io.rsocket.loadbalance.LoadbalanceStrategy; |
| 28 | +import io.rsocket.loadbalance.LoadbalanceTarget; |
26 | 29 | import io.rsocket.transport.ClientTransport;
|
27 | 30 | import io.rsocket.transport.netty.client.TcpClientTransport;
|
28 | 31 | import io.rsocket.transport.netty.client.WebsocketClientTransport;
|
@@ -116,8 +119,9 @@ static RSocketRequester.Builder builder() {
|
116 | 119 | }
|
117 | 120 |
|
118 | 121 | /**
|
119 |
| - * Wrap an existing {@link RSocket}. Typically used in client or server |
120 |
| - * responders to wrap the {@code RSocket} for the remote side. |
| 122 | + * Wrap an existing {@link RSocket}. Typically for internal framework use, |
| 123 | + * to wrap the remote {@code RSocket} in a client or server responder, but |
| 124 | + * it can also be used to wrap any {@link RSocket}. |
121 | 125 | */
|
122 | 126 | static RSocketRequester wrap(
|
123 | 127 | RSocket rsocket, MimeType dataMimeType, MimeType metadataMimeType,
|
@@ -224,36 +228,56 @@ interface Builder {
|
224 | 228 | RSocketRequester.Builder apply(Consumer<RSocketRequester.Builder> configurer);
|
225 | 229 |
|
226 | 230 | /**
|
227 |
| - * Build an {@link RSocketRequester} instance for use with a TCP |
228 |
| - * transport. Requests are made via {@link io.rsocket.core.RSocketClient} |
229 |
| - * which establishes a shared TCP connection to given host and port. |
230 |
| - * @param host the host of the server to connect to |
231 |
| - * @param port the port of the server to connect to |
| 231 | + * Build an {@link RSocketRequester} with an |
| 232 | + * {@link io.rsocket.core.RSocketClient} that connects over TCP to the |
| 233 | + * given host and port. The requester can be used to make requests |
| 234 | + * concurrently. Requests are made over a shared connection that is also |
| 235 | + * re-established as needed when further requests are made. |
| 236 | + * @param host the host to connect to |
| 237 | + * @param port the port to connect to |
232 | 238 | * @return the created {@code RSocketRequester}
|
233 | 239 | * @since 5.3
|
234 | 240 | */
|
235 | 241 | RSocketRequester tcp(String host, int port);
|
236 | 242 |
|
237 | 243 | /**
|
238 |
| - * Build an {@link RSocketRequester} instance for use with a WebSocket |
239 |
| - * transport. Requests are made via {@link io.rsocket.core.RSocketClient} |
240 |
| - * which establishes a shared WebSocket connection to given URL. |
241 |
| - * @param uri the URL of the server to connect to |
| 244 | + * Build an {@link RSocketRequester} with an |
| 245 | + * {@link io.rsocket.core.RSocketClient} that connects over WebSocket to |
| 246 | + * the given URL. The requester can be used to make requests |
| 247 | + * concurrently. Requests are made over a shared connection that is also |
| 248 | + * re-established as needed when further requests are made. |
| 249 | + * @param uri the URL to connect to |
242 | 250 | * @return the created {@code RSocketRequester}
|
243 | 251 | * @since 5.3
|
244 | 252 | */
|
245 | 253 | RSocketRequester websocket(URI uri);
|
246 | 254 |
|
247 | 255 | /**
|
248 |
| - * Build an {@link RSocketRequester} instance for use with the given |
249 |
| - * transport. Requests are made via {@link io.rsocket.core.RSocketClient} |
250 |
| - * which establishes a shared connection through the given transport. |
251 |
| - * @param transport the transport to use for connecting to the server |
| 256 | + * Variant of {@link #tcp(String, int)} and {@link #websocket(URI)} |
| 257 | + * with an already initialized {@link ClientTransport}. |
| 258 | + * @param transport the transport to connect with |
252 | 259 | * @return the created {@code RSocketRequester}
|
253 | 260 | * @since 5.3
|
254 | 261 | */
|
255 | 262 | RSocketRequester transport(ClientTransport transport);
|
256 | 263 |
|
| 264 | + /** |
| 265 | + * Build an {@link RSocketRequester} with an |
| 266 | + * {@link io.rsocket.loadbalance.LoadbalanceRSocketClient} that will |
| 267 | + * connect to one of the given targets selected through the given |
| 268 | + * {@link io.rsocket.loadbalance.LoadbalanceRSocketClient}. |
| 269 | + * @param targetPublisher a {@code Publisher} that supplies a list of |
| 270 | + * target transports to loadbalance against; the given list may be |
| 271 | + * periodically updated by the {@code Publisher}. |
| 272 | + * @param loadbalanceStrategy the strategy to use for selecting from |
| 273 | + * the list of loadbalance targets. |
| 274 | + * @return the created {@code RSocketRequester} |
| 275 | + * @since 5.3 |
| 276 | + */ |
| 277 | + RSocketRequester transports( |
| 278 | + Publisher<List<LoadbalanceTarget>> targetPublisher, |
| 279 | + LoadbalanceStrategy loadbalanceStrategy); |
| 280 | + |
257 | 281 | /**
|
258 | 282 | * Connect to the server over TCP.
|
259 | 283 | * @param host the server host
|
|
0 commit comments