Code Monkey home page Code Monkey logo

service-call-4j's Introduction

Protect your RPCs with ServiceCall4j

Build Status Coverage Status SonarQube Analysis Maven Central

Service-Call-4j

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

Install

  • 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'

Getting Started

  1. 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;
	}
}
  1. 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();
  1. Perform your calls
String response = enhancedHelloWorldCall.call("World");

More Info

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.

service-call-4j's People

Contributors

dimosr avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.