Package io.vrap.rmf.base.client.http
Class PolicyBuilder
java.lang.Object
io.vrap.rmf.base.client.http.PolicyBuilder
PolicyBuilder
The PolicyBuilder allows the combination of different policies for failing requests.
The order of policies matters. For example applying a timeout
before
withRetry(RetryPolicyBuilder)
retry} will time out across all requests whereas applying a timeout after the retry count
against every single request even the retried ones.
Retry
Retrying on HTTP status codes
final ApiHttpClient build = ClientBuilder.of() // ... .withPolicies(policyBuilder -> policyBuilder.withRetry(retry -> retry.maxRetries(3) .statusCodes(Arrays.asList(HttpStatusCode.SERVICE_UNAVAILABLE_503, HttpStatusCode.INTERNAL_SERVER_ERROR_500)))) .build();
See the test code.
Retrying specific exceptions
final ApiHttpClient build = ClientBuilder.of() // ... .withPolicies(policyBuilder -> policyBuilder .withRetry(retry -> retry.maxRetries(3).failures(singletonList(JsonException.class)))) .build();
See the test code.
Timeout
final ApiHttpClient build = ClientBuilder.of() // ... .withPolicies( policyBuilder -> policyBuilder.withTimeout(Duration.ofSeconds(10), TimeoutBuilder::withInterrupt)) .build();
See the test code.
Bulkhead
Implementation of a Queue to limit the number of concurrent requests handled by the client
final ApiHttpClient build = ClientBuilder.of() // ... .withPolicies(policyBuilder -> policyBuilder.withBulkhead(64, Duration.ofSeconds(10))) .build();
See the test code.
-
Constructor Summary
ConstructorDescriptionPolicyBuilder
(dev.failsafe.spi.Scheduler scheduler, List<dev.failsafe.Policy<ApiHttpResponse<byte[]>>> policies) PolicyBuilder
(List<dev.failsafe.Policy<ApiHttpResponse<byte[]>>> policies) -
Method Summary
Modifier and TypeMethodDescriptionbuild()
static dev.failsafe.Bulkhead<ApiHttpResponse<byte[]>>
bulkhead
(int maxConcurrency) static dev.failsafe.Bulkhead<ApiHttpResponse<byte[]>>
bulkhead
(int maxConcurrency, FailsafeConcurrencyBuilderOptions fn) static dev.failsafe.Bulkhead<ApiHttpResponse<byte[]>>
static dev.failsafe.Bulkhead<ApiHttpResponse<byte[]>>
bulkhead
(int maxConcurrency, Duration maxWaitTime, FailsafeConcurrencyBuilderOptions fn) static PolicyBuilder
of()
static dev.failsafe.Timeout<ApiHttpResponse<byte[]>>
static dev.failsafe.Timeout<ApiHttpResponse<byte[]>>
timeout
(Duration duration, FailsafeTimeoutBuilderOptions fn) withBulkhead
(int maxConcurrency) withBulkhead
(int maxConcurrency, FailsafeConcurrencyBuilderOptions fn) withBulkhead
(int maxConcurrency, Duration maxWaitTime) withBulkhead
(int maxConcurrency, Duration maxWaitTime, FailsafeConcurrencyBuilderOptions fn) withPolicy
(dev.failsafe.Policy<ApiHttpResponse<byte[]>> policy) withRetry
(int maxRetries) withRetry
(RetryPolicyBuilder retryPolicyBuilder) withScheduler
(dev.failsafe.spi.Scheduler scheduler) withScheduler
(ExecutorService scheduler) withScheduler
(ScheduledExecutorService scheduler) withTimeout
(Duration duration) withTimeout
(Duration duration, FailsafeTimeoutBuilderOptions fn)
-
Constructor Details
-
PolicyBuilder
public PolicyBuilder() -
PolicyBuilder
-
PolicyBuilder
public PolicyBuilder(dev.failsafe.spi.Scheduler scheduler, List<dev.failsafe.Policy<ApiHttpResponse<byte[]>>> policies)
-
-
Method Details
-
withScheduler
-
withScheduler
-
withScheduler
-
withRetry
-
withRetry
-
withRetry
-
withRetry
-
withRetry
-
withBulkhead
-
withBulkhead
-
withBulkhead
-
withBulkhead
public PolicyBuilder withBulkhead(int maxConcurrency, Duration maxWaitTime, FailsafeConcurrencyBuilderOptions fn) -
withTimeout
-
withTimeout
-
withPolicy
-
build
-
of
-
timeout
-
timeout
public static dev.failsafe.Timeout<ApiHttpResponse<byte[]>> timeout(Duration duration, FailsafeTimeoutBuilderOptions fn) -
bulkhead
-
bulkhead
public static dev.failsafe.Bulkhead<ApiHttpResponse<byte[]>> bulkhead(int maxConcurrency, Duration maxWaitTime) -
bulkhead
public static dev.failsafe.Bulkhead<ApiHttpResponse<byte[]>> bulkhead(int maxConcurrency, FailsafeConcurrencyBuilderOptions fn) -
bulkhead
public static dev.failsafe.Bulkhead<ApiHttpResponse<byte[]>> bulkhead(int maxConcurrency, Duration maxWaitTime, FailsafeConcurrencyBuilderOptions fn)
-