Package io.servicetalk.http.netty
Enum Class HttpClients.DiscoveryStrategy
java.lang.Object
java.lang.Enum<HttpClients.DiscoveryStrategy>
io.servicetalk.http.netty.HttpClients.DiscoveryStrategy
- All Implemented Interfaces:
Serializable
,Comparable<HttpClients.DiscoveryStrategy>
,Constable
- Enclosing class:
- HttpClients
Defines
ServiceDiscoverer
will be used.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionResolves an address in a background.Resolves an address every time a new connection is required. -
Method Summary
Modifier and TypeMethodDescriptionReturns the enum constant of this class with the specified name.static HttpClients.DiscoveryStrategy[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
BACKGROUND
Resolves an address in a background.The
LoadBalancer
subscribes to thestream of events
fromServiceDiscoverer
and listens for updates in a background. All changes propagated by a discovery system will be available to theLoadBalancer
. When a new connection is required, the resolved address will already be available.This is the recommended default strategy that allows a client to:
- Perform client-side load balancing.
- Remove the cost (latency) required for resolving an address from the hot path of request processing.
- Move/shift traffic immediately based on updates from the
ServiceDiscoverer
.
-
ON_NEW_CONNECTION
Resolves an address every time a new connection is required.Client holds the unresolved address internally and uses
ServiceDiscoverer
to resolve it only when a new connection is required. This behavior may be beneficial for the following scenarios:- Client has a low rate of opening new connections.
- Application creates many clients (or uses a
multi-address
client) that talk to many different hosts. the defaultBACKGROUND
strategy introduces a risk to overload the discovery system. The impact might be more visible whenServiceDiscoverer
uses polling to receive updated, like DNS. - To mimic behavior of other HTTP client implementations, like default Java HttpClient or
HttpURLConnection
.
Important side effects of this strategy to take into account:
- The total latency for opening a new connection will be increased by a latency of the first
ServiceDiscoverer
answer. - If the target host has more than one resolved address, created clients loose ability to perform
client-side load
balancing for each request. Instead, the client will connect to any random resolved address returned
by a
ServiceDiscoverer
. This approach introduces randomness at connect time but doesn't guarantee balancing for every request. - Created clients won't be able to move/shift traffic based on changes observed by a
ServiceDiscoverer
until the remote server closes existing connections. - The only way to change or customize a
ServiceDiscoverer
for this strategy is to useHttpClients.forSingleAddress(ServiceDiscoverer, Object, DiscoveryStrategy)
client factory. Setting a differentServiceDiscoverer
instance viaSingleAddressHttpClientBuilder.serviceDiscoverer(ServiceDiscoverer)
method later will throw an exception. - Currently,
TransportObserver
won't be able to takeServiceDiscoverer
latency into account becauseonNewConnection
callback is invoked later. Users need to use observability features provided by aServiceDiscoverer
implementation or intercept itsServiceDiscoverer.discover(Object)
publisher to track this latency. Correlation between that tracking logic andTransportObserver.onNewConnection(Object, Object)
(if desired) can be achieved using a state propagated viaAsyncContext
. Observability features for this strategy will be improved in the future releases.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-