forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue ReactiveX#74: adding ratpack docs and fixing some configuration…
… issues * adding docs and fixing some configuration issues, closes ReactiveX#74 * removing unused import
- Loading branch information
Showing
8 changed files
with
235 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
= resilience4j-ratpack | ||
|
||
== Gradle | ||
|
||
``` | ||
repositories { | ||
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' } | ||
mavenCentral() | ||
} | ||
|
||
|
||
dependencies { | ||
compile('io.github.resilience4j:resilience4j-ratpack:0.9.0-SNAPSHOT') | ||
} | ||
``` | ||
|
||
== Promises | ||
|
||
Ratpack promises provide the means by which an application can become fully non-blocking and asynchronous. | ||
Resilience4j provides transformers that can be applied to Promises. This is ideal when promising a value | ||
that is coming from some sort of I/O source. | ||
|
||
=== CircuitBreaker | ||
|
||
You can easily apply a CircuitBreaker to any Ratpack Promise. | ||
|
||
[source,java] | ||
---- | ||
public Promise<String> methodWhichReturnsAPromise() { | ||
return backendBConnector.methodWhichReturnsAPromise() | ||
.transform(CircuitBreakerTransformer.of(circuitBreaker).recover(t -> "recovered")); | ||
} | ||
---- | ||
|
||
=== Retry | ||
|
||
You can easily apply a Retry to any Ratpack Promise. | ||
|
||
[source,java] | ||
---- | ||
public Promise<String> methodWhichReturnsAPromise() { | ||
return backendBConnector.methodWhichReturnsAPromise() | ||
.transform(RetryTransformer.of(retry).recover(t -> "recovered")); | ||
} | ||
---- | ||
|
||
=== RateLimiter | ||
|
||
You can easily apply a RateLimiter to any Ratpack Promise. | ||
|
||
[source,java] | ||
---- | ||
public Promise<String> methodWhichReturnsAPromise() { | ||
return backendBConnector.methodWhichReturnsAPromise() | ||
.transform(RateLimiterTransformer.of(rateLimiter).recover(t -> "recovered")); | ||
} | ||
---- | ||
|
||
== Guice AOP | ||
|
||
Guice provides method interception capabilities. Here are provided some annotations which allow | ||
methods returning promises, completion stage, and normal values, to be operated on. | ||
|
||
=== CircuitBreaker | ||
The demo shows how to use the `CircuitBreaker` annotation to make your Ratpack 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(name = "backendA", recovery = MyRecoveryFunction.class) | ||
@Singleton | ||
public class BackendAConnector implements Connector { | ||
... | ||
} | ||
---- | ||
Where `MyRecoveryFunction` is implements `io.github.resilience4j.ratpack.RecoveryFunction` and provides | ||
a fallback value that is returned when the circuit breaker identified by `name` is open. | ||
|
||
=== Retry | ||
TODO | ||
Retry will be supported once the concept of a RetryRegistry is in place. | ||
|
||
=== RateLimiter | ||
The demo shows how to use the `RateLimiter` annotation to make your Ratpack 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] | ||
---- | ||
@RateLimiter(name = "backendA", recovery = MyRecoveryFunction.class) | ||
@Singleton | ||
public class BackendAConnector implements Connector { | ||
... | ||
} | ||
---- | ||
Where `MyRecoveryFunction` is implements `io.github.resilience4j.ratpack.RecoveryFunction` and provides | ||
a fallback value that is returned when the rate limiter rate limit identified by `name` is exceeded. | ||
|
||
== Functional style | ||
|
||
You can still use a functional programming style for CircuitBreaker, Retry, and RateLimiter. For example: | ||
|
||
[source,java] | ||
---- | ||
@Singleton | ||
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"; | ||
} | ||
} | ||
---- | ||
|
||
== Monitoring | ||
TODO | ||
Ratpack provides the concept of a health check. See https://ratpack.io/manual/current/api/ratpack/health/HealthCheckHandler.html for details. | ||
CircuitBreaker, RateLimiter, and Retry health checks have not been implemented yet. | ||
When implemented they should function similarly to the spring boot health checks. | ||
|
||
== Configuration | ||
|
||
You must install the `ResilienceModule` if you want to use AOP so that the method interceptors work. | ||
You can optionally configure your CircuitBreakers, RateLimiters, and Retries in your Guice Module as well. | ||
|
||
Note: If you don't register a `CircuitBreakerRegistry` or `RateLimiterRegistry`, the defaults | ||
will be used when using AOP. | ||
|
||
For example | ||
|
||
[source,java] | ||
---- | ||
public class MyModule extends AbstractModule { | ||
@Override | ||
protected void configure() { | ||
CircuitBreakerConfig config = CircuitBreakerConfig.custom(); | ||
bind(CircuitBreakerRegistry.class).toInstance(CircuitBreakerRegistry.of(config); | ||
install(ResilienceModule.class); | ||
} | ||
} | ||
---- | ||
|
||
== CircuitBreaker Event Monitoring | ||
TODO | ||
Handlers for displaying the last X CircuitBreaker, Ratelimiter, or Retry events are not yet implemented. | ||
When implemented they should function similarly to the spring boot management endpoints. | ||
|
||
== License | ||
|
||
Copyright 2017 Dan Maas | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
...ratpack/src/main/java/io/github/resilience4j/ratpack/internal/CircuitBreakerProvider.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
...4j-ratpack/src/main/java/io/github/resilience4j/ratpack/internal/RateLimiterProvider.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.