Top Description Inners Methods
org.springframework.messaging.rsocket

public Interface RSocketRequester

extends Disposable
Known Direct Implementers
org.springframework.messaging.rsocket.DefaultRSocketRequester
Imports
java.net.URI, java.util.List, java.util.function.Consumer, io.rsocket.ConnectionSetupPayload, .Payload, .RSocket, io.rsocket.core.RSocketClient, io.rsocket.loadbalance.LoadbalanceStrategy, .LoadbalanceTarget, io.rsocket.transport.ClientTransport, io.rsocket.transport.netty.client.TcpClientTransport, .WebsocketClientTransport, org.reactivestreams.Publisher, reactor.core.Disposable, reactor.core.publisher.Flux, .Mono, org.springframework.core.ParameterizedTypeReference, .ReactiveAdapterRegistry, org.springframework.core.codec.Decoder, org.springframework.lang.Nullable, org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler, org.springframework.util.MimeType

A thin wrapper around a sending RSocket with a fluent API accepting and returning higher level Objects for input and for output, along with methods to prepare routing and other metadata.
Authors
Rossen Stoyanchev, Brian Clozel
Since
5.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
RSocketRequester.Builder

Builder to create a requester by connecting to a server.

public static interface
RSocketRequester.MetadataSpec<
a self reference to the spec type
S extends RSocketRequester.MetadataSpec<S>
>

Spec for providing additional composite metadata entries.

public static interface
RSocketRequester.RequestSpec

Spec to declare the input for an RSocket request.

public static interface
RSocketRequester.RetrieveSpec

Spec to declare the expected output for an RSocket request.

Method Summary

Modifier and TypeMethod and Description
public static RSocketRequester.Builder
builder()

Obtain a builder to create a client RSocketRequester by connecting to an RSocket server.

public MimeType
dataMimeType()

Return the data MimeType selected for the underlying RSocket at connection time.

public default void
dispose()

Implements reactor.core.Disposable.dispose.

Shortcut method that delegates to the same on the underlying rsocketClient() in order to close the connection from the underlying transport and notify subscribers.
public default boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Shortcut method that delegates to the same on the underlying rsocketClient().
public RSocketRequester.RequestSpec
metadata(Object
the metadata value to encode
metadata
,
MimeType
the mime type that describes the metadata; This is required for connection using composite metadata. Otherwise, the value is encoded according to the mime type for the connection and this argument may be left as null.
mimeType
)

Begin to specify a new request with the given metadata value, which can be a concrete value or any producer of a single value that can be adapted to a Publisher via ReactiveAdapterRegistry.

public MimeType
metadataMimeType()

Return the metadata MimeType selected for the underlying RSocket at connection time.

public RSocketRequester.RequestSpec

Returns:

a spec for further defining and executing the request
route
(String
the route expressing a remote handler mapping
route
,
Object...
variables to be expanded into the route template
routeVars
)

Begin to specify a new request with the given route to a remote handler.

public RSocket
rsocket()

Return the underlying RSocket if the requester was created with a "live" RSocket via wrap(RSocket, MimeType, MimeType, RSocketStrategies) or via one of the (deprecated) connect methods on the RSocketRequester builder, or otherwise return null.

public RSocketClient
rsocketClient()

Return the underlying RSocketClient used to make requests with.

public RSocketStrategies
strategies()

Return the configured RSocketStrategies.

public static RSocketRequester
wrap(RSocket rsocket, MimeType dataMimeType, MimeType metadataMimeType, RSocketStrategies strategies)

Wrap an existing RSocket.

Method Detail

builderback to summary
public static RSocketRequester.Builder builder()

Obtain a builder to create a client RSocketRequester by connecting to an RSocket server.

dataMimeTypeback to summary
public MimeType dataMimeType()

Return the data MimeType selected for the underlying RSocket at connection time. On the client side this is configured via RSocketRequester.Builder#dataMimeType(MimeType) while on the server side it's obtained from the ConnectionSetupPayload.

