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> UdpClientattr(AttributeKey<A> key, @Nullable A value) Update the given attribute key or remove it if the value is null.final UdpClientbindAddress(Supplier<? extends SocketAddress> bindAddressSupplier) Set a new local address to which this transport should bind on subscribe.final Mono<? extends Connection>connect()final ConnectionBlock theClientTransportand return aConnection.final ConnectionconnectNow(Duration timeout) Block theClientTransportand return aConnection.static UdpClientcreate()Prepare aUdpClient.final UdpClientdoOnConnect(Consumer<? super UdpClientConfig> doOnConnect) Set or add a callback called whenClientTransportis about to connect to the remote endpoint.final UdpClientdoOnConnected(Consumer<? super Connection> doOnConnected) Set or add a callback called afterConnectionhas been connected.final UdpClientdoOnDisconnected(Consumer<? super Connection> doOnDisconnected) Set or add a callback called afterConnectionhas been disconnected.final UdpClienthandle(BiFunction<? super UdpInbound, ? super UdpOutbound, ? extends Publisher<Void>> handler) Attach an IO handler to react on connected client.final UdpClientThe host to which this client should connect.final UdpClientmetrics(boolean enable) Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistry.final UdpClientmetrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder) Specifies whether the metrics are enabled on theTransport.final UdpClientobserve(ConnectionObserver observer) Set or add the givenConnectionObserverto observe the connection state changes.final <O> UdpClientoption(ChannelOption<O> key, @Nullable O value) Update the given option key or remove it if the value is null.final UdpClientport(int port) The port to which this client should connect.final UdpClientremoteAddress(Supplier<? extends SocketAddress> remoteAddressSupplier) The address to which this client should connect on each subscribe.final UdpClientrunOn(EventLoopGroup eventLoopGroup) Run IO loops on the givenEventLoopGroup.final UdpClientrunOn(LoopResources channelResources) Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.final UdpClientrunOn(LoopResources loopResources, boolean preferNative) Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.final UdpClientrunOn(LoopResources loopResources, InternetProtocolFamily family) Deprecated.as of 1.3.0.final UdpClientrunOn(LoopResources loopResources, SocketProtocolFamily family) Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.final UdpClientwiretap(boolean enable) Apply or remove a wire logger configuration usingTransportcategory (logger),DEBUGlogger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.final UdpClientApply a wire logger configuration using the specified category (logger),DEBUGlogger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.final UdpClientApply a wire logger configuration using the specified category (logger), logger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, 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, warmupMethods 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:TransportUpdate the given attribute key or remove it if the value is null.- Overrides:
attrin classTransport<UdpClient,UdpClientConfig> - Type Parameters:
A- the attribute type- Parameters:
key- theAttributeKeykeyvalue- theAttributeKeyvalue- Returns:
- a new
Transportreference
-
bindAddress
Description copied from class:TransportSet a new local address to which this transport should bind on subscribe.- Overrides:
bindAddressin classTransport<UdpClient,UdpClientConfig> - Parameters:
bindAddressSupplier- A supplier of the address to bind to.- Returns:
- a new
Transport
-
connect
Description copied from class:ClientTransportConnect theClientTransportand return aMonoofConnection. IfMonois cancelled, the underlying connection will be aborted. Once theConnectionhas been emitted and is not necessary anymore, disposing must be done by the user viaDisposableChannel.dispose().- Overrides:
connectin classClientTransport<UdpClient,UdpClientConfig> - Returns:
- a
MonoofConnection
-
connectNow
Description copied from class:ClientTransportBlock theClientTransportand return aConnection. Disposing must be done by the user viaDisposableChannel.dispose(). The max connection timeout is 45 seconds.- Overrides:
connectNowin classClientTransport<UdpClient,UdpClientConfig> - Returns:
- a
Connection
-
connectNow
Description copied from class:ClientTransportBlock theClientTransportand return aConnection. Disposing must be done by the user viaDisposableChannel.dispose().- Overrides:
connectNowin classClientTransport<UdpClient,UdpClientConfig> - Parameters:
timeout- connect timeout (resolution: ns)- Returns:
- a
Connection
-
doOnConnect
Description copied from class:ClientTransportSet or add a callback called whenClientTransportis about to connect to the remote endpoint.- Overrides:
doOnConnectin classClientTransport<UdpClient,UdpClientConfig> - Parameters:
doOnConnect- a consumer observing connect events- Returns:
- a new
ClientTransportreference
-
doOnConnected
Description copied from class:ClientTransportSet or add a callback called afterConnectionhas been connected.- Overrides:
doOnConnectedin classClientTransport<UdpClient,UdpClientConfig> - Parameters:
doOnConnected- a consumer observing connected events- Returns:
- a new
ClientTransportreference
-
doOnDisconnected
Description copied from class:ClientTransportSet or add a callback called afterConnectionhas been disconnected.- Overrides:
doOnDisconnectedin classClientTransport<UdpClient,UdpClientConfig> - Parameters:
doOnDisconnected- a consumer observing disconnected events- Returns:
- a new
ClientTransportreference
-
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:ClientTransportThe host to which this client should connect.- Overrides:
hostin classClientTransport<UdpClient,UdpClientConfig> - Parameters:
host- the host to connect to- Returns:
- a new
ClientTransportreference
-
metrics
Description copied from class:TransportWhether 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:
metricsin classTransport<UdpClient,UdpClientConfig> - Parameters:
enable- true enables metrics collection; false disables it- Returns:
- a new
Transportreference
-
metrics
Description copied from class:TransportSpecifies 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:
metricsin classTransport<UdpClient,UdpClientConfig> - Parameters:
enable- if true enables the metrics on theTransport.recorder- a supplier for theChannelMetricsRecorder- Returns:
- a new
Transportreference
-
observe
Description copied from class:TransportSet or add the givenConnectionObserverto observe the connection state changes.- Overrides:
observein classTransport<UdpClient,UdpClientConfig> - Parameters:
observer- theConnectionObserverto be set or add- Returns:
- a new
Transportreference
-
option
Description copied from class:TransportUpdate the given option key or remove it if the value is null. Note: SettingChannelOption.AUTO_READoption will be ignored. It is configured to befalse.- Overrides:
optionin classTransport<UdpClient,UdpClientConfig> - Type Parameters:
O- the option type- Parameters:
key- theChannelOptionkeyvalue- theChannelOptionvalue or null- Returns:
- a new
Transportreference
-
port
The port to which this client should connect. If a port is not specified, the default port12012is used.Note: The port can be specified also with
PORTenvironment variable.- Overrides:
portin classClientTransport<UdpClient,UdpClientConfig> - Parameters:
port- the port to connect to- Returns:
- a new
UdpClientreference
-
remoteAddress
Description copied from class:ClientTransportThe address to which this client should connect on each subscribe.- Overrides:
remoteAddressin classClientTransport<UdpClient,UdpClientConfig> - Parameters:
remoteAddressSupplier- A supplier of the address to connect to.- Returns:
- a new
ClientTransport
-
runOn
Description copied from class:TransportRun IO loops on the givenEventLoopGroup.- Overrides:
runOnin classTransport<UdpClient,UdpClientConfig> - Parameters:
eventLoopGroup- an eventLoopGroup to share- Returns:
- a new
Transportreference
-
runOn
Description copied from class:TransportRun IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer. Will prefer native (epoll/io_uring/kqueue) implementation if available unless the environment propertyreactor.netty.nativeis set tofalse.- Overrides:
runOnin classTransport<UdpClient,UdpClientConfig> - Parameters:
channelResources- aLoopResourcesaccepting native runtime expectation and returning an eventLoopGroup- Returns:
- a new
Transportreference
-
runOn
Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.- Overrides:
runOnin 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
UdpClientreference
-
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 suppliedEventLoopGroupfrom theLoopResourcescontainer.- Parameters:
loopResources- a new loop resourcesfamily- a specificInternetProtocolFamilyto run with- Returns:
- a new
UdpClientreference
-
runOn
Run IO loops on a suppliedEventLoopGroupfrom theLoopResourcescontainer.- Parameters:
loopResources- a new loop resourcesfamily- a specificSocketProtocolFamilyto run with- Returns:
- a new
UdpClientreference - Since:
- 1.3.0
-
wiretap
Description copied from class:TransportApply or remove a wire logger configuration usingTransportcategory (logger),DEBUGlogger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretapin classTransport<UdpClient,UdpClientConfig> - Parameters:
enable- specifies whether the wire logger configuration will be added to the pipeline- Returns:
- a new
Transportreference
-
wiretap
Description copied from class:TransportApply a wire logger configuration using the specified category (logger),DEBUGlogger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretapin classTransport<UdpClient,UdpClientConfig> - Parameters:
category- the logger category- Returns:
- a new
Transportreference
-
wiretap
Description copied from class:TransportApply a wire logger configuration using the specified category (logger), logger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretapin classTransport<UdpClient,UdpClientConfig> - Parameters:
category- the logger categorylevel- the logger level- Returns:
- a new
Transportreference
-