Class PolicyBuilder

java.lang.Object
io.vrap.rmf.base.client.http.PolicyBuilder

public class PolicyBuilder extends Object

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.