disposeback to summary
public default void dispose()

Implements reactor.core.Disposable.dispose.

Shortcut method that delegates to the same on the underlying rsocketClient() in order to close the connection from the underlying transport and notify subscribers.

Annotations
@Override
Since
5.3.7
isDisposedback to summary
public default boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Shortcut method that delegates to the same on the underlying rsocketClient().

Returns:boolean

Doc from reactor.core.Disposable.isDisposed.

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
Since
5.3.7
metadataback to summary
public RSocketRequester.RequestSpec metadata(Object metadata, MimeType mimeType)

Begin to specify a new request with the given metadata value, which can be a concrete value or any producer of a single value that can be adapted to a Publisher via ReactiveAdapterRegistry.

Parameters
metadata:Object

the metadata value to encode

mimeType:MimeType

the mime type that describes the metadata; This is required for connection using composite metadata. Otherwise, the value is encoded according to the mime type for the connection and this argument may be left as null.

metadataMimeTypeback to summary
public MimeType metadataMimeType()

Return the metadata MimeType selected for the underlying RSocket at connection time. On the client side this is configured via RSocketRequester.Builder#metadataMimeType(MimeType) while on the server side it's obtained from the ConnectionSetupPayload.

routeback to summary
public RSocketRequester.RequestSpec route(String route, Object... routeVars)

Begin to specify a new request with the given route to a remote handler.

The route can be a template with placeholders, e.g. "flight.{code}" in which case the supplied route variables are formatted via toString() and expanded into the template. If a formatted variable contains a "." it is replaced with the escape sequence "%2E" to avoid treating it as separator by the responder.

If the connection is set to use composite metadata, the route is encoded as "message/x.rsocket.routing.v0". Otherwise, the route is encoded according to the mime type for the connection.

Parameters
route:String

the route expressing a remote handler mapping

routeVars:Object[]

variables to be expanded into the route template

Returns:RSocketRequester.RequestSpec

a spec for further defining and executing the request

rsocketback to summary
public RSocket rsocket()

Return the underlying RSocket if the requester was created with a "live" RSocket via wrap(RSocket, MimeType, MimeType, RSocketStrategies) or via one of the (deprecated) connect methods on the RSocketRequester builder, or otherwise return null.

Annotations
@Nullable
rsocketClientback to summary
public RSocketClient rsocketClient()

Return the underlying RSocketClient used to make requests with.

Since
5.3
strategiesback to summary
public RSocketStrategies strategies()

Return the configured RSocketStrategies.

wrapback to summary
public static RSocketRequester wrap(RSocket rsocket, MimeType dataMimeType, MimeType metadataMimeType, RSocketStrategies strategies)

Wrap an existing RSocket. Typically for internal framework use, to wrap the remote RSocket in a client or server responder, but it can also be used to wrap any RSocket.

org.springframework.messaging.rsocket back to summary

public Interface RSocketRequester.Builder

Known Direct Implementers
org.springframework.messaging.rsocket.DefaultRSocketRequesterBuilder

Builder to create a requester by connecting to a server.

Method Summary

Modifier and TypeMethod and Description
public RSocketRequester.Builder
apply(Consumer<RSocketRequester.Builder>
the configurer to apply
configurer
)

Configure this builder through a Consumer.

public Mono<RSocketRequester>

Returns:

an RSocketRequester for the connection
connect
(ClientTransport
the client transport to use
transport
)

Deprecated as of 5.3 in favor of transport(ClientTransport)
Connect to the server with the given ClientTransport.
public Mono<RSocketRequester>

Returns:

an RSocketRequester for the connection
connectTcp
(String
the server host
host
,
int
the server port
port
)

Deprecated as of 5.3 in favor of tcp(String, int)
Connect to the server over TCP.
public Mono<RSocketRequester>

Returns:

an RSocketRequester for the connection
connectWebSocket
(URI
the RSocket server endpoint URI
uri
)

