Git Product home page Git Product logo

camel-consul-leader's Introduction

camel-consul-leader

Circle CI Coverage Status

About

This is an Apache Camel utility that will provide cluster wide leader election of a clustered route by using the ControlBus component to start and stop the route based on leader election in Consul.

Usage

Maven POM

Add the following to your POM:

<dependency>
  <groupId>com.github.jhberges</groupId>
  <artifactId>camel-consul-leader</artifactId>
  <version>${camel-consul-leader.version}</version>
</dependency>

Where ${camel-consul-leader.version} is a property containing a released version of this artifact.

The artifact is published via Sonatype's OSS repository manager, and is synced to Maven Central from there. Hence propagation to central is on it's terms.

Mark the route to be controlled as non-autostartup

For example:

from("direct:la-di-da")
  .routeId("routeId")
  .autoStartup(false);

Initialize in your Camel app

ConsulLeaderElector.Builder
  .forConsulHost(consulUrl)             // For example https://consul.acme.com:8500
  .usingBasicAuth(username, password)   // If using basic-auth. Optional
  .controllingRoute("routeId")          // The route id to start and stop, based on leadership
  .inCamelContext(camelContext)         // The Camel context to operate in
  .usingServiceName("service-name")     // camel-consul-leader will register the key: service/<service-name>/leader and use this for session-locking
  .usingExecutor(executor)              // Execution service to use
  .usingLockDelay(consulLockDelay)      // "lock-delay" (see https://www.consul.io/docs/internals/sessions.html for details)
  .usingTimeToLive(consulSessionTTL)    // TimeToLive for the session (in seconds)
  .usingRetryStrategy(countOfTries,     // Strategy for creating session in Consul
                      retryPeriodBase,  // Default: tries=5, period=2 (seconds), backOff=1.5
                      backOffMultiplier)
  .allowingIslandMode(flag)             // If set to `false` the component will terminate your app with `System.exit(1);`
  .withPollConfiguration(initialDelay, 
                          pollInterval) // Time before, and between polls (seconds)
  .build();                             // Registers and starts the service

Island-mode

If the configured Consul URL cannot be reached, the app will start up as "an island".

This means that the app will assume it's a leader and just start the route.

Time and polling

The following time values are hardcoded at the time of writing:

  • Consul polling interval: intervall for checking the leadership status in the KV store. Set to 5 seconds.
  • Session TTL: timeout for the session lock. Set to 8 seconds.

References

Contributing

Contributions are welcome and are preferred in form of normal pull requests.

Code format

This repo prefers TABs over SPACEs, and generally follow more or less normal Sun Java conventions :-p

camel-consul-leader's People

Contributors

jhberges avatar mortenaa avatar mrsteffenjo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

camel-consul-leader's Issues

Cluster lock fails during start

  1. Consul sessionKey=Optional[0fef6935-50e1-a2f6-978d-cda039dac10a]
  2. 2016/02/10 11:37:06 [WARN] consul.kvs: Rejecting lock of service/xxx/leader due to lock-delay until 2016-02-10 11:37:18.682462267 +0000 UTC
  3. 2016/02/10 11:37:23 [ERR] http: Request PUT /v1/kv/service/xxx/leader?acquire=0fef6935-50e1-a2f6-978d-cda039dac10a, error: invalid session "0fef6935-50e1-a2f6-978d-cda039dac10a" from=172.17.0.23:48013

Support periodic step-down from leadership

For example if the route under control has been idle for N MINUTES, then stop route and step down.

This would make it possible to keep other aspiring leaders somewhat lukewarm.

Redundant and repetitive logging

Example from running in "island" mode:

2016-01-28 09:58:43.915  INFO 12476 --- [pool-1-thread-1] j.c.consul.leader.ConsulLeaderElector    : Starting route=poll.es
2016-01-28 09:58:43.916  INFO 12476 --- [pool-1-thread-1] o.a.camel.spring.SpringCamelContext      : Route: poll.es started and consuming from: Endpoint[timer://pollTimer?period=1000]
2016-01-28 09:58:43.916  INFO 12476 --- [pool-1-thread-1] o.a.c.c.controlbus.ControlBusProducer    : ControlBus task done [${camelContext.startRoute("poll.es")}] with result -> void

This repeats for each poll

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.