Elector - simple zookeeper based leader election
Features
- emits
leader
event when instance has been elected a leader - emits
follower
event when instance is a follower - check using
elector.isLeader
Install
npm install --save elector
Usage
const Elector = const elector = host: 'localhost:2818' // alternatively pass in zookeeper client// const elector = new Elector(new zookeeper.createClient('localhost:2818')) // connects to zookeeper and starts the election processelector elector elector // leave the election and closes zookeeper connection// do this to leave the election quickly// elector.disconnect()
License
MIT