Deprecated as of 5.3 in favor of websocket(URI)
Connect to the server over WebSocket.
public RSocketRequester.Builder
dataMimeType(MimeType mimeType)

Configure the payload data MimeType to specify on the SETUP frame that applies to the whole connection.

public RSocketRequester.Builder
metadataMimeType(MimeType mimeType)

Configure the payload metadata MimeType to specify on the SETUP frame that applies to the whole connection.

public RSocketRequester.Builder
rsocketConnector(RSocketConnectorConfigurer configurer)

Callback to configure the RSocketConnector directly.

public RSocketRequester.Builder
rsocketStrategies(RSocketStrategies
the strategies to use
strategies
)

Provide the RSocketStrategies to use.

public RSocketRequester.Builder
public RSocketRequester.Builder
setupData(Object data)

Set the data for the setup payload.

public RSocketRequester.Builder
setupMetadata(Object value, MimeType mimeType)

Add metadata entry to the setup payload.

public RSocketRequester.Builder
setupRoute(String route, Object... routeVars)

Set the route for the setup payload.

public RSocketRequester

Returns:

the created RSocketRequester
tcp
(String
the host to connect to
host
,
int
the port to connect to
port
)

Build an RSocketRequester with an io.rsocket.core.RSocketClient that connects over TCP to the given host and port.

public RSocketRequester

Returns:

the created RSocketRequester
transport
(ClientTransport
the transport to connect with
transport
)

Variant of tcp(String, int) and websocket(URI) with an already initialized ClientTransport.

public RSocketRequester

Returns:

the created RSocketRequester
transports
(Publisher<List<LoadbalanceTarget>>
a Publisher that supplies a list of target transports to loadbalance against; the given list may be periodically updated by the Publisher.
targetPublisher
,
LoadbalanceStrategy
the strategy to use for selecting from the list of loadbalance targets.
loadbalanceStrategy
)

Build an RSocketRequester with an io.rsocket.loadbalance.LoadbalanceRSocketClient that will connect to one of the given targets selected through the given io.rsocket.loadbalance.LoadbalanceRSocketClient.

public RSocketRequester

Returns:

the created RSocketRequester
websocket
(URI
the URL to connect to
uri
)

Build an RSocketRequester with an io.rsocket.core.RSocketClient that connects over WebSocket to the given URL.

Method Detail

applyback to summary
public RSocketRequester.Builder apply(Consumer<RSocketRequester.Builder> configurer)

Configure this builder through a Consumer. This enables libraries such as Spring Security to provide shortcuts for applying a set of related customizations.

Parameters
configurer:Consumer<RSocketRequester.Builder>

the configurer to apply

connectback to summary
public Mono<RSocketRequester> connect(ClientTransport transport)

Deprecated

as of 5.3 in favor of transport(ClientTransport)

Connect to the server with the given ClientTransport.

Parameters
transport:ClientTransport

the client transport to use

Returns:Mono<RSocketRequester>

an RSocketRequester for the connection

Annotations
@Deprecated
connectTcpback to summary
public Mono<RSocketRequester> connectTcp(String host, int port)

Deprecated

as of 5.3 in favor of tcp(String, int)

Connect to the server over TCP.

Parameters
host:String

the server host

port:int

the server port

Returns:Mono<RSocketRequester>

an RSocketRequester for the connection

Annotations
@Deprecated
See Also
TcpClientTransport
connectWebSocketback to summary
public Mono<RSocketRequester> connectWebSocket(URI uri)

Deprecated

as of 5.3 in favor of websocket(URI)

Connect to the server over WebSocket.

Parameters
uri:URI

the RSocket server endpoint URI

Returns:Mono<RSocketRequester>

an RSocketRequester for the connection

Annotations
@Deprecated
See Also
WebsocketClientTransport
dataMimeTypeback to summary
public RSocketRequester.Builder dataMimeType(MimeType mimeType)

