https://github.com/hyperlink/elector
simple zookeeper based leader election
https://github.com/hyperlink/elector
leader-election nodejs zookeeper
Last synced: 8 months ago
JSON representation
simple zookeeper based leader election
- Host: GitHub
- URL: https://github.com/hyperlink/elector
- Owner: hyperlink
- License: mit
- Created: 2017-06-15T19:58:47.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-05-29T04:45:41.000Z (about 6 years ago)
- Last Synced: 2025-09-25T19:12:30.417Z (9 months ago)
- Topics: leader-election, nodejs, zookeeper
- Language: JavaScript
- Size: 161 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Elector - simple zookeeper based leader election
[](https://travis-ci.org/hyperlink/elector)
[](https://greenkeeper.io/)
[](https://badge.fury.io/js/elector)
## Features
* emits `leader` event when instance has been elected a leader
* emits `follower` event when instance is a follower
* check using `elector.isLeader`
## Install
```bash
npm install --save elector
```
## Usage
```javascript
const Elector = require('elector')
const elector = new 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 process
elector.connect()
elector.on('leader', function () {
console.log('I am the supreme leader worship me!')
})
elector.on('follower', function () {
console.log('I am but a lowly follower :(')
})
// leave the election and closes zookeeper connection
// do this to leave the election quickly
// elector.disconnect()
```
## License
MIT