Giter Club home page Giter Club logo

shepherd's Introduction

Maven Central

Shepherd

Allows to balance set of POJO objects in distributed environment. May be extremely useful if you need to scale your service horizontally by distributing jobs/worker among instances.

It relies on Kafka Rebalance Protocol extending org.apache.kafka.clients.consumer.internals.AbstractCoordinator.

Thereby it inherits well-known Kafka heartbeat mechanics and its config parameters (heartbeat.interval.ms, session.timeout.ms)

Usage

     
/* Specify Kafka servers (will be used for rebalance only) */
KafkaPushFarm kafkaPushFarm = new KafkaPushFarm(kafkaBootstrapServers);

/* Join the pasture to herd of specific name and class */
Pasture<String> skyNet = kafkaPushFarm.addBreedingPasture("SkyNet", String.class,
    /* listener that will be use to update local assignment to this pasture */
    (population, version, generation, isLeader) -> {
    logger.info("Assigned leader={} version={} [{}]", isLeader, version, population);
    });

/* set global population that will be distributed among all members of this herd */
skyNet.getShepherd().setPopulation(population, version.intValue())

skyNet.start();

Modules

common

Contains basic interfaces

Farm - entry point to join herd

Pasture - represents local pasture

Shepherd - allows to set up global population for herd

PastureListener - listen for any changes in population on local pasture

kafka

Kafka based implementation

kafka-example

Demo example that reads messages from Kafka aggregate them in local repository and distribute among service instances You need to have Docker in the running environment.

  1. run StartKafkaContainer
  2. run several times JoinPasture
  3. add messages to "population" topic

shepherd's People

Contributors

kptfh avatar github-actions[bot] avatar

Watchers

Igor Yova avatar Olexii Ratych avatar Andrey Mizurov avatar Vladislav Sidorovich avatar  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.