Skip to content

Latest commit

 

History

History
 
 

riptide-failsafe

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Riptide: Failsafe

Valves

Build Status Coverage Status Javadoc Release Maven Central License

Riptide: Failsafe adds Failsafe support to Riptide. It offers retries and a circuit breaker to every remote call.

Example

Http.builder()
    .plugin(new FailsafePlugin(scheduler)
            .withRetryPolicy(retryPolicy)
            .withCircuitBreaker(circuitBreaker))
    .build();

Features

  • seamlessly integrates Riptide with Failsafe

Dependencies

  • Java 8
  • Riptide Core
  • Failsafe

Installation

Add the following dependency to your project:

<dependency>
    <groupId>org.zalando</groupId>
    <artifactId>riptide-failsafe</artifactId>
    <version>${riptide.version}</version>
</dependency>

Configuration

The failsafe plugin will not perform retries nor apply circuit breakers unless they were explicitly configured:

Http.builder()
    .plugin(new FailsafePlugin(Executors.newScheduledThreadPool(20))
            .withRetryPolicy(new RetryPolicy()
                    .retryOn(SocketTimeoutException.class)
                    .withDelay(25, TimeUnit.MILLISECONDS)
                    .withMaxRetries(4))
            .withCircuitBreaker(new CircuitBreaker()
                    .withFailureThreshold(3, 10)
                    .withSuccessThreshold(5)
                    .withDelay(1, TimeUnit.MINUTES)))
    .build();

Please visit the Failsafe readme in order to see possible configurations. Make sure you check out zalando/failsafe-actuator for a seemless integration of Failsafe and Spring Boot:

@Autowired
private CircuitBreaker breaker;

Http.builder()
    .plugin(new FailsafePlugin(Executors.newScheduledThreadPool(20))
            .withRetryPolicy(new RetryPolicy()
                    .retryOn(SocketTimeoutException.class)
                    .withDelay(25, TimeUnit.MILLISECONDS)
                    .withMaxRetries(4))
            .withCircuitBreaker(breaker))
    .build();

Usage

Given the failsafe plugin was configured as shown in the last section: A regular call like the following will now be retried up to 4 times if the server did not respond within the socket timeout.

http.get("/users/me")
    .dispatch(series(),
        on(SUCCESSFUL).call(User.class, this::greet),
        anySeries().call(problemHandling()))

Handling certain technical issues automatically, like socket timeouts, is quite useful. But there might be cases where the server did respond, but the response indicates something that is worth retrying, e.g. a 409 Conflict or a 503 Service Unavailable. Use the predefined retry route that comes with the failsafe plugin:

http.get("/users/me")
    .dispatch(series(),
        on(SUCCESSFUL).call(User.class, this::greet),
        on(CLIENT_ERROR).dispatch(status(),
            on(CONFLICT).call(retry())),
        on(SERVER_ERROR).dispatch(status(),
            on(SERVICE_UNAVAILABLE).call(retry())),
        anySeries().call(problemHandling()))

Getting Help

If you have questions, concerns, bug reports, etc., please file an issue in this repository's Issue Tracker.

Getting Involved/Contributing

To contribute, simply open a pull request and add a brief description (1-2 sentences) of your addition or change. For more details, check the contribution guidelines.