Configure the payload data MimeType to specify on the SETUP frame that applies to the whole connection.

If not set, this will be initialized to the MimeType of the first non-default Decoder, or otherwise the MimeType of the first decoder.

metadataMimeTypeback to summary
public RSocketRequester.Builder metadataMimeType(MimeType mimeType)

Configure the payload metadata MimeType to specify on the SETUP frame that applies to the whole connection.

By default this is set to "message/x.rsocket.composite-metadata.v0" in which case the route, if provided, is encoded as a "message/x.rsocket.routing.v0" composite metadata entry. If this is set to any other MimeType, it is assumed that's the MimeType for the route, if provided.

rsocketConnectorback to summary
public RSocketRequester.Builder rsocketConnector(RSocketConnectorConfigurer configurer)

Callback to configure the RSocketConnector directly.

Since
5.2.6
rsocketStrategiesback to summary
public RSocketRequester.Builder rsocketStrategies(RSocketStrategies strategies)

Provide the RSocketStrategies to use.

This is useful for changing the default settings, yet still allowing further customizations via rsocketStrategies(Consumer). If not set, defaults are obtained from RSocketStrategies#builder().

Parameters
strategies:RSocketStrategies

the strategies to use

rsocketStrategiesback to summary
public RSocketRequester.Builder rsocketStrategies(Consumer<RSocketStrategies.Builder> configurer)

Customize the RSocketStrategies.

Allows further customization on RSocketStrategies, mutating them if they were set, or starting from RSocketStrategies#builder() defaults}.

setupDataback to summary
public RSocketRequester.Builder setupData(Object data)

Set the data for the setup payload. The data will be encoded according to the configured dataMimeType(MimeType). The data be a concrete value or any producer of a single value that can be adapted to a Publisher via ReactiveAdapterRegistry.

By default this is not set.

setupMetadataback to summary
public RSocketRequester.Builder setupMetadata(Object value, MimeType mimeType)

Add metadata entry to the setup payload. Composite metadata must be in use if this is called more than once or in addition to setupRoute(String, Object...). The metadata value be a concrete value or any producer of a single value that can be adapted to a Publisher via ReactiveAdapterRegistry.

setupRouteback to summary
public RSocketRequester.Builder setupRoute(String route, Object... routeVars)

Set the route for the setup payload. The rules for formatting and encoding the route are the same as those for a request route as described in route(String, Object...).

By default this is not set.

tcpback to summary
public RSocketRequester tcp(String host, int port)

Build an RSocketRequester with an io.rsocket.core.RSocketClient that connects over TCP to the given host and port. The requester can be used to make requests concurrently. Requests are made over a shared connection that is also re-established as needed when further requests are made.

Parameters
host:String

the host to connect to

port:int

the port to connect to

Returns:RSocketRequester

the created RSocketRequester

Since
5.3
transportback to summary
public RSocketRequester transport(ClientTransport transport)

Variant of tcp(String, int) and websocket(URI) with an already initialized ClientTransport.

Parameters
transport:ClientTransport

the transport to connect with

Returns:RSocketRequester

the created RSocketRequester

Since
5.3
transportsback to summary
public RSocketRequester transports(Publisher<List<LoadbalanceTarget>> targetPublisher, LoadbalanceStrategy loadbalanceStrategy)

Build an RSocketRequester with an io.rsocket.loadbalance.LoadbalanceRSocketClient that will connect to one of the given targets selected through the given io.rsocket.loadbalance.LoadbalanceRSocketClient.

Parameters
targetPublisher:Publisher<List<LoadbalanceTarget>>

a Publisher that supplies a list of target transports to loadbalance against; the given list may be periodically updated by the Publisher.

loadbalanceStrategy:LoadbalanceStrategy

the strategy to use for selecting from the list of loadbalance targets.

Returns:RSocketRequester

the created RSocketRequester

Since
5.3
websocketback to summary
public RSocketRequester websocket(URI uri)

