An open API service indexing awesome lists of open source software.

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

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();
```