Package reactor.netty.udp
Class UdpClient
A UdpClient allows building in a safe immutable way a UDP client that is materialized
and connecting when
connect()
is ultimately called.
Example:
UdpClient.create()
.doOnConnect(startMetrics)
.doOnConnected(startedMetrics)
.doOnDisconnected(stopMetrics)
.host("127.0.0.1")
.port(1234)
.connect()
.block()
- Author:
- Stephane Maldini, Violeta Georgieva
-
Nested Class Summary
Nested classes/interfaces inherited from class reactor.netty.transport.ClientTransport
ClientTransport.ResolvedAddressSelector<CONF>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <A> UdpClient
attr
(AttributeKey<A> key, @Nullable A value) Update the given attribute key or remove it if the value is null.final UdpClient
bindAddress
(Supplier<? extends SocketAddress> bindAddressSupplier) Set a new local address to which this transport should bind on subscribe.final Mono<? extends Connection>
connect()
final Connection
Block theClientTransport
and return aConnection
.final Connection
connectNow
(Duration timeout) Block theClientTransport
and return aConnection
.static UdpClient
create()
Prepare aUdpClient
.final UdpClient
doOnConnect
(Consumer<? super UdpClientConfig> doOnConnect) Set or add a callback called whenClientTransport
is about to connect to the remote endpoint.final UdpClient
doOnConnected
(Consumer<? super Connection> doOnConnected) Set or add a callback called afterConnection
has been connected.final UdpClient
doOnDisconnected
(Consumer<? super Connection> doOnDisconnected) Set or add a callback called afterConnection
has been disconnected.final UdpClient
handle
(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) Attach an IO handler to react on connected client.final UdpClient
The host to which this client should connect.final UdpClient
metrics
(boolean enable) Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistry
.final UdpClient
metrics
(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder) Specifies whether the metrics are enabled on theTransport
.final UdpClient
observe
(ConnectionObserver observer) Set or add the givenConnectionObserver
to observe the connection state changes.final <O> UdpClient
option
(ChannelOption<O> key, @Nullable O value) Update the given option key or remove it if the value is null.final UdpClient
port
(int port) The port to which this client should connect.final UdpClient
remoteAddress
(Supplier<? extends SocketAddress> remoteAddressSupplier) The address to which this client should connect on each subscribe.final UdpClient
runOn
(EventLoopGroup eventLoopGroup) Run IO loops on the givenEventLoopGroup
.final UdpClient
runOn
(LoopResources channelResources) Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.final UdpClient
runOn
(LoopResources loopResources, boolean preferNative) Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.final UdpClient
runOn
(LoopResources loopResources, InternetProtocolFamily family) Deprecated.as of 1.3.0.final UdpClient
runOn
(LoopResources loopResources, SocketProtocolFamily family) Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.final UdpClient
wiretap
(boolean enable) Apply or remove a wire logger configuration usingTransport
category (logger),DEBUG
logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.final UdpClient
Apply a wire logger configuration using the specified category (logger),DEBUG
logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.final UdpClient
Apply a wire logger configuration using the specified category (logger), logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.Methods inherited from class reactor.netty.transport.ClientTransport
doAfterResolve, doOnResolve, doOnResolveError, noProxy, proxy, proxyWithSystemProperties, resolvedAddressesSelector, resolver, resolver, warmup
Methods inherited from class reactor.netty.transport.Transport
channelGroup, configuration, doOnChannelInit, duplicate, wiretap, wiretap
-
Constructor Details
-
UdpClient
public UdpClient()
-
-
Method Details
-
create
Prepare aUdpClient
.- Returns:
- a
UdpClient
-
attr
Description copied from class:Transport
Update the given attribute key or remove it if the value is null.- Overrides:
attr
in classTransport<UdpClient,
UdpClientConfig> - Type Parameters:
A
- the attribute type- Parameters:
key
- theAttributeKey
keyvalue
- theAttributeKey
value- Returns:
- a new
Transport
reference
-
bindAddress
Description copied from class:Transport
Set a new local address to which this transport should bind on subscribe.- Overrides:
bindAddress
in classTransport<UdpClient,
UdpClientConfig> - Parameters:
bindAddressSupplier
- A supplier of the address to bind to.- Returns:
- a new
Transport
-
connect
Description copied from class:ClientTransport
Connect theClientTransport
and return aMono
ofConnection
. IfMono
is cancelled, the underlying connection will be aborted. Once theConnection
has been emitted and is not necessary anymore, disposing must be done by the user viaDisposableChannel.dispose()
.- Overrides:
connect
in classClientTransport<UdpClient,
UdpClientConfig> - Returns:
- a
Mono
ofConnection
-
connectNow
Description copied from class:ClientTransport
Block theClientTransport
and return aConnection
. Disposing must be done by the user viaDisposableChannel.dispose()
. The max connection timeout is 45 seconds.- Overrides:
connectNow
in classClientTransport<UdpClient,
UdpClientConfig> - Returns:
- a
Connection
-
connectNow
Description copied from class:ClientTransport
Block theClientTransport
and return aConnection
. Disposing must be done by the user viaDisposableChannel.dispose()
.- Overrides:
connectNow
in classClientTransport<UdpClient,
UdpClientConfig> - Parameters:
timeout
- connect timeout (resolution: ns)- Returns:
- a
Connection
-
doOnConnect
Description copied from class:ClientTransport
Set or add a callback called whenClientTransport
is about to connect to the remote endpoint.- Overrides:
doOnConnect
in classClientTransport<UdpClient,
UdpClientConfig> - Parameters:
doOnConnect
- a consumer observing connect events- Returns:
- a new
ClientTransport
reference
-
doOnConnected
Description copied from class:ClientTransport
Set or add a callback called afterConnection
has been connected.- Overrides:
doOnConnected
in classClientTransport<UdpClient,
UdpClientConfig> - Parameters:
doOnConnected
- a consumer observing connected events- Returns:
- a new
ClientTransport
reference
-
doOnDisconnected
Description copied from class:ClientTransport
Set or add a callback called afterConnection
has been disconnected.- Overrides:
doOnDisconnected
in classClientTransport<UdpClient,
UdpClientConfig> - Parameters:
doOnDisconnected
- a consumer observing disconnected events- Returns:
- a new
ClientTransport
reference
-
handle
public final UdpClient handle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) Attach an IO handler to react on connected client. -
host
Description copied from class:ClientTransport
The host to which this client should connect.- Overrides:
host
in classClientTransport<UdpClient,
UdpClientConfig> - Parameters:
host
- the host to connect to- Returns:
- a new
ClientTransport
reference
-
metrics
Description copied from class:Transport
Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistry
. Applications can separately register their ownfilters
. 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.
- Overrides:
metrics
in classTransport<UdpClient,
UdpClientConfig> - Parameters:
enable
- true enables metrics collection; false disables it- Returns:
- a new
Transport
reference
-
metrics
Description copied from class:Transport
Specifies whether the metrics are enabled on theTransport
. 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 theTransport
).- Overrides:
metrics
in classTransport<UdpClient,
UdpClientConfig> - Parameters:
enable
- if true enables the metrics on theTransport
.recorder
- a supplier for theChannelMetricsRecorder
- Returns:
- a new
Transport
reference
-
observe
Description copied from class:Transport
Set or add the givenConnectionObserver
to observe the connection state changes.- Overrides:
observe
in classTransport<UdpClient,
UdpClientConfig> - Parameters:
observer
- theConnectionObserver
to be set or add- Returns:
- a new
Transport
reference
-
option
Description copied from class:Transport
Update the given option key or remove it if the value is null. Note: SettingChannelOption.AUTO_READ
option will be ignored. It is configured to befalse
.- Overrides:
option
in classTransport<UdpClient,
UdpClientConfig> - Type Parameters:
O
- the option type- Parameters:
key
- theChannelOption
keyvalue
- theChannelOption
value or null- Returns:
- a new
Transport
reference
-
port
The port to which this client should connect. If a port is not specified, the default port12012
is used.Note: The port can be specified also with
PORT
environment variable.- Overrides:
port
in classClientTransport<UdpClient,
UdpClientConfig> - Parameters:
port
- the port to connect to- Returns:
- a new
UdpClient
reference
-
remoteAddress
Description copied from class:ClientTransport
The address to which this client should connect on each subscribe.- Overrides:
remoteAddress
in classClientTransport<UdpClient,
UdpClientConfig> - Parameters:
remoteAddressSupplier
- A supplier of the address to connect to.- Returns:
- a new
ClientTransport
-
runOn
Description copied from class:Transport
Run IO loops on the givenEventLoopGroup
.- Overrides:
runOn
in classTransport<UdpClient,
UdpClientConfig> - Parameters:
eventLoopGroup
- an eventLoopGroup to share- Returns:
- a new
Transport
reference
-
runOn
Description copied from class:Transport
Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container. Will prefer native (epoll/io_uring/kqueue) implementation if available unless the environment propertyreactor.netty.native
is set tofalse
.- Overrides:
runOn
in classTransport<UdpClient,
UdpClientConfig> - Parameters:
channelResources
- aLoopResources
accepting native runtime expectation and returning an eventLoopGroup- Returns:
- a new
Transport
reference
-
runOn
Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.- Overrides:
runOn
in classClientTransport<UdpClient,
UdpClientConfig> - Parameters:
loopResources
- a new loop resourcespreferNative
- should prefer running on epoll, io_uring, kqueue or similar instead of java NIO- Returns:
- a new
UdpClient
reference
-
runOn
@Deprecated public final UdpClient runOn(LoopResources loopResources, InternetProtocolFamily family) Deprecated.as of 1.3.0. PreferrunOn(LoopResources, SocketProtocolFamily)
. This method will be removed in version 1.4.0.Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.- Parameters:
loopResources
- a new loop resourcesfamily
- a specificInternetProtocolFamily
to run with- Returns:
- a new
UdpClient
reference
-
runOn
Run IO loops on a suppliedEventLoopGroup
from theLoopResources
container.- Parameters:
loopResources
- a new loop resourcesfamily
- a specificSocketProtocolFamily
to run with- Returns:
- a new
UdpClient
reference - Since:
- 1.3.0
-
wiretap
Description copied from class:Transport
Apply or remove a wire logger configuration usingTransport
category (logger),DEBUG
logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretap
in classTransport<UdpClient,
UdpClientConfig> - Parameters:
enable
- specifies whether the wire logger configuration will be added to the pipeline- Returns:
- a new
Transport
reference
-
wiretap
Description copied from class:Transport
Apply a wire logger configuration using the specified category (logger),DEBUG
logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretap
in classTransport<UdpClient,
UdpClientConfig> - Parameters:
category
- the logger category- Returns:
- a new
Transport
reference
-
wiretap
Description copied from class:Transport
Apply a wire logger configuration using the specified category (logger), logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretap
in classTransport<UdpClient,
UdpClientConfig> - Parameters:
category
- the logger categorylevel
- the logger level- Returns:
- a new
Transport
reference
-