Code Monkey home page Code Monkey logo

spring-boot-resilience4j-retry's Introduction

Resilience4j Retry: Building Fault-Tolerant Spring Boot Applications

For complete understanding of Resilience4j Retry module and how we can use it inside the Spring Boot application you can checkout our blog.

Blog Link: Resilience4j Retry: Building Fault-Tolerant Spring Boot Applications

spring-boot-resilience4j-retry

A simple app highlighting how we can implement retry mechanism using Resilience4j in Spring Boot

App Overview

This is a simple app wherein we are fetching the movie details based on the movie id. The movie details are fetched from external service that is called using the Spring Rest Template. For simplicity, we have created a mock controller which acts as a external service for returning the movie details.

Retry Scenarios

We have created a single controller endpoint which accepts movie id as path parameter and query parameter retryType which accepts predefined set of values to mimic the different retry examples.

Acceptable Values

For Path Parameter - Movie Id

a. 1 or 2 - Mock controller returns valid movie information
b. 3 - Mock controller returns HTTP status code 404
c. 4 or any other numeric value - Mock controller returns null which leads to MovieNotFound Exception

For Query Parameter - retryType

Different retry instances are defined inside the application.yml. To mimic different retry scenarios use:
a. simple-retry: simpleRetry retry instance will be triggered
b. retry-on-exception: retryOnException retry instance will be triggered.
c. retry-on-exception-predicate: retryBasedOnExceptionPredicate retry instance will be triggered.
d. retry-on-conditional-predicate: retryBasedOnConditionalPredicate retry instance will be triggered.
e. retry-using-exponential-backoff: retryUsingExponentialBackoff retry instance will be triggered.
f. retry-using-randomized-wait: retryUsingRandomizedWait retry instance will be triggered.
g. retry-with-fallback: simpleRetry retry instance will be triggered and fallback method logic will be executed in this case.
h. retry-with-custom-config: customRetryConfig retry instance defined in RetryConfiguration class will be triggered.
i. retry-with-event-details: retryWithEventDetails retry instance will be triggered.

cURL Commands

Check the application logs in order to get the better understanding of different retry scenarios.

1. Simple Retry

curl 'http://localhost:8080/movies/3?retryType=simple-retry'

2. Retry on Configured Exceptions

curl 'http://localhost:8080/movies/3?retryType=retry-on-exception'

3. Retry on Exception Predicate

curl 'http://localhost:8080/movies/4?retryType=retry-on-exception-predicate'

4. Retry on Conditional Predicate

curl 'http://localhost:8080/movies/4?retryType=retry-on-conditional-predicate'

5. Retry Using Exponential Backoff

curl 'http://localhost:8080/movies/3?retryType=retry-using-exponential-backoff'

6. Retry Using Randomized Wait

curl 'http://localhost:8080/movies/3?retryType=retry-using-randomized-wait'

7. Retry with Fallback

curl 'http://localhost:8080/movies/4?retryType=retry-with-fallback'

8. Retry with Custom Retry Configuration

curl 'http://localhost:8080/movies/3?retryType=retry-with-custom-config'

9. Retry with Event Details

curl 'http://localhost:8080/movies/3?retryType=retry-with-event-details'

spring-boot-resilience4j-retry's People

Stargazers

 avatar

Watchers

 avatar

Forkers

aanshumann

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.