dropwizard-resilience4j-bundle

Lightweight Resilience4j integration for Dropwizard

License

License

Categories

Categories

DropWizard Container Microservices resilience4j Application Layer Libs Distributed Applications
GroupId

GroupId

com.expediagroup
ArtifactId

ArtifactId

dropwizard-resilience4j-bundle
Last Version

Last Version

2.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

dropwizard-resilience4j-bundle
Lightweight Resilience4j integration for Dropwizard
Project URL

Project URL

https://github.com/homeaway/dropwizard-resilience4j-bundle
Source Code Management

Source Code Management

https://github.com/homeaway/dropwizard-resilience4j-bundle

Download dropwizard-resilience4j-bundle

How to add to project

<!-- https://jarcasting.com/artifacts/com.expediagroup/dropwizard-resilience4j-bundle/ -->
<dependency>
    <groupId>com.expediagroup</groupId>
    <artifactId>dropwizard-resilience4j-bundle</artifactId>
    <version>2.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.expediagroup/dropwizard-resilience4j-bundle/
implementation 'com.expediagroup:dropwizard-resilience4j-bundle:2.1.0'
// https://jarcasting.com/artifacts/com.expediagroup/dropwizard-resilience4j-bundle/
implementation ("com.expediagroup:dropwizard-resilience4j-bundle:2.1.0")
'com.expediagroup:dropwizard-resilience4j-bundle:jar:2.1.0'
<dependency org="com.expediagroup" name="dropwizard-resilience4j-bundle" rev="2.1.0">
  <artifact name="dropwizard-resilience4j-bundle" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.expediagroup', module='dropwizard-resilience4j-bundle', version='2.1.0')
)
libraryDependencies += "com.expediagroup" % "dropwizard-resilience4j-bundle" % "2.1.0"
[com.expediagroup/dropwizard-resilience4j-bundle "2.1.0"]

Dependencies

compile (14)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-annotations jar
com.google.code.findbugs : jsr305 jar
io.dropwizard : dropwizard-core jar
io.dropwizard : dropwizard-jackson jar
io.dropwizard : dropwizard-jersey jar
io.dropwizard : dropwizard-util jar
io.dropwizard.metrics : metrics-core jar
io.github.resilience4j : resilience4j-circuitbreaker jar 1.4.0
io.github.resilience4j : resilience4j-metrics jar 1.4.0
io.github.resilience4j : resilience4j-retry jar 1.4.0
io.vavr : vavr jar 0.10.2
javax.validation : validation-api jar 1.1.0.Final
org.glassfish.hk2 : hk2-api jar 2.6.1
org.hibernate : hibernate-validator jar

test (5)

Group / Artifact Type Version
io.dropwizard : dropwizard-testing jar
javax.ws.rs : javax.ws.rs-api jar 2.1.1
junit : junit jar 4.13
org.apache.commons : commons-lang3 jar
org.assertj : assertj-core jar

Project Modules

There are no modules declared in this project.

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.dropwizard</groupId>
    <artifactId>dropwizard-resilience4j-bundle</artifactId>
    <version>3.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);
                                                 }));
}
com.expediagroup

HomeAway

Versions

Version
2.1.0
2.0.1
2.0.0