Giter Club home page Giter Club logo

dropwizard-resilience4j-bundle's Introduction

dropwizard-resilience4j-bundle Build Status

Lightweight integration of Resilience4J into Dropwizard configuration and metrics. Does not provide any other services - actually using all the Resilience4j stuff is up to you. The R4J documentation is pretty good.

Currently this only supports Circuit Breakers and Retries, but supporting more R4j features is welcome.

User Guide

In your POM...

<dependency>
    <groupId>com.expediagroup</groupId>
    <artifactId>dropwizard-resilience4j-bundle</artifactId>
    <version>2.0.0</version> <!-- use latest -->
</dependency>

In your config.yaml...

resilience4j:
    circuitBreakers:
        - name: myFancyCircuitBreaker
          waitDurationInOpenState: 30s
          failureRateThreshold: 10
        ## Add as many as you want
        ## All parameters are optional except `name`, defaults are documented in CircuitBreakerConfiguration.java
        ##- name: anotherCircuitBreaker
    retryConfigurations:
      - name: exponentialRandomizedBackoffRetry
              maxAttempts: 4
              intervalFunction:
                type: exponentialRandomBackoff
                initialInterval: 10ms
                multiplier: 2.5
                randomizationFactor: 0.5
      ## Add as many as you want
      ## most parameters are optional, but `intervalFunction` is required. Several are available, see `IntervalFunctionFactory` for full list, 
      ## but currently: constant, randomized, exponentialBackoff, exponentialRandomBackoff

Add to your application's Config class:

@NotNull
private Resilience4jConfiguration resilience4j;

Configured R4J objects are automatically wired into Dropwizard Metrics, and also into HK2 using the name from the YAML. You can also retrieve them from the configuration class...

val breaker = myAppConfig.getResilience4j().getCircuitBreakerRegistry().circuitBreaker("myFancyCircuitBreaker");
val retry = myAppConfig.getResilience4j().getRetryRegistry().retry("myFancyRetry");

If you want to configure the objects in code before they are created, you can pass a handler into the bundle when it's constructed.

@Override
public void initialize(Bootstrap<RatesEngineConfiguration> bootstrap) {
    bootstrap.addBundle(new Resilience4jBundle<>(TestConfiguration::getResilience4j,
                                                 (breakerName, breakerBuilder) -> {
                                                     //breakerName is what was configured in YAML
                                                     //breakerBuilder can be modified as desired
                                                     breakerBuilder.ignoreExceptions(IOException.class);
                                                 },
                                                 (retryName, retryBuilder) -> {
                                                     //retryName is what was configured in YAML
                                                     //retryBuilder can be modified as desired
                                                     retryBuilder.retryOnResult(myRetryPredicate);
                                                 }));
}

dropwizard-resilience4j-bundle's People

Contributors

breischl avatar desumera avatar eleduardo avatar eocantu avatar jordanjlopez avatar renovate[bot] avatar thejc avatar

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.