Class CircuitBreakerClient
- All Implemented Interfaces:
Client<HttpRequest,
,HttpResponse> HttpClient
,Unwrappable
HttpClient
decorator that handles failures of HTTP requests based on circuit breaker pattern.-
Method Summary
Modifier and TypeMethodDescriptionstatic CircuitBreakerClientBuilder
builder
(CircuitBreakerRule rule) Returns a newCircuitBreakerClientBuilder
with the specifiedCircuitBreakerRule
.static CircuitBreakerClientBuilder
builder
(CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Returns a newCircuitBreakerClientBuilder
with the specifiedCircuitBreakerRuleWithContent
.static CircuitBreakerClientBuilder
builder
(CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent, int maxContentLength) Returns a newCircuitBreakerClientBuilder
with the specifiedCircuitBreakerRuleWithContent
and the specifiedmaxContentLength
which is required to determine aResponse
as a success or failure.protected HttpResponse
doExecute
(ClientRequestContext ctx, HttpRequest req, CircuitBreakerCallback callback) Invoked when theCircuitBreaker
is in closed state.static Function<? super HttpClient,
CircuitBreakerClient> newDecorator
(CircuitBreakerClientHandler handler, CircuitBreakerRule rule) Creates a new decorator with the specifiedCircuitBreakerClientHandler
andCircuitBreakerRule
.static Function<? super HttpClient,
CircuitBreakerClient> newDecorator
(CircuitBreakerClientHandler handler, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator with the specifiedCircuitBreakerClientHandler
andCircuitBreakerRuleWithContent
.static Function<? super HttpClient,
CircuitBreakerClient> newDecorator
(CircuitBreakerMapping mapping, CircuitBreakerRule rule) Creates a new decorator with the specifiedCircuitBreakerMapping
andCircuitBreakerRule
.static Function<? super HttpClient,
CircuitBreakerClient> newDecorator
(CircuitBreakerMapping mapping, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator with the specifiedCircuitBreakerMapping
andCircuitBreakerRuleWithContent
.static Function<? super HttpClient,
CircuitBreakerClient> newDecorator
(CircuitBreaker circuitBreaker, CircuitBreakerRule rule) Creates a new decorator using the specifiedCircuitBreaker
instance andCircuitBreakerRule
.static Function<? super HttpClient,
CircuitBreakerClient> newDecorator
(CircuitBreaker circuitBreaker, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator using the specifiedCircuitBreaker
instance andCircuitBreakerRuleWithContent
.static Function<? super HttpClient,
CircuitBreakerClient> newPerHostAndMethodDecorator
(BiFunction<String, String, ? extends CircuitBreaker> factory, CircuitBreakerRule rule) Deprecated.static Function<? super HttpClient,
CircuitBreakerClient> newPerHostAndMethodDecorator
(BiFunction<String, String, ? extends CircuitBreaker> factory, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) static Function<? super HttpClient,
CircuitBreakerClient> newPerHostDecorator
(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRule rule) Creates a new decorator that binds oneCircuitBreaker
per host with the specifiedCircuitBreakerRule
.static Function<? super HttpClient,
CircuitBreakerClient> newPerHostDecorator
(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator that binds oneCircuitBreaker
per host with the specifiedCircuitBreakerRuleWithContent
.static Function<? super HttpClient,
CircuitBreakerClient> newPerMethodDecorator
(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRule rule) Creates a new decorator that binds oneCircuitBreaker
perHttpMethod
with the specifiedCircuitBreakerRule
.static Function<? super HttpClient,
CircuitBreakerClient> newPerMethodDecorator
(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator that binds oneCircuitBreaker
perHttpMethod
with the specifiedCircuitBreakerRuleWithContent
.static Function<? super HttpClient,
CircuitBreakerClient> newPerPathDecorator
(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRule rule) Creates a new decorator that binds oneCircuitBreaker
per request path with the specifiedCircuitBreakerRule
.static Function<? super HttpClient,
CircuitBreakerClient> newPerPathDecorator
(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator that binds oneCircuitBreaker
per request path with the specifiedCircuitBreakerRuleWithContent
.Methods inherited from class com.linecorp.armeria.client.circuitbreaker.AbstractCircuitBreakerClient
execute, toString
Methods inherited from class com.linecorp.armeria.common.util.AbstractUnwrappable
as, unwrap, unwrapAll
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.client.HttpClient
execute
Methods inherited from interface com.linecorp.armeria.common.util.Unwrappable
equalsIgnoreWrapper, unwrapAll
-
Method Details
-
newDecorator
public static Function<? super HttpClient,CircuitBreakerClient> newDecorator(CircuitBreaker circuitBreaker, CircuitBreakerRule rule) Creates a new decorator using the specifiedCircuitBreaker
instance andCircuitBreakerRule
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services. -
newDecorator
public static Function<? super HttpClient,CircuitBreakerClient> newDecorator(CircuitBreaker circuitBreaker, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator using the specifiedCircuitBreaker
instance andCircuitBreakerRuleWithContent
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services. -
newDecorator
public static Function<? super HttpClient,CircuitBreakerClient> newDecorator(CircuitBreakerMapping mapping, CircuitBreakerRule rule) Creates a new decorator with the specifiedCircuitBreakerMapping
andCircuitBreakerRule
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services. -
newDecorator
@UnstableApi public static Function<? super HttpClient,CircuitBreakerClient> newDecorator(CircuitBreakerClientHandler handler, CircuitBreakerRule rule) Creates a new decorator with the specifiedCircuitBreakerClientHandler
andCircuitBreakerRule
. -
newDecorator
public static Function<? super HttpClient,CircuitBreakerClient> newDecorator(CircuitBreakerMapping mapping, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator with the specifiedCircuitBreakerMapping
andCircuitBreakerRuleWithContent
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services. -
newDecorator
@UnstableApi public static Function<? super HttpClient,CircuitBreakerClient> newDecorator(CircuitBreakerClientHandler handler, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator with the specifiedCircuitBreakerClientHandler
andCircuitBreakerRuleWithContent
. -
newPerMethodDecorator
public static Function<? super HttpClient,CircuitBreakerClient> newPerMethodDecorator(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRule rule) Creates a new decorator that binds oneCircuitBreaker
perHttpMethod
with the specifiedCircuitBreakerRule
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services.- Parameters:
factory
- a function that takes anHttpMethod
and creates a newCircuitBreaker
.
-
newPerMethodDecorator
public static Function<? super HttpClient,CircuitBreakerClient> newPerMethodDecorator(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator that binds oneCircuitBreaker
perHttpMethod
with the specifiedCircuitBreakerRuleWithContent
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services.- Parameters:
factory
- a function that takes anHttpMethod
and creates a newCircuitBreaker
.
-
newPerHostDecorator
public static Function<? super HttpClient,CircuitBreakerClient> newPerHostDecorator(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRule rule) Creates a new decorator that binds oneCircuitBreaker
per host with the specifiedCircuitBreakerRule
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services.- Parameters:
factory
- a function that takes a host name and creates a newCircuitBreaker
.
-
newPerHostDecorator
public static Function<? super HttpClient,CircuitBreakerClient> newPerHostDecorator(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator that binds oneCircuitBreaker
per host with the specifiedCircuitBreakerRuleWithContent
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services.- Parameters:
factory
- a function that takes a host name and creates a newCircuitBreaker
.
-
newPerPathDecorator
public static Function<? super HttpClient,CircuitBreakerClient> newPerPathDecorator(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRule rule) Creates a new decorator that binds oneCircuitBreaker
per request path with the specifiedCircuitBreakerRule
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services.- Parameters:
factory
- a function that takes a request path and creates a newCircuitBreaker
.
-
newPerPathDecorator
public static Function<? super HttpClient,CircuitBreakerClient> newPerPathDecorator(Function<String, ? extends CircuitBreaker> factory, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Creates a new decorator that binds oneCircuitBreaker
per request path with the specifiedCircuitBreakerRuleWithContent
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services.- Parameters:
factory
- a function that takes a request path and creates a newCircuitBreaker
.
-
newPerHostAndMethodDecorator
@Deprecated public static Function<? super HttpClient,CircuitBreakerClient> newPerHostAndMethodDecorator(BiFunction<String, String, ? extends CircuitBreaker> factory, CircuitBreakerRule rule) Deprecated.Creates a new decorator that binds oneCircuitBreaker
per host andHttpMethod
with the specifiedCircuitBreakerRule
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services.- Parameters:
factory
- a function that takes a host+method and creates a newCircuitBreaker
.
-
newPerHostAndMethodDecorator
@Deprecated public static Function<? super HttpClient,CircuitBreakerClient> newPerHostAndMethodDecorator(BiFunction<String, String, ? extends CircuitBreaker> factory, CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Deprecated.Creates a new decorator that binds oneCircuitBreaker
per host andHttpMethod
with the specifiedCircuitBreakerRuleWithContent
.Since
CircuitBreaker
is a unit of failure detection, don't reuse the same instance for unrelated services.- Parameters:
factory
- a function that takes a host+method and creates a newCircuitBreaker
.
-
builder
Returns a newCircuitBreakerClientBuilder
with the specifiedCircuitBreakerRule
. -
builder
public static CircuitBreakerClientBuilder builder(CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent) Returns a newCircuitBreakerClientBuilder
with the specifiedCircuitBreakerRuleWithContent
. -
builder
public static CircuitBreakerClientBuilder builder(CircuitBreakerRuleWithContent<HttpResponse> ruleWithContent, int maxContentLength) Returns a newCircuitBreakerClientBuilder
with the specifiedCircuitBreakerRuleWithContent
and the specifiedmaxContentLength
which is required to determine aResponse
as a success or failure.- Throws:
IllegalArgumentException
- if the specifiedmaxContentLength
is equal to or less than0
-
doExecute
protected HttpResponse doExecute(ClientRequestContext ctx, HttpRequest req, CircuitBreakerCallback callback) throws Exception Description copied from class:AbstractCircuitBreakerClient
Invoked when theCircuitBreaker
is in closed state.- Specified by:
doExecute
in classAbstractCircuitBreakerClient<HttpRequest,
HttpResponse> - Throws:
Exception
-
newDecorator(CircuitBreakerMapping, CircuitBreakerRule)
withCircuitBreakerMapping.perHostAndMethod(BiFunction)
.