Top Description Inners Fields Constructors Methods
io.rsocket.loadbalance

public Class LoadbalanceRSocketClient

extends Object
implements RSocketClient
Class Inheritance
All Implemented Interfaces
io.rsocket.core.RSocketClient, io.rsocket.Closeable, reactor.core.Disposable
Imports
io.rsocket.Payload, .RSocket, io.rsocket.core.RSocketClient, .RSocketConnector, io.rsocket.transport.ClientTransport, java.util.List, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, reactor.util.annotation.Nullable

An implementation of RSocketClient backed by a pool of RSocket instances and using a LoadbalanceStrategy to select the RSocket to use for a given request.
Since
1.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final RSocketPool

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static LoadbalanceRSocketClient.Builder

Returns:

the created builder
builder
(Publisher<List<LoadbalanceTarget>>
refreshes the list of load balance targets periodically
targetPublisher
)

Return a builder for a LoadbalanceRSocketClient.

public boolean
connect()

Overrides default io.rsocket.core.RSocketClient.connect.

Connect to the remote rsocket endpoint, if not yet connected.
public static LoadbalanceRSocketClient

Returns:

the created client instance
create
(RSocketConnector
a "template" for connecting to load balance targets
connector
,
Publisher<List<LoadbalanceTarget>>
refreshes the list of load balance targets periodically
targetPublisher
)

Shortcut to create an LoadbalanceRSocketClient with round-robin load balancing.

public void
dispose()

Implements reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.
public Mono<Void>
fireAndForget(Mono<Payload> payloadMono)

Implements io.rsocket.core.RSocketClient.fireAndForget.

Perform a Fire-and-Forget interaction via RSocket#fireAndForget(Payload).
public Mono<Void>
public Mono<Void>
onClose()

Overrides default io.rsocket.core.RSocketClient.onClose.

Returns a Mono that terminates when the instance is terminated by any reason.
public Flux<Payload>
public Mono<Payload>
requestResponse(Mono<Payload> payloadMono)

Implements io.rsocket.core.RSocketClient.requestResponse.

Perform a Request-Response interaction via RSocket#requestResponse(Payload).
public Flux<Payload>
requestStream(Mono<Payload> payloadMono)

Implements io.rsocket.core.RSocketClient.requestStream.

Perform a Request-Stream interaction via RSocket#requestStream(Payload).
public Mono<RSocket>
source()

Implements io.rsocket.core.RSocketClient.source.

Return Mono that selects an RSocket from the underlying pool.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

rSocketPoolback to summary
private final RSocketPool rSocketPool

Constructor Detail

LoadbalanceRSocketClientback to summary
private LoadbalanceRSocketClient(RSocketPool rSocketPool)

Method Detail

builderback to summary
public static LoadbalanceRSocketClient.Builder builder(Publisher<List<LoadbalanceTarget>> targetPublisher)

Return a builder for a LoadbalanceRSocketClient.

Parameters
targetPublisher:Publisher<List<LoadbalanceTarget>>

refreshes the list of load balance targets periodically

Returns:LoadbalanceRSocketClient.Builder

the created builder

connectback to summary
public boolean connect()

Overrides default io.rsocket.core.RSocketClient.connect.

Doc from io.rsocket.core.RSocketClient.connect.

Connect to the remote rsocket endpoint, if not yet connected. This method is a shortcut for RSocketClient#source().subscribe().

Returns:boolean

true if an attempt to connect was triggered or if already connected, or false if the client is terminated.

Annotations
@Override
createback to summary
public static LoadbalanceRSocketClient create(RSocketConnector connector, Publisher<List<LoadbalanceTarget>> targetPublisher)

Shortcut to create an LoadbalanceRSocketClient with round-robin load balancing. Effectively a shortcut for:

LoadbalanceRSocketClient.builder(targetPublisher)
   .connector(RSocketConnector.create())
   .build();
Parameters
connector:RSocketConnector

a "template" for connecting to load balance targets

targetPublisher:Publisher<List<LoadbalanceTarget>>

refreshes the list of load balance targets periodically

Returns:LoadbalanceRSocketClient

the created client instance

disposeback to summary
public void dispose()

Implements reactor.core.Disposable.dispose.

Doc from reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.

Implementations are required to make this method idempotent.

Annotations
@Override
fireAndForgetback to summary
public Mono<Void> fireAndForget(Mono<Payload> payloadMono)

Implements io.rsocket.core.RSocketClient.fireAndForget.

Doc from io.rsocket.core.RSocketClient.fireAndForget.

Perform a Fire-and-Forget interaction via RSocket#fireAndForget(Payload). Allows multiple subscriptions and performs a request per subscriber.

Annotations
@Override
metadataPushback to summary
public Mono<Void> metadataPush(Mono<Payload> payloadMono)

Implements io.rsocket.core.RSocketClient.metadataPush.

