Git Product home page Git Product logo

loadbalancer4java's Introduction

loadbalancer4java

Build Status

Software load balancer for CompletableFutures in Java, that is meant as a simple replacement for Hystrix and Ribbon when using Java 8.

It provides the following features:

  • Load balancing
  • Fault tolerance
  • Protocol independent

Still needs to be pushed to Nexus:

<dependency>
    <groupId>dk.nversion</groupId>
    <artifactId>loadbalancer4java</artifactId>
    <version>0.1/version>
</dependency>

How to Use It

Create a List or Array with your endpoints, then create a new LoadBalancer with the preferred configuration:

String[] urls = new String[] { "url1", "url2", "url3" };

LoadBalancer loadBalancer = LoadBalancer.builder()
    // Return indexes for 3 endpoints and do it in a round robin fashion
    .setEndpointCount(urls.length)
    .setPolicy(LoadBalancerPolicy.ROUND_ROBIN)
    // 10 failures in 30 seconds will take the endpoint out of rotation for 60 seconds
    .setMaxFailureRate(10, 30, TimeUnit.SECONDS, 60, TimeUnit.SECONDS)
    // Try to call the endpoints 2 times more if the first call fails
    .setRetryCount(2)
    .build();

Wrap the call where you call your backend with the loadBalancer and use the CompletableFuture exactly the same way as before:

// CompletableFuture<String> future = backend.call(urls[0], "request1");
CompletableFuture<String> loadBalancedFuture = loadBalancer.wrap((index, retryCount) -> {
    return backend.call(urls[index], "request1");
});

loadBalancedFuture.whenComplete((response, ex) -> {
    if(ex == null) {
        // This is
    } else {
        // Handle Exception
    }
});

TODO

  • Implement caching support like Guava CacheBuilder
  • Implement queuing of calls

loadbalancer4java's People

Contributors

tlbdk avatar

Stargazers

Andrew NS Yeow avatar NIHAL RAI avatar

Watchers

 avatar James Cloos avatar

Forkers

nihalrai wl21st

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.