public class Reactor2TcpClient<P> extends Object implements TcpOperations<P>
TcpOperations
based on the TCP client support of the Reactor project.
This implementation wraps N (Reactor) clients for N connect(org.springframework.messaging.tcp.TcpConnectionHandler<P>)
calls,
i.e. a separate (Reactor) client instance for each connection.
Modifier and Type | Field and Description |
---|---|
static Class<reactor.io.net.impl.netty.tcp.NettyTcpClient> |
REACTOR_TCP_CLIENT_TYPE |
Constructor and Description |
---|
Reactor2TcpClient(reactor.io.net.NetStreams.TcpClientFactory<Message<P>,Message<P>> tcpClientSpecFactory)
A constructor with a pre-configured
Spec.TcpClientSpec Function
factory. |
Reactor2TcpClient(String host,
int port,
reactor.io.codec.Codec<reactor.io.buffer.Buffer,Message<P>,Message<P>> codec)
A constructor that creates a
TcpClientSpec factory
with a default SynchronousDispatcher , i.e. |
Modifier and Type | Method and Description |
---|---|
ListenableFuture<Void> |
connect(TcpConnectionHandler<P> connectionHandler)
Open a new connection.
|
ListenableFuture<Void> |
connect(TcpConnectionHandler<P> connectionHandler,
ReconnectStrategy strategy)
Open a new connection and a strategy for reconnecting if the connection fails.
|
ListenableFuture<Void> |
shutdown()
Shut down and close any open connections.
|
public static final Class<reactor.io.net.impl.netty.tcp.NettyTcpClient> REACTOR_TCP_CLIENT_TYPE
public Reactor2TcpClient(String host, int port, reactor.io.codec.Codec<reactor.io.buffer.Buffer,Message<P>,Message<P>> codec)
TcpClientSpec
factory
with a default SynchronousDispatcher
, i.e.
relying on Netty threads. The number of Netty threads can be tweaked with
the reactor.tcp.ioThreadCount
System property. The network I/O
threads will be shared amongst the active clients.
Also see the constructor accepting a ready Reactor
Spec.TcpClientSpec
Function
factory.
host
- the host to connect toport
- the port to connect tocodec
- the codec to use for encoding and decoding the TCP streampublic Reactor2TcpClient(reactor.io.net.NetStreams.TcpClientFactory<Message<P>,Message<P>> tcpClientSpecFactory)
Spec.TcpClientSpec
Function
factory. This might be used to add SSL or specific network parameters to
the generated client configuration.
NOTE: if the client is configured with a thread-creating
dispatcher, you are responsible for cleaning them, e.g. using
Resource.shutdown()
.
tcpClientSpecFactory
- the TcpClientSpec Function
to use for each client creationpublic ListenableFuture<Void> connect(TcpConnectionHandler<P> connectionHandler)
TcpOperations
connect
in interface TcpOperations<P>
connectionHandler
- a handler to manage the connectionpublic ListenableFuture<Void> connect(TcpConnectionHandler<P> connectionHandler, ReconnectStrategy strategy)
TcpOperations
connect
in interface TcpOperations<P>
connectionHandler
- a handler to manage the connectionstrategy
- a strategy for reconnectingpublic ListenableFuture<Void> shutdown()
TcpOperations
shutdown
in interface TcpOperations<P>