Doc from io.rsocket.core.RSocketClient.metadataPush.

Perform a Metadata Push via RSocket#metadataPush(Payload). Allows multiple subscriptions and performs a request per subscriber.

Annotations
@Override
onCloseback to summary
public Mono<Void> onClose()

Overrides default io.rsocket.core.RSocketClient.onClose.

Doc from io.rsocket.Closeable.onClose.

Returns a Mono that terminates when the instance is terminated by any reason. Note, in case of error termination, the cause of error will be propagated as an error signal through org.reactivestreams.Subscriber#onError(Throwable). Otherwise, Subscriber#onComplete() will be called.

Returns:Mono<Void>

a Mono to track completion with success or error of the underlying resource. When the underlying resource is an `RSocket`, the Mono exposes stream 0 (i.e. connection level) errors.

Annotations
@Override
requestChannelback to summary
public Flux<Payload> requestChannel(Publisher<Payload> payloads)

Implements io.rsocket.core.RSocketClient.requestChannel.

Doc from io.rsocket.core.RSocketClient.requestChannel.

Perform a Request-Channel interaction via RSocket#requestChannel(Publisher). Allows multiple subscriptions and performs a request per subscriber.

Annotations
@Override
requestResponseback to summary
public Mono<Payload> requestResponse(Mono<Payload> payloadMono)

Implements io.rsocket.core.RSocketClient.requestResponse.

Doc from io.rsocket.core.RSocketClient.requestResponse.

Perform a Request-Response interaction via RSocket#requestResponse(Payload). Allows multiple subscriptions and performs a request per subscriber.

Annotations
@Override
requestStreamback to summary
public Flux<Payload> requestStream(Mono<Payload> payloadMono)

Implements io.rsocket.core.RSocketClient.requestStream.

Doc from io.rsocket.core.RSocketClient.requestStream.

Perform a Request-Stream interaction via RSocket#requestStream(Payload). Allows multiple subscriptions and performs a request per subscriber.

Annotations
@Override
sourceback to summary
public Mono<RSocket> source()

Implements io.rsocket.core.RSocketClient.source.

Return Mono that selects an RSocket from the underlying pool.

Annotations
@Override
io.rsocket.loadbalance back to summary

public Class LoadbalanceRSocketClient.Builder

extends Object
Class Inheritance

Builder for creating an LoadbalanceRSocketClient.

Field Summary

Modifier and TypeField and Description
private RSocketConnector
pack-priv LoadbalanceStrategy
private final Publisher<List<LoadbalanceTarget>>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public LoadbalanceRSocketClient
build()

Build the LoadbalanceRSocketClient instance.

public LoadbalanceRSocketClient.Builder
connector(RSocketConnector
the connector to use as a template
connector
)

Configure the "template" connector to use for connecting to load balance targets.

public LoadbalanceRSocketClient.Builder
public LoadbalanceRSocketClient.Builder
roundRobinLoadbalanceStrategy()

Configure RoundRobinLoadbalanceStrategy as the strategy to use to select targets.

public LoadbalanceRSocketClient.Builder
weightedLoadbalanceStrategy()

Configure WeightedLoadbalanceStrategy as the strategy to use to select targets.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectorback to summary
private RSocketConnector connector
Annotations
@Nullable
loadbalanceStrategyback to summary
pack-priv LoadbalanceStrategy loadbalanceStrategy
Annotations
@Nullable
targetPublisherback to summary
private final Publisher<List<LoadbalanceTarget>> targetPublisher

Constructor Detail

Builderback to summary
pack-priv Builder(Publisher<List<LoadbalanceTarget>> targetPublisher)

Method Detail

buildback to summary
public LoadbalanceRSocketClient build()

Build the LoadbalanceRSocketClient instance.

connectorback to summary
public LoadbalanceRSocketClient.Builder connector(RSocketConnector connector)

Configure the "template" connector to use for connecting to load balance targets. To establish a connection, the ClientTransport contained in each target is passed to the connector's connect method and thus the same connector with the same settings applies to all targets.

By default this is initialized with RSocketConnector#create().

Parameters
connector:RSocketConnector

the connector to use as a template

loadbalanceStrategyback to summary
public LoadbalanceRSocketClient.Builder loadbalanceStrategy(LoadbalanceStrategy strategy)

Configure the LoadbalanceStrategy to use.

By default, RoundRobinLoadbalanceStrategy is used.

roundRobinLoadbalanceStrategyback to summary
public LoadbalanceRSocketClient.Builder roundRobinLoadbalanceStrategy()

Configure RoundRobinLoadbalanceStrategy as the strategy to use to select targets.

This is the strategy used by default.

weightedLoadbalanceStrategyback to summary
public LoadbalanceRSocketClient.Builder weightedLoadbalanceStrategy()

Configure WeightedLoadbalanceStrategy as the strategy to use to select targets.

By default, RoundRobinLoadbalanceStrategy is used.