Protect your RPCs with ServiceCall4j
A library for adding resiliency capabilities to your RPCs (Remote Procedure Calls) in a declarative way. The capabilities provided by this library are the following:
- Caching
- Monitoring
- Retrying
- Timeout
- Throttling
- Circuit Breaker
- Maven
<dependency>
<groupId>com.github.dimosr</groupId>
<artifactId>ServiceCall4j</artifactId>
<version>1.1.0</version>
</dependency>
- Gradle
compile 'com.github.dimosr:ServiceCall4j:1.1.0'
- Make sure the call you want to enhance implements the ServiceCall interface provided by Service-Call-4j:
public interface ServiceCall<REQUEST, RESPONSE> {
RESPONSE call(REQUEST request);
}
...
public class MyAdjustedHelloWorldCall implements ServiceCall<String, String> {
String call(String input) {
return "Hello " + input;
}
}
- Use the provided Builder to build your enhanced ServiceCall:
ServiceCall<String, String> enhancedHelloWorldCall = new ServiceCallBuilder<>(new MyAdjustedHelloWorldCall())
.withCircuitBreaker(15, 5, 3, 300)
.withCache(cache)
.withMonitoring((i, d) -> System.out.println("Duration: " + d.toMillis()))
.withTimeouts(Duration.ofMillis(1), TimeUnit.MILLISECONDS, Executors.newFixedThreadPool(10))
.withThrottling(100)
.withRetrying(false, 2)
.build();
- Perform your calls
String response = enhancedHelloWorldCall.call("World");
Check the project's Wiki for more documentation about how each capability can be used.
This Wiki also contains a FAQ section, describing what's the difference between this library and alternatives, such as Hystrix.
If you want a quick demo of how you can use the library, check this.