https://github.com/hadielmougy/shield
Fault tolerance library for java
https://github.com/hadielmougy/shield
circuit-breaker fault-tolerance java rate-limiting resiliency retry throttling timeout
Last synced: 10 months ago
JSON representation
Fault tolerance library for java
- Host: GitHub
- URL: https://github.com/hadielmougy/shield
- Owner: hadielmougy
- License: apache-2.0
- Created: 2020-02-08T22:42:02.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-03T13:45:11.000Z (about 2 years ago)
- Last Synced: 2023-12-03T14:31:06.514Z (about 2 years ago)
- Topics: circuit-breaker, fault-tolerance, java, rate-limiting, resiliency, retry, throttling, timeout
- Language: Java
- Homepage:
- Size: 145 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# shield
Fault tolerance library for java
## Usage
```xml
io.github.hadielmougy
shield
0.1.2
```
## Supported Interceptors
### Throttler
```java
final Supplier throttler = Shield.decorate(target)
.with(Interceptor.throttler()
.requests(1)
.maxWaitMillis(500))
.build();
```
### Rate limit
```java
final Supplier limiter = Shield.decorate(target)
.with(Interceptor.rateLimiter()
.rate(1))
.build();
```
### Timeout
```java
final Supplier decorated = Shield.decorate(target)
.with(Interceptor.timeout().waitMillis(1100))
.with(Interceptor.retry().delayMillis(1000).maxRetries(5))
.build();
```
### Retry
```java
final Retry retry = Interceptor.retry()
.delayMillis(500)
.maxRetries(3)
.onException(IllegalArgumentException.class);
```
### Circuit-breaker
```java
// count based
final Supplier comp = Shield.decorate( component)
.with(Interceptor.circuitBreaker()
.failureRateThreshold(50)
.slidingWindowSize(4)
.waitDurationInOpenState(Duration.ofSeconds(1))
.slidingWindowType(CircuitBreaker.WindowType.COUNT_BASED))
.build();
// time based
final Supplier comp = Shield.decorate(target)
.with(Interceptor.circuitBreaker()
.failureRateThreshold(50)
.slidingWindowSize(1)
.waitDurationInOpenState(Duration.ofSeconds(1))
.slidingWindowType(CircuitBreaker.WindowType.TIME_BASED))
.build();
```
### Assemble
```java
final Supplier decorated = Shield.decorate(() -> ...)
.with(retry)
.with(...)
.build();
decorated.get();
```