Interface EndpointSelectionStrategy
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Endpoint
selection strategy that creates a EndpointSelector
.-
Method Summary
Modifier and TypeMethodDescriptionReturns a newWeightRampingUpStrategyBuilder
that builds a weight ramping upEndpointSelectionStrategy
which ramps the weight of newly addedEndpoint
s.newSelector
(EndpointGroup endpointGroup) static EndpointSelectionStrategy
Returns a weight ramping upEndpointSelectionStrategy
which ramps the weight of newly addedEndpoint
s usingEndpointWeightTransition.linear()
.static EndpointSelectionStrategy
Returns a round-robin strategy, which ignoresEndpoint.weight()
.static EndpointSelectionStrategy
sticky
(ToLongFunction<? super ClientRequestContext> requestContextHasher) Returns a sticky strategy which uses a user passedToLongFunction
to compute hashes for consistent hashing.static EndpointSelectionStrategy
Returns a weighted round-robin strategy.
-
Method Details
-
weightedRoundRobin
Returns a weighted round-robin strategy. The endpoint is selected using Interleaved WRR algorithm.- See Also:
-
roundRobin
Returns a round-robin strategy, which ignoresEndpoint.weight()
.- See Also:
-
rampingUp
Returns a weight ramping upEndpointSelectionStrategy
which ramps the weight of newly addedEndpoint
s usingEndpointWeightTransition.linear()
. TheEndpoint
is selected using weighted random distribution. The weights ofEndpoint
s are ramped up by 10 percent every 2 seconds up to 100 percent by default. If you want to customize the parameters, usebuilderForRampingUp()
. -
builderForRampingUp
Returns a newWeightRampingUpStrategyBuilder
that builds a weight ramping upEndpointSelectionStrategy
which ramps the weight of newly addedEndpoint
s. TheEndpoint
is selected using weighted random distribution. -
sticky
static EndpointSelectionStrategy sticky(ToLongFunction<? super ClientRequestContext> requestContextHasher) Returns a sticky strategy which uses a user passedToLongFunction
to compute hashes for consistent hashing.This strategy can be useful when all requests that qualify some given criteria must be sent to the same backend server. A common use case is to send all requests for the same logged-in user to the same backend, which could have a local cache keyed by user id.
In below example, created strategy will route all
HttpRequest
which have the same value for key "cookie" of its header to the same server:ToLongFunction<ClientRequestContext> hasher = (ClientRequestContext ctx) -> { return ((HttpRequest) ctx.request()).headers().get(HttpHeaderNames.COOKIE).hashCode(); }; EndpointSelectionStrategy strategy = EndpointSelectionStrategy.sticky(hasher);
- See Also:
-
newSelector
-