<commit_before>= Spring Boot Demo of Resilience4j

This demo shows how to use the fault tolerance library https://github.com/resilience4j/resilience4j[Resilience4j] in a Spring Boot application.

== Gradle

Add the Spring Boot Starter of Resilience4j to your compile dependency:

```
repositories {
	maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
	mavenCentral()
}


dependencies {
	compile('io.github.resilience4j:resilience4j-spring-boot:0.9.0-SNAPSHOT')
	compile('io.github.resilience4j:resilience4j-metrics:0.9.0-SNAPSHOT') // Optional
	compile('io.github.resilience4j:resilience4j-prometheus:0.9.0-SNAPSHOT') // Optional
	compile('io.prometheus:simpleclient_spring_boot:0.0.21') // Optional
}
```

== Spring AOP

The demo shows how to use the `CircuitBreaker` annotation to make your Spring Boot application more fault tolerant. You can either annotate a class in order to protect all public methods or just some specific methods.
For example:

[source,java]
----
@CircuitBreaker(backend = "backendA")
@Component(value = "backendAConnector")
public class BackendAConnector implements Connector {
    ...
}
----

== Functional style

But you can still use a functional programming style. For example:

[source,java]
----
@Service(value = "businessBService")
public class BusinessBService implements BusinessService  {

    public Try<String> methodWithRecovery() {
        Try.CheckedSupplier<String> backendFunction = CircuitBreaker.decorateCheckedSupplier(circuitBreaker, () -> backendBConnector.failure());
        return Try.of(backendFunction)
                .recover((throwable) -> recovery(throwable));
    }

    private String recovery(Throwable throwable) {
        // Handle exception and invoke fallback
        return "Hello world from recovery";
    }

}
----

== RxJava

You can even apply a CircuitBreaker to any RxJava `Flowable` or `Observable`.

[source,java]
----
public Observable<String> methodWhichReturnsAStream() {
    return backendBConnector.methodWhichReturnsAnObservable()
            .timeout(1, TimeUnit.SECONDS)
            .lift(CircuitBreakerOperator.of(circuitBreaker));
}
----

== Monitoring<commit_msg>Updated to Resilience4j 0.9.0<commit_after>= Spring Boot Demo of Resilience4j

This demo shows how to use the fault tolerance library https://github.com/resilience4j/resilience4j[Resilience4j] in a Spring Boot application.

== Gradle

Add the Spring Boot Starter of Resilience4j to your compile dependency:

```
repositories {
	maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
	mavenCentral()
}


ext{
	resilience4jVersion = '0.9.0'
}

dependencies {
	compile("io.github.resilience4j:resilience4j-spring-boot:${resilience4jVersion}")
	compile("io.github.resilience4j:resilience4j-metrics:${resilience4jVersion}") // Optional
	compile("io.github.resilience4j:resilience4j-prometheus:${resilience4jVersion}") // Optional
	compile('io.prometheus:simpleclient_spring_boot:0.0.21') // Optional
	compile("io.vavr:vavr-jackson:0.9.0")
}
```

== Spring AOP

The demo shows how to use the `CircuitBreaker` annotation to make your Spring Boot application more fault tolerant. You can either annotate a class in order to protect all public methods or just some specific methods.
For example:

[source,java]
----
@CircuitBreaker(backend = "backendA")
@Component(value = "backendAConnector")
public class BackendAConnector implements Connector {
    ...
}
----

== Functional style

But you can still use a functional programming style. For example:

[source,java]
----
@Service(value = "businessBService")
public class BusinessBService implements BusinessService  {

    public Try<String> methodWithRecovery() {
        Supplier<String> backendFunction = CircuitBreaker.decorateSupplier(circuitBreaker, () -> backendBConnector.failure());
        return Try.of(backendFunction)
                .recover((throwable) -> recovery(throwable));
    }

    private String recovery(Throwable throwable) {
        // Handle exception and invoke fallback
        return "Hello world from recovery";
    }

}
----

== RxJava

You can even apply a CircuitBreaker to any RxJava `Flowable` or `Observable`.

[source,java]
----
public Observable<String> methodWhichReturnsAStream() {
    return backendBConnector.methodWhichReturnsAnObservable()
            .timeout(1, TimeUnit.SECONDS)
            .lift(CircuitBreakerOperator.of(circuitBreaker));
}
----

== Monitoring
{'fraction_non_alphanumeric': 0.11101083032490974, 'fraction_numerical': 0.012409747292418772, 'mean_word_length': 4.258600237247924, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4456355', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1334, 'n_words': 338}