Build an RSocketRequester with an io.rsocket.core.RSocketClient that connects over WebSocket to the given URL. The requester can be used to make requests concurrently. Requests are made over a shared connection that is also re-established as needed when further requests are made.

Parameters
uri:URI

the URL to connect to

Returns:RSocketRequester

the created RSocketRequester

Since
5.3
org.springframework.messaging.rsocket back to summary

public Interface RSocketRequester.MetadataSpec<S extends RSocketRequester.MetadataSpec<S>>

Known Direct Subinterfaces
org.springframework.messaging.rsocket.RSocketRequester.RequestSpec
Type Parameters
<S>
a self reference to the spec type

Spec for providing additional composite metadata entries.

Method Summary

Modifier and TypeMethod and Description
public S
metadata(Object
an Object to be encoded with a suitable Encoder, or a DataBuffer
metadata
,
MimeType
the mime type that describes the metadata
mimeType
)

Use this to append additional metadata entries when using composite metadata.

Method Detail

metadataback to summary
public S metadata(Object metadata, MimeType mimeType)

Use this to append additional metadata entries when using composite metadata. An IllegalArgumentException is raised if this method is used when not using composite metadata. The metadata value be a concrete value or any producer of a single value that can be adapted to a Publisher via ReactiveAdapterRegistry.

Parameters
metadata:Object

an Object to be encoded with a suitable Encoder, or a DataBuffer

mimeType:MimeType

the mime type that describes the metadata

org.springframework.messaging.rsocket back to summary

public Interface RSocketRequester.RequestSpec

extends RSocketRequester.MetadataSpec<RSocketRequester.RequestSpec>, RetrieveSpec
Known Direct Implementers
org.springframework.messaging.rsocket.DefaultRSocketRequester.DefaultRequestSpec

Spec to declare the input for an RSocket request.

Method Summary

Modifier and TypeMethod and Description
public RSocketRequester.RetrieveSpec

Returns:

spec to declare the expected response
data
(Object
the Object value for the payload data
data
)

Provide payload data for the request.

public RSocketRequester.RetrieveSpec

Returns:

spec to declare the expected response
data
(Object
the source of payload data value(s). This must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry
producer
,
Class<?>
the type of values to be produced
elementClass
)

Variant of data(Object) that also accepts a hint for the types of values that will be produced.

public RSocketRequester.RetrieveSpec

Returns:

spec to declare the expected response
data
(Object
the source of payload data value(s). This must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry
producer
,
ParameterizedTypeReference<?>
the type of values to be produced
elementTypeRef
)

Variant of data(Object, Class) for when the type hint has to have a generic type.

public RSocketRequester.RequestSpec
metadata(Consumer<RSocketRequester.MetadataSpec<?>>
the configurer to apply
configurer
)

Append additional metadata entries through a Consumer.

public Mono<Void>
Inherited from org.springframework.messaging.rsocket.RSocketRequester.MetadataSpec:
metadata
Inherited from org.springframework.messaging.rsocket.RSocketRequester.RetrieveSpec:
retrieveFluxretrieveFluxretrieveMonoretrieveMonosend

Method Detail

databack to summary
public RSocketRequester.RetrieveSpec data(Object data)

Provide payload data for the request. This can be one of:

Parameters
data:Object

the Object value for the payload data

Returns:RSocketRequester.RetrieveSpec

spec to declare the expected response

databack to summary
public RSocketRequester.RetrieveSpec data(Object producer, Class<?> elementClass)

Variant of data(Object) that also accepts a hint for the types of values that will be produced. The class hint is used to find a compatible Encoder once, up front vs per value.

Parameters
producer:Object

the source of payload data value(s). This must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry

elementClass:Class<?>

the type of values to be produced

Returns:RSocketRequester.RetrieveSpec

spec to declare the expected response

databack to summary
public RSocketRequester.RetrieveSpec data(Object producer, ParameterizedTypeReference<?> elementTypeRef)

