Class Reactor2TcpClient<P>
- java.lang.Object
- org.springframework.messaging.tcp.reactor.Reactor2TcpClient<P>
- All Implemented Interfaces:
TcpOperations<P>
public class Reactor2TcpClient<P> extends Object implements TcpOperations<P>
An implementation ofTcpOperations
based on the TCP client support of project Reactor.This implementation wraps N Reactor
TcpClient
instances created for Nconnect(org.springframework.messaging.tcp.TcpConnectionHandler<P>)
calls, i.e. once instance per connection.- Since:
- 4.2
- Author:
- Rossen Stoyanchev, Stephane Maldini
Field Summary
Fields Modifier and Type Field Description static Class<reactor.io.net.impl.netty.tcp.NettyTcpClient>
REACTOR_TCP_CLIENT_TYPE
Constructor Summary
Constructors Constructor Description Reactor2TcpClient(String host, int port, reactor.io.codec.Codec<reactor.io.buffer.Buffer,Message<P>,Message<P>> codec)
A constructor that creates aTcpClientSpec
factory with a defaultSynchronousDispatcher
, i.e.Reactor2TcpClient(reactor.fn.Supplier<InetSocketAddress> addressSupplier, reactor.io.codec.Codec<reactor.io.buffer.Buffer,Message<P>,Message<P>> codec)
A variant ofReactor2TcpClient(String, int, Codec)
that takes a supplier of any number of addresses instead of just one host and port.Reactor2TcpClient(reactor.io.net.NetStreams.TcpClientFactory<Message<P>,Message<P>> tcpClientSpecFactory)
A constructor with a pre-configuredSpec.TcpClientSpec
Function
factory.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.static io.netty.channel.nio.NioEventLoopGroup
initEventLoopGroup()
ListenableFuture<Void>
shutdown()
Shut down and close any open connections.
Field Detail
REACTOR_TCP_CLIENT_TYPE
public static final Class<reactor.io.net.impl.netty.tcp.NettyTcpClient> REACTOR_TCP_CLIENT_TYPE
Constructor Detail
Reactor2TcpClient
public Reactor2TcpClient(String host, int port, reactor.io.codec.Codec<reactor.io.buffer.Buffer,Message<P>,Message<P>> codec)
A constructor that creates aTcpClientSpec
factory with a defaultSynchronousDispatcher
, i.e. relying on Netty threads. The number of Netty threads can be tweaked with thereactor.tcp.ioThreadCount
System property. The network I/O threads will be shared amongst the active clients.- Parameters:
host
- the host to connect toport
- the port to connect tocodec
- the codec to use for encoding and decoding the TCP stream
Reactor2TcpClient
public Reactor2TcpClient(reactor.fn.Supplier<InetSocketAddress> addressSupplier, reactor.io.codec.Codec<reactor.io.buffer.Buffer,Message<P>,Message<P>> codec)
A variant ofReactor2TcpClient(String, int, Codec)
that takes a supplier of any number of addresses instead of just one host and port. This can be used toreconnect
to a different address after the current host becomes unavailable.- Parameters:
addressSupplier
- supplier of addresses to use for connectingcodec
- the codec to use for encoding and decoding the TCP stream- Since:
- 4.3.15
Reactor2TcpClient
public Reactor2TcpClient(reactor.io.net.NetStreams.TcpClientFactory<Message<P>,Message<P>> tcpClientSpecFactory)
A constructor with a pre-configuredSpec.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()
.- Parameters:
tcpClientSpecFactory
- the TcpClientSpecFunction
to use for each client creation
Method Detail
initEventLoopGroup
public static io.netty.channel.nio.NioEventLoopGroup initEventLoopGroup()
connect
public ListenableFuture<Void> connect(TcpConnectionHandler<P> connectionHandler)
Description copied from interface:TcpOperations
Open a new connection.- Specified by:
connect
in interfaceTcpOperations<P>
- Parameters:
connectionHandler
- a handler to manage the connection- Returns:
- a ListenableFuture that can be used to determine when and if the connection is successfully established
connect
public ListenableFuture<Void> connect(TcpConnectionHandler<P> connectionHandler, ReconnectStrategy strategy)
Description copied from interface:TcpOperations
Open a new connection and a strategy for reconnecting if the connection fails.- Specified by:
connect
in interfaceTcpOperations<P>
- Parameters:
connectionHandler
- a handler to manage the connectionstrategy
- a strategy for reconnecting- Returns:
- a ListenableFuture that can be used to determine when and if the initial connection is successfully established
shutdown
public ListenableFuture<Void> shutdown()
Description copied from interface:TcpOperations
Shut down and close any open connections.- Specified by:
shutdown
in interfaceTcpOperations<P>
- Returns:
- a ListenableFuture that can be used to determine when and if the connection is successfully closed