public abstract class TcpClient extends ClientTransport<TcpClient,TcpClientConfig>
connect() is ultimately called.
Example:
TcpClient.create()
.doOnConnect(connectMetrics)
.doOnConnected(connectedMetrics)
.doOnDisconnected(disconnectedMetrics)
.host("127.0.0.1")
.port(1234)
.secure()
.connect()
.block()
| Constructor and Description |
|---|
TcpClient() |
| Modifier and Type | Method and Description |
|---|---|
TcpClient |
addressSupplier(Supplier<? extends SocketAddress> connectAddressSupplier)
Deprecated.
Use
remoteAddress(Supplier). This method will be removed in version 1.1.0. |
<A> TcpClient |
attr(AttributeKey<A> key,
A value)
Update the given attribute key or remove it if the value is null.
|
TcpClient |
bindAddress(Supplier<? extends SocketAddress> bindAddressSupplier)
Set a new local address to which this transport should bind on subscribe.
|
TcpClient |
bootstrap(Function<? super Bootstrap,? extends Bootstrap> bootstrapMapper)
Deprecated.
as of 0.9.10. Use the other methods exposed by
TcpClient to achieve the same configurations.
The method will be removed in version 1.1.0. |
Mono<? extends Connection> |
connect()
|
Connection |
connectNow()
Block the
ClientTransport and return a Connection. |
Connection |
connectNow(Duration timeout)
Block the
ClientTransport and return a Connection. |
static TcpClient |
create()
Prepare a pooled
TcpClient |
static TcpClient |
create(ConnectionProvider provider)
Prepare a
TcpClient |
TcpClient |
doOnConnect(Consumer<? super TcpClientConfig> doOnConnect)
Set or add a callback called when
ClientTransport is about to connect to the remote endpoint. |
TcpClient |
doOnConnected(Consumer<? super Connection> doOnConnected)
Set or add a callback called after
Connection has been connected. |
TcpClient |
doOnDisconnected(Consumer<? super Connection> doOnDisconnected)
Set or add a callback called after
Connection has been disconnected. |
TcpClient |
handle(BiFunction<? super NettyInbound,? super NettyOutbound,? extends Publisher<Void>> handler)
Attach an IO handler to react on connected client
|
TcpClient |
host(String host)
The host to which this client should connect.
|
TcpClient |
metrics(boolean enable)
Whether to enable metrics to be collected and registered in Micrometer's
globalRegistry. |
TcpClient |
metrics(boolean enable,
Supplier<? extends ChannelMetricsRecorder> recorder)
Specifies whether the metrics are enabled on the
Transport. |
static TcpClient |
newConnection()
Prepare a non pooled
TcpClient |
TcpClient |
noProxy()
Remove any previously applied Proxy configuration customization
|
TcpClient |
noSSL()
Remove any previously applied SSL configuration customization
|
TcpClient |
observe(ConnectionObserver observer)
Set or add the given
ConnectionObserver to observe the connection state changes. |
<O> TcpClient |
option(ChannelOption<O> key,
O value)
Update the given option key or remove it if the value is null.
|
TcpClient |
port(int port)
The port to which this client should connect.
|
TcpClient |
proxy(Consumer<? super ProxyProvider.TypeSpec> proxyOptions)
Apply a proxy configuration
|
TcpClient |
remoteAddress(Supplier<? extends SocketAddress> remoteAddressSupplier)
The address to which this client should connect on each subscribe.
|
TcpClient |
resolver(AddressResolverGroup<?> resolver)
Assign an
AddressResolverGroup. |
TcpClient |
runOn(EventLoopGroup eventLoopGroup)
Run IO loops on the given
EventLoopGroup. |
TcpClient |
runOn(LoopResources channelResources)
Run IO loops on a supplied
EventLoopGroup from the LoopResources container. |
TcpClient |
runOn(LoopResources loopResources,
boolean preferNative)
Run IO loops on a supplied
EventLoopGroup from the LoopResources container. |
TcpClient |
secure()
Enable default sslContext support.
|
TcpClient |
secure(Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder)
Apply an SSL configuration customization via the passed builder.
|
TcpClient |
secure(SslProvider sslProvider)
Apply an SSL configuration via the passed
SslProvider. |
Mono<Void> |
warmup()
Based on the actual configuration, returns a
Mono that triggers:
an initialization of the event loop group
an initialization of the host name resolver
loads the necessary native libraries for the transport
loads the necessary native libraries for the security if there is such
By default, when method is not used, the connect operation absorbs the extra time needed to load resources. |
TcpClient |
wiretap(boolean enable)
Apply or remove a wire logger configuration using
Transport category (logger),
DEBUG logger level and AdvancedByteBufFormat.HEX_DUMP for ByteBuf format,
which means both events and content will be logged and the content will be in hex format. |
TcpClient |
wiretap(String category)
Apply a wire logger configuration using the specified category (logger),
DEBUG logger level and AdvancedByteBufFormat.HEX_DUMP for ByteBuf format,
which means both events and content will be logged and the content will be in hex format. |
TcpClient |
wiretap(String category,
LogLevel level)
Apply a wire logger configuration using the specified category (logger),
logger level and
AdvancedByteBufFormat.HEX_DUMP for ByteBuf format,
which means both events and content will be logged and the content will be in hex format. |
doAfterResolve, doOnResolve, doOnResolveError, proxyWithSystemProperties, resolverchannelGroup, configuration, doOnChannelInit, duplicate, wiretap, wiretappublic static TcpClient create(ConnectionProvider provider)
TcpClientprovider - a ConnectionProvider to acquire connectionsTcpClientpublic static TcpClient newConnection()
TcpClientTcpClient@Deprecated public final TcpClient addressSupplier(Supplier<? extends SocketAddress> connectAddressSupplier)
remoteAddress(Supplier). This method will be removed in version 1.1.0.connectAddressSupplier - A supplier of the address to connect to.TcpClientpublic <A> TcpClient attr(AttributeKey<A> key, @Nullable A value)
Transportattr in class Transport<TcpClient,TcpClientConfig>A - the attribute typekey - the AttributeKey keyvalue - the AttributeKey valueTransport referencepublic TcpClient bindAddress(Supplier<? extends SocketAddress> bindAddressSupplier)
TransportbindAddress in class Transport<TcpClient,TcpClientConfig>bindAddressSupplier - A supplier of the address to bind to.Transport@Deprecated public final TcpClient bootstrap(Function<? super Bootstrap,? extends Bootstrap> bootstrapMapper)
TcpClient to achieve the same configurations.
The method will be removed in version 1.1.0.Bootstrap mapping function to update TcpClient configuration and
return an enriched TcpClient to use.
Note:
There isn't only one method that replaces this deprecated method.
The configuration that can be done with this deprecated method,
can also be done with the other methods exposed by TcpClient.
Examples:
Configuration via the deprecated '.bootstrap(...)' method
TcpClient.bootstrap(b ->
b.attr(...) // configures the channel attributes
.group(...) // configures the event loop group
.handler(...) // configures the channel handler
.localAddress(...) // configures the bind (local) address
.option(...) // configures the channel options
.remoteAddress(...) // configures the remote address
.resolver(...)) // configures the host names resolver
Configuration via the other methods exposed by TcpClient
TcpClient.attr(...) // configures the channel attributes
.runOn(...) // configures the event loop group
.doOnChannelInit(...) // configures the channel handler
.bindAddress(...) // configures the bind (local) address
.option(...) // configures the channel options
.remoteAddress(...) // configures the remote address
.resolver(...) // configures the host names resolver
Wire logging in plain text
TcpClient.wiretap("logger", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL)
public Mono<? extends Connection> connect()
ClientTransportClientTransport and return a Mono of Connection. If
Mono is cancelled, the underlying connection will be aborted. Once the
Connection has been emitted and is not necessary anymore, disposing must be
done by the user via DisposableChannel.dispose().connect in class ClientTransport<TcpClient,TcpClientConfig>Mono of Connectionpublic final Connection connectNow()
ClientTransportClientTransport and return a Connection. Disposing must be
done by the user via DisposableChannel.dispose(). The max connection
timeout is 45 seconds.connectNow in class ClientTransport<TcpClient,TcpClientConfig>Connectionpublic final Connection connectNow(Duration timeout)
ClientTransportClientTransport and return a Connection. Disposing must be
done by the user via DisposableChannel.dispose().connectNow in class ClientTransport<TcpClient,TcpClientConfig>timeout - connect timeout (resolution: ns)Connectionpublic TcpClient doOnConnect(Consumer<? super TcpClientConfig> doOnConnect)
ClientTransportClientTransport is about to connect to the remote endpoint.doOnConnect in class ClientTransport<TcpClient,TcpClientConfig>doOnConnect - a consumer observing connect eventsClientTransport referencepublic TcpClient doOnConnected(Consumer<? super Connection> doOnConnected)
ClientTransportConnection has been connected.doOnConnected in class ClientTransport<TcpClient,TcpClientConfig>doOnConnected - a consumer observing connected eventsClientTransport referencepublic TcpClient doOnDisconnected(Consumer<? super Connection> doOnDisconnected)
ClientTransportConnection has been disconnected.doOnDisconnected in class ClientTransport<TcpClient,TcpClientConfig>doOnDisconnected - a consumer observing disconnected eventsClientTransport referencepublic TcpClient handle(BiFunction<? super NettyInbound,? super NettyOutbound,? extends Publisher<Void>> handler)
public TcpClient host(String host)
ClientTransporthost in class ClientTransport<TcpClient,TcpClientConfig>host - the host to connect toClientTransport referencepublic TcpClient metrics(boolean enable)
TransportglobalRegistry.
Applications can separately register their own
filters.
For example, to put an upper bound on the number of tags produced:
MeterFilter filter = ... ; Metrics.globalRegistry.config().meterFilter(MeterFilter.maximumAllowableTags(prefix, 100, filter));
By default this is not enabled.
metrics in class Transport<TcpClient,TcpClientConfig>enable - true enables metrics collection; false disables itTransport referencepublic TcpClient metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder)
TransportTransport.
All generated metrics are provided to the specified recorder
which is only instantiated if metrics are being enabled (the instantiation is not lazy,
but happens immediately, while configuring the Transport).metrics in class Transport<TcpClient,TcpClientConfig>enable - if true enables the metrics on the Transport.recorder - a supplier for the ChannelMetricsRecorderTransport referencepublic TcpClient noProxy()
ClientTransportnoProxy in class ClientTransport<TcpClient,TcpClientConfig>ClientTransport referencepublic TcpClient noSSL()
TcpClientpublic TcpClient observe(ConnectionObserver observer)
TransportConnectionObserver to observe the connection state changes.observe in class Transport<TcpClient,TcpClientConfig>observer - the ConnectionObserver to be set or addTransport referencepublic <O> TcpClient option(ChannelOption<O> key, @Nullable O value)
TransportChannelOption.AUTO_READ option will be ignored. It is configured to be false.option in class Transport<TcpClient,TcpClientConfig>O - the option typekey - the ChannelOption keyvalue - the ChannelOption value or nullTransport referencepublic TcpClient port(int port)
ClientTransportport in class ClientTransport<TcpClient,TcpClientConfig>port - the port to connect toClientTransport referencepublic TcpClient proxy(Consumer<? super ProxyProvider.TypeSpec> proxyOptions)
ClientTransportproxy in class ClientTransport<TcpClient,TcpClientConfig>proxyOptions - the proxy configuration callbackClientTransport referencepublic TcpClient remoteAddress(Supplier<? extends SocketAddress> remoteAddressSupplier)
ClientTransportremoteAddress in class ClientTransport<TcpClient,TcpClientConfig>remoteAddressSupplier - A supplier of the address to connect to.ClientTransportpublic TcpClient resolver(AddressResolverGroup<?> resolver)
ClientTransportAddressResolverGroup.resolver in class ClientTransport<TcpClient,TcpClientConfig>resolver - the new AddressResolverGroupClientTransport referencepublic TcpClient runOn(EventLoopGroup eventLoopGroup)
TransportEventLoopGroup.runOn in class Transport<TcpClient,TcpClientConfig>eventLoopGroup - an eventLoopGroup to shareTransport referencepublic TcpClient runOn(LoopResources channelResources)
TransportEventLoopGroup from the LoopResources container.
Will prefer native (epoll/kqueue) implementation if available
unless the environment property reactor.netty.native is set to false.runOn in class Transport<TcpClient,TcpClientConfig>channelResources - a LoopResources accepting native runtime expectation and
returning an eventLoopGroupTransport referencepublic TcpClient runOn(LoopResources loopResources, boolean preferNative)
TransportEventLoopGroup from the LoopResources container.runOn in class ClientTransport<TcpClient,TcpClientConfig>loopResources - a new loop resourcespreferNative - should prefer running on epoll, kqueue or similar instead of java NIOTransport referencepublic TcpClient secure()
SslContext will be
assigned to
with a default value of 10 seconds handshake timeout unless
the environment property reactor.netty.tcp.sslHandshakeTimeout is set.TcpClientpublic TcpClient secure(Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder)
SslContext to be passed to with a default value of
10 seconds handshake timeout unless the environment property reactor.netty.tcp.sslHandshakeTimeout is set.sslProviderBuilder - builder callback for further customization of SslContext.TcpClientpublic TcpClient secure(SslProvider sslProvider)
SslProvider.sslProvider - The provider to set when configuring SSLTcpClientpublic Mono<Void> warmup()
Mono that triggers:
connect operation absorbs the extra time needed to load resources.warmup in class ClientTransport<TcpClient,TcpClientConfig>Mono representing the completion of the warmuppublic TcpClient wiretap(boolean enable)
TransportTransport category (logger),
DEBUG logger level and AdvancedByteBufFormat.HEX_DUMP for ByteBuf format,
which means both events and content will be logged and the content will be in hex format.wiretap in class Transport<TcpClient,TcpClientConfig>enable - specifies whether the wire logger configuration will be added to the pipelineTransport referencepublic TcpClient wiretap(String category)
TransportDEBUG logger level and AdvancedByteBufFormat.HEX_DUMP for ByteBuf format,
which means both events and content will be logged and the content will be in hex format.wiretap in class Transport<TcpClient,TcpClientConfig>category - the logger categoryTransport referencepublic TcpClient wiretap(String category, LogLevel level)
TransportAdvancedByteBufFormat.HEX_DUMP for ByteBuf format,
which means both events and content will be logged and the content will be in hex format.wiretap in class Transport<TcpClient,TcpClientConfig>category - the logger categorylevel - the logger levelTransport reference