Variant of data(Object, Class) for when the type hint has to have a generic type. See ParameterizedTypeReference.

Parameters
producer:Object

the source of payload data value(s). This must be a Publisher or another producer adaptable to a Publisher via ReactiveAdapterRegistry

elementTypeRef:ParameterizedTypeReference<?>

the type of values to be produced

Returns:RSocketRequester.RetrieveSpec

spec to declare the expected response

metadataback to summary
public RSocketRequester.RequestSpec metadata(Consumer<RSocketRequester.MetadataSpec<?>> configurer)

Append additional metadata entries through a Consumer. This enables libraries such as Spring Security to provide shortcuts for applying a set of customizations.

Parameters
configurer:Consumer<RSocketRequester.MetadataSpec<?>>

the configurer to apply

Exceptions
IllegalArgumentException:
if not using composite metadata.
sendMetadataback to summary
public Mono<Void> sendMetadata()

Perform a metadataPush.

Since
5.3
org.springframework.messaging.rsocket back to summary

public Interface RSocketRequester.RetrieveSpec

Known Direct Subinterfaces
org.springframework.messaging.rsocket.RSocketRequester.RequestSpec

Spec to declare the expected output for an RSocket request.
Since
5.2.2

Method Summary

Modifier and TypeMethod and Description
public <
parameterize the expected type of values
T
>
Flux<T>

Returns:

the decoded response
retrieveFlux
(Class<T>
the expected type for values in the response
dataType
)

Perform an requestStream or a requestChannel exchange depending on whether the request input is single or multi-payload.

public <T> Flux<T>
retrieveFlux(ParameterizedTypeReference<T> dataTypeRef)

Variant of retrieveFlux(Class) for when the dataType has to have a generic type.

public <
parameter for the expected data type
T
>
Mono<T>

Returns:

the decoded response
retrieveMono
(Class<T>
the expected data type for the response
dataType
)

Perform a requestResponse exchange.

public <T> Mono<T>
retrieveMono(ParameterizedTypeReference<T> dataTypeRef)

Variant of retrieveMono(Class) for when the dataType has to have a generic type.

public Mono<Void>

Returns:

a completion that indicates if the payload was sent successfully or not. Note, however that is a one-way send and there is no indication of whether or how the even was handled on the remote end.
send
()

Perform a fireAndForget sending the provided data and metadata.

Method Detail

retrieveFluxback to summary
public <T> Flux<T> retrieveFlux(Class<T> dataType)

Perform an requestStream or a requestChannel exchange depending on whether the request input is single or multi-payload.

If the return type is Flux<Void>, the Flux will complete after all data is consumed.

Parameters
<T>
parameterize the expected type of values
dataType:Class<T>

the expected type for values in the response

Returns:Flux<T>

the decoded response

retrieveFluxback to summary
public <T> Flux<T> retrieveFlux(ParameterizedTypeReference<T> dataTypeRef)

Variant of retrieveFlux(Class) for when the dataType has to have a generic type. See ParameterizedTypeReference.

retrieveMonoback to summary
public <T> Mono<T> retrieveMono(Class<T> dataType)

Perform a requestResponse exchange.

If the return type is Mono<Void>, the Mono will complete after all data is consumed.

Note

This method will raise an error if the request payload is a multivalued Publisher as there is no many-to-one RSocket interaction.

Parameters
<T>
parameter for the expected data type
dataType:Class<T>

the expected data type for the response

Returns:Mono<T>

the decoded response

retrieveMonoback to summary
public <T> Mono<T> retrieveMono(ParameterizedTypeReference<T> dataTypeRef)

Variant of retrieveMono(Class) for when the dataType has to have a generic type. See ParameterizedTypeReference.

sendback to summary
public Mono<Void> send()

Perform a fireAndForget sending the provided data and metadata.

Returns:Mono<Void>

a completion that indicates if the payload was sent successfully or not. Note, however that is a one-way send and there is no indication of whether or how the even was handled on the remote end.