public final class RSocketServer extends Object
For example:
CloseableChannel closeable =
RSocketServer.create(SocketAcceptor.with(new RSocket() {...}))
.bind(TcpServerTransport.create("localhost", 7000))
.block();
Modifier and Type | Method and Description |
---|---|
RSocketServer |
acceptor(SocketAcceptor acceptor)
Set the acceptor to handle incoming connections and handle requests.
|
ServerTransport.ConnectionAcceptor |
asConnectionAcceptor()
An alternative to
bind(ServerTransport) that is useful for installing RSocket on a
server that is started independently. |
ServerTransport.ConnectionAcceptor |
asConnectionAcceptor(int maxFrameLength)
An alternative to
bind(ServerTransport) that is useful for installing RSocket on a
server that is started independently. |
<T extends Closeable> |
bind(ServerTransport<T> transport)
Start the server on the given transport.
|
<T extends Closeable> |
bindNow(ServerTransport<T> transport)
Start the server on the given transport.
|
static RSocketServer |
create()
Static factory method to create an
RSocketServer . |
static RSocketServer |
create(SocketAcceptor acceptor)
Static factory method to create an
RSocketServer instance with the given SocketAcceptor . |
RSocketServer |
fragment(int mtu)
When this is set, frames larger than the given maximum transmission unit (mtu) size value are
fragmented.
|
RSocketServer |
interceptors(Consumer<InterceptorRegistry> configurer)
Configure interception at one of the following levels:
Transport level
At the level of accepting new connections
Performing requests
Responding to requests
|
RSocketServer |
lease(Consumer<LeaseSpec> leaseConfigurer)
Enables the Lease feature of the RSocket protocol where the number of requests that can be
performed from either side are rationed via
LEASE frames from the responder side. |
RSocketServer |
maxInboundPayloadSize(int maxInboundPayloadSize)
When this is set, frames reassembler control maximum payload size which can be reassembled.
|
RSocketServer |
payloadDecoder(PayloadDecoder decoder)
Configure the
PayloadDecoder used to create Payload 's from incoming raw frame
buffers. |
RSocketServer |
resume(Resume resume)
Enables the Resume capability of the RSocket protocol where if the client gets disconnected,
the connection is re-acquired and any interrupted streams are transparently resumed.
|
public static RSocketServer create()
RSocketServer
.public static RSocketServer create(SocketAcceptor acceptor)
RSocketServer
instance with the given SocketAcceptor
. Effectively a shortcut for:
RSocketServer.create().acceptor(...);
acceptor
- the acceptor to handle connections withacceptor(SocketAcceptor)
public RSocketServer acceptor(SocketAcceptor acceptor)
An example with access to the SETUP
frame and sending RSocket for performing
requests back to the client if needed:
RSocketServer.create((setup, sendingRSocket) -> Mono.just(new RSocket() {...}))
.bind(TcpServerTransport.create("localhost", 7000))
.subscribe();
A shortcut to provide the handling RSocket only:
RSocketServer.create(SocketAcceptor.with(new RSocket() {...}))
.bind(TcpServerTransport.create("localhost", 7000))
.subscribe();
A shortcut to handle request-response interactions only:
RSocketServer.create(SocketAcceptor.forRequestResponse(payload -> ...))
.bind(TcpServerTransport.create("localhost", 7000))
.subscribe();
By default, new RSocket(){}
is used for handling which rejects requests from the
client with UnsupportedOperationException
.
acceptor
- the acceptor to handle incoming connections and requests withpublic RSocketServer interceptors(Consumer<InterceptorRegistry> configurer)
configurer
- a configurer to customize interception with.LimitRateInterceptor
public RSocketServer resume(Resume resume)
Use the Resume
argument to customize the Resume session duration, storage, retry
logic, and others.
By default this is not enabled.
resume
- configuration for the Resume capabilitypublic RSocketServer lease(Consumer<LeaseSpec> leaseConfigurer)
LEASE
frames from the responder side. For
this to work clients must also support and request to enable this when connecting.
Example usage:
RSocketServer.create(SocketAcceptor.with(new RSocket() {...}))
.lease(spec ->
spec.sender(() -> Flux.interval(ofSeconds(1))
.map(__ -> Lease.create(ofSeconds(1), 1)))
)
.bind(TcpServerTransport.create("localhost", 7000))
.subscribe();
By default this is not enabled.
leaseConfigurer
- consumer which accepts LeaseSpec
and use it for configuringpublic RSocketServer maxInboundPayloadSize(int maxInboundPayloadSize)
By default this is not set in which case maximum reassembled payloads size is not controlled.
maxInboundPayloadSize
- the threshold size for reassembly, must no be less than 64 bytes.
Please note, maxInboundPayloadSize
must always be greater or equal to Transport.maxFrameLength()
, otherwise inbound frame can exceed the
maxInboundPayloadSize
public RSocketServer fragment(int mtu)
By default this is not set in which case payloads are sent whole up to the maximum frame size of 16,777,215 bytes.
mtu
- the threshold size for fragmentation, must be no less than 64public RSocketServer payloadDecoder(PayloadDecoder decoder)
PayloadDecoder
used to create Payload
's from incoming raw frame
buffers. The following decoders are available:
PayloadDecoder.DEFAULT
-- the data and metadata are independent copies of the
underlying frame ByteBuf
PayloadDecoder.ZERO_COPY
-- the data and metadata are retained slices of the
underlying ByteBuf
. That's more efficient but requires careful tracking and
release
of the payload when no longer needed.
By default this is set to PayloadDecoder.DEFAULT
in which case data and metadata are
copied and do not need to be tracked and released.
decoder
- the decoder to usepublic <T extends Closeable> Mono<T> bind(ServerTransport<T> transport)
The following transports are available from additional RSocket Java modules:
TcpServerTransport
via
rsocket-transport-netty
.
WebsocketServerTransport
via rsocket-transport-netty
.
LocalServerTransport
via rsocket-transport-local
T
- the type of Closeable
for the given transporttransport
- the transport of choice to connect withMono
with a Closeable
that can be used to obtain information about
the server, stop it, or be notified of when it is stopped.public <T extends Closeable> T bindNow(ServerTransport<T> transport)
.bind(ServerTransport).block()
public ServerTransport.ConnectionAcceptor asConnectionAcceptor()
bind(ServerTransport)
that is useful for installing RSocket on a
server that is started independently.io.rsocket.examples.transport.ws.WebSocketHeadersSample
public ServerTransport.ConnectionAcceptor asConnectionAcceptor(int maxFrameLength)
bind(ServerTransport)
that is useful for installing RSocket on a
server that is started independently.io.rsocket.examples.transport.ws.WebSocketHeadersSample