public class Reactor2TcpClient<P> extends java.lang.Object implements TcpOperations<P>
TcpOperations
based on the TCP client support of project Reactor.
This implementation wraps N Reactor TcpClient instances created
for N connect(org.springframework.messaging.tcp.TcpConnectionHandler<P>) calls, i.e. once instance per connection.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.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(java.lang.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. |
Reactor2TcpClient(reactor.fn.Supplier<java.net.InetSocketAddress> addressSupplier,
reactor.io.codec.Codec<reactor.io.buffer.Buffer,Message<P>,Message<P>> codec)
A variant of
Reactor2TcpClient(String, int, Codec) that takes a
supplier of any number of addresses instead of just one host and port. |
| Modifier and Type | Method and Description |
|---|---|
ListenableFuture<java.lang.Void> |
connect(TcpConnectionHandler<P> connectionHandler)
Open a new connection.
|
ListenableFuture<java.lang.Void> |
connect(TcpConnectionHandler<P> connectionHandler,
ReconnectStrategy strategy)
Open a new connection and a strategy for reconnecting if the connection fails.
|
static io.netty.channel.nio.NioEventLoopGroup |
initEventLoopGroup() |
ListenableFuture<java.lang.Void> |
shutdown()
Shut down and close any open connections.
|
public static final java.lang.Class<reactor.io.net.impl.netty.tcp.NettyTcpClient> REACTOR_TCP_CLIENT_TYPE
public Reactor2TcpClient(java.lang.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.host - the host to connect toport - the port to connect tocodec - the codec to use for encoding and decoding the TCP streampublic Reactor2TcpClient(reactor.fn.Supplier<java.net.InetSocketAddress> addressSupplier,
reactor.io.codec.Codec<reactor.io.buffer.Buffer,Message<P>,Message<P>> codec)
Reactor2TcpClient(String, int, Codec) that takes a
supplier of any number of addresses instead of just one host and port.
This can be used to reconnect to a different address after the current host becomes unavailable.addressSupplier - supplier of addresses to use for connectingcodec - 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. via
Resource.shutdown().
tcpClientSpecFactory - the TcpClientSpec Function to use for
each client creationpublic static io.netty.channel.nio.NioEventLoopGroup initEventLoopGroup()
public ListenableFuture<java.lang.Void> connect(TcpConnectionHandler<P> connectionHandler)
TcpOperationsconnect in interface TcpOperations<P>connectionHandler - a handler to manage the connectionpublic ListenableFuture<java.lang.Void> connect(TcpConnectionHandler<P> connectionHandler, ReconnectStrategy strategy)
TcpOperationsconnect in interface TcpOperations<P>connectionHandler - a handler to manage the connectionstrategy - a strategy for reconnectingpublic ListenableFuture<java.lang.Void> shutdown()
TcpOperationsshutdown in interface TcpOperations<P>