Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/umran/consistent-hash-exchange
An internal message exchange that distributes asynchronous requests into serializable, but concurrently running queues using consistent hashing as the routing mechanism
https://github.com/umran/consistent-hash-exchange
Last synced: 2 days ago
JSON representation
An internal message exchange that distributes asynchronous requests into serializable, but concurrently running queues using consistent hashing as the routing mechanism
- Host: GitHub
- URL: https://github.com/umran/consistent-hash-exchange
- Owner: umran
- Created: 2019-05-20T22:59:22.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-05-28T17:46:22.000Z (over 5 years ago)
- Last Synced: 2024-11-07T05:26:15.103Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node Consistent Hash Exchange
An internal message exchange that distributes asynchronous requests into serializable, but concurrently running queues using consistent hashing as the routing mechanism.
## Guarantees
Since the exchange uses consistent hashing, every job enqueued with the same routingKey ends up in the same queue. That way, partial ordering of requests based on their routing key can be achieved while maintaing a desired level of concurrency.
## Usage
```javascript
const Exchange = require('consistent-hash-exchange')// define a task
const task = async args => {
// do something async and return results
const result = await db.write(args)return result
}// create a new exchange that binds 20 concurrent queues each
// running the task defined above in series
const exchange = new Exchange(task, 20)// enqueue a job
const replyToken = Math.floor(Math.random() * 10)
const routingKey = 'some routing key'
const args = { name: 'some name' }
exchange.enqueue(replyToken, routingKey, args)// listen to the reply event that will be fired when
// the job has been processed
exchange.once(replyToken, result => {
console.log(result)
})
```