public abstract class TcpClient extends Object
connect(Bootstrap)
is ultimately called.
Internally, materialization happens in two phases, first configure()
is
called to retrieve a ready to use Bootstrap
then connect(Bootstrap)
is 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(java.util.function.Supplier<? extends SocketAddress> connectAddressSupplier)
Deprecated.
as of 0.9.7. Use
remoteAddress(Supplier) |
<T> TcpClient |
attr(AttributeKey<T> key,
T value)
Inject default attribute to the future
Channel connection. |
TcpClient |
bindAddress(java.util.function.Supplier<? extends SocketAddress> bindAddressSupplier)
The address to which this client should bind on subscribe.
|
TcpClient |
bootstrap(java.util.function.Function<? super Bootstrap,? extends Bootstrap> bootstrapMapper)
Deprecated.
as of 0.9.10. Use the methods exposed on
TcpClient level. The method
will be removed in version 1.1.0. |
Bootstrap |
configure()
Materialize a Bootstrap from the parent
TcpClient chain to use with connect(Bootstrap) or separately |
Mono<? extends Connection> |
connect()
|
abstract Mono<? extends Connection> |
connect(Bootstrap b)
|
Connection |
connectNow()
Block the
TcpClient and return a Connection . |
Connection |
connectNow(java.time.Duration timeout)
Block the
TcpClient and return a Connection . |
static TcpClient |
create()
Prepare a pooled
TcpClient |
static TcpClient |
create(ConnectionProvider provider)
Prepare a
TcpClient |
TcpClient |
doOnConnect(java.util.function.Consumer<? super Bootstrap> doOnConnect)
Setup a callback called when
Channel is about to connect. |
TcpClient |
doOnConnected(java.util.function.Consumer<? super Connection> doOnConnected)
Setup a callback called after
Channel has been connected. |
TcpClient |
doOnDisconnected(java.util.function.Consumer<? super Connection> doOnDisconnected)
Setup a callback called after
Channel has been disconnected. |
TcpClient |
doOnLifecycle(java.util.function.Consumer<? super Bootstrap> doOnConnect,
java.util.function.Consumer<? super Connection> doOnConnected,
java.util.function.Consumer<? super Connection> doOnDisconnected)
Deprecated.
as of 0.9.7. Use
doOnConnect(Consumer) , doOnConnected(Consumer)
or doOnDisconnected(Consumer) |
TcpClient |
handle(java.util.function.BiFunction<? super NettyInbound,? super NettyOutbound,? extends Publisher<Void>> handler)
Attach an IO handler to react on connected client
|
boolean |
hasProxy()
Return true if that
TcpClient is configured with a proxy |
TcpClient |
host(String host)
The host to which this client should connect.
|
boolean |
isSecure()
Return true if that
TcpClient secured via SSL transport |
TcpClient |
metrics(boolean metricsEnabled)
Whether to enable metrics to be collected and registered in Micrometer's
globalRegistry
under the name Metrics.TCP_CLIENT_PREFIX . |
TcpClient |
metrics(boolean metricsEnabled,
ChannelMetricsRecorder recorder)
Deprecated.
as of 0.9.7. Use
metrics(boolean, Supplier) |
TcpClient |
metrics(boolean metricsEnabled,
java.util.function.Supplier<? extends ChannelMetricsRecorder> recorder)
Specifies whether the metrics are enabled on the
TcpClient . |
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)
Setup all lifecycle callbacks called on or after
Channel
has been connected and after it has been disconnected. |
<T> TcpClient |
option(ChannelOption<T> key,
T value)
|
TcpClient |
port(int port)
The port to which this client should connect.
|
TcpClient |
proxy(java.util.function.Consumer<? super ProxyProvider.TypeSpec> proxyOptions)
Apply a proxy configuration
|
ProxyProvider |
proxyProvider()
Return the current
ProxyProvider if any |
TcpClient |
remoteAddress(java.util.function.Supplier<? extends SocketAddress> remoteAddressSupplier)
The address to which this client should connect for 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 channelResources,
boolean preferNative)
Run IO loops on a supplied
EventLoopGroup from the
LoopResources container. |
TcpClient |
secure()
Enable default sslContext support.
|
TcpClient |
secure(java.util.function.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 . |
SslProvider |
sslProvider()
Return the current
SslProvider if that TcpClient secured via SSL
transport or null |
TcpClient |
wiretap(boolean enable)
Apply or remove a wire logger configuration using
TcpClient category
and DEBUG logger level |
TcpClient |
wiretap(String category)
Apply a wire logger configuration using the specified category
and
DEBUG logger level |
TcpClient |
wiretap(String category,
LogLevel level)
Apply a wire logger configuration using the specified category
and logger level
|
public static TcpClient create(ConnectionProvider provider)
TcpClient
provider
- a ConnectionProvider
to acquire connectionsTcpClient
public static TcpClient newConnection()
TcpClient
TcpClient
@Deprecated public final TcpClient addressSupplier(java.util.function.Supplier<? extends SocketAddress> connectAddressSupplier)
remoteAddress(Supplier)
connectAddressSupplier
- A supplier of the address to connect to.TcpClient
public final TcpClient remoteAddress(java.util.function.Supplier<? extends SocketAddress> remoteAddressSupplier)
remoteAddressSupplier
- A supplier of the address to connect to.TcpClient
public final <T> TcpClient attr(AttributeKey<T> key, @Nullable T value)
Channel
connection. They will be
available via AttributeMap.attr(AttributeKey)
.
If the value
is null
, the attribute of the specified key
is removed.T
- the attribute typekey
- the attribute keyvalue
- the attribute valueTcpClient
AbstractBootstrap.attr(AttributeKey, Object)
public final TcpClient bindAddress(java.util.function.Supplier<? extends SocketAddress> bindAddressSupplier)
bindAddressSupplier
- A supplier of the address to bind to.TcpClient
@Deprecated public final TcpClient bootstrap(java.util.function.Function<? super Bootstrap,? extends Bootstrap> bootstrapMapper)
TcpClient
level. The method
will be removed in version 1.1.0.Bootstrap
configuration given mapper taking currently configured one
and returning a new one to be ultimately used for socket binding.
Configuration will apply during configure()
phase.
bootstrapMapper
- A bootstrap mapping function to update configuration and return an
enriched bootstrap.TcpClient
public Bootstrap configure()
TcpClient
chain to use with connect(Bootstrap)
or separatelyBootstrap
public final Mono<? extends Connection> connect()
TcpClient
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()
.
If update configuration phase fails, a Mono.error(Throwable)
will be returnedMono
of Connection
public abstract Mono<? extends Connection> connect(Bootstrap b)
b
- the Bootstrap
to connectMono
of Connection
public final Connection connectNow()
TcpClient
and return a Connection
. Disposing must be
done by the user via DisposableChannel.dispose()
. The max connection
timeout is 45 seconds.Mono
of Connection
public final Connection connectNow(java.time.Duration timeout)
TcpClient
and return a Connection
. Disposing must be
done by the user via DisposableChannel.dispose()
.timeout
- connect timeoutMono
of Connection
public final TcpClient doOnConnect(java.util.function.Consumer<? super Bootstrap> doOnConnect)
Channel
is about to connect.doOnConnect
- a runnable observing connected eventsTcpClient
public final TcpClient doOnConnected(java.util.function.Consumer<? super Connection> doOnConnected)
Channel
has been connected.doOnConnected
- a consumer observing connected eventsTcpClient
public final TcpClient doOnDisconnected(java.util.function.Consumer<? super Connection> doOnDisconnected)
Channel
has been disconnected.doOnDisconnected
- a consumer observing disconnected eventsTcpClient
@Deprecated public final TcpClient doOnLifecycle(java.util.function.Consumer<? super Bootstrap> doOnConnect, java.util.function.Consumer<? super Connection> doOnConnected, java.util.function.Consumer<? super Connection> doOnDisconnected)
doOnConnect(Consumer)
, doOnConnected(Consumer)
or doOnDisconnected(Consumer)
Channel
has been connected and after it has been disconnected.doOnConnect
- a consumer observing client start eventdoOnConnected
- a consumer observing client started eventdoOnDisconnected
- a consumer observing client stop eventTcpClient
public final TcpClient host(String host)
host
- The host to connect to.TcpClient
public final TcpClient handle(java.util.function.BiFunction<? super NettyInbound,? super NettyOutbound,? extends Publisher<Void>> handler)
public final boolean hasProxy()
TcpClient
is configured with a proxyTcpClient
is configured with a proxypublic final boolean isSecure()
TcpClient
secured via SSL transportTcpClient
secured via SSL transportpublic final TcpClient noProxy()
TcpClient
public final TcpClient noSSL()
TcpClient
public final TcpClient observe(ConnectionObserver observer)
Channel
has been connected and after it has been disconnected.observer
- a consumer observing state changesTcpClient
public final <T> TcpClient option(ChannelOption<T> key, @Nullable T value)
ChannelOption
value for low level connection settings like SO_TIMEOUT
or SO_KEEPALIVE
. This will apply to each new channel from remote peer.
Use a value of null
to remove a previous set ChannelOption
.T
- the option typekey
- the option keyvalue
- the option valueTcpClient
AbstractBootstrap.option(ChannelOption, Object)
public final TcpClient port(int port)
port
- The port to connect to.TcpClient
public final TcpClient proxy(java.util.function.Consumer<? super ProxyProvider.TypeSpec> proxyOptions)
proxyOptions
- the proxy configuration callbackTcpClient
@Nullable public ProxyProvider proxyProvider()
ProxyProvider
if anyProxyProvider
if anypublic final TcpClient resolver(AddressResolverGroup<?> resolver)
AddressResolverGroup
.resolver
- the new AddressResolverGroup
TcpClient
public final TcpClient runOn(EventLoopGroup eventLoopGroup)
EventLoopGroup
.eventLoopGroup
- an eventLoopGroup to shareTcpClient
public final TcpClient runOn(LoopResources channelResources)
EventLoopGroup
from the
LoopResources
container. Will prefer native (epoll/kqueue) implementation if
available unless the environment property reactor.netty.native
is set
to false
.channelResources
- a LoopResources
accepting native runtime expectation and
returning an eventLoopGroupTcpClient
public final TcpClient runOn(LoopResources channelResources, boolean preferNative)
EventLoopGroup
from the
LoopResources
container.channelResources
- a LoopResources
accepting native runtime expectation and
returning an eventLoopGroup.preferNative
- Should the connector prefer native (epoll/kqueue) if available.TcpClient
public final 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.TcpClient
public final TcpClient secure(java.util.function.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.TcpClient
public final TcpClient secure(SslProvider sslProvider)
SslProvider
.sslProvider
- The provider to set when configuring SSLTcpClient
@Nullable public SslProvider sslProvider()
SslProvider
if that TcpClient
secured via SSL
transport or nullSslProvider
if that TcpClient
secured via SSL
transport or nullpublic final TcpClient metrics(boolean metricsEnabled)
globalRegistry
under the name Metrics.TCP_CLIENT_PREFIX
. Applications can
separately register their own
filters
associated with this name.
For example, to put an upper bound on the number of tags produced:
MeterFilter filter = ... ; Metrics.globalRegistry.config().meterFilter(MeterFilter.maximumAllowableTags(TCP_CLIENT_PREFIX, 100, filter));
By default this is not enabled.
metricsEnabled
- true enables metrics collection; false disables itTcpClient
@Deprecated public final TcpClient metrics(boolean metricsEnabled, ChannelMetricsRecorder recorder)
metrics(boolean, Supplier)
TcpClient
.
All generated metrics are provided to the specified recorder.metricsEnabled
- if true enables the metrics on the client.recorder
- the ChannelMetricsRecorder
TcpClient
public final TcpClient metrics(boolean metricsEnabled, java.util.function.Supplier<? extends ChannelMetricsRecorder> recorder)
TcpClient
.
All generated metrics are provided to the specified recorder
which is only instantiated if metrics are being enabled.metricsEnabled
- if true enables the metrics on the client.recorder
- a supplier for the ChannelMetricsRecorder
TcpClient
public final TcpClient wiretap(boolean enable)
TcpClient
category
and DEBUG
logger levelenable
- Specifies whether the wire logger configuration will be added to
the pipelineTcpClient
public final TcpClient wiretap(String category)
DEBUG
logger levelcategory
- the logger categoryTcpClient