Socket
Socket
Sign inDemoInstall

consistent-hash-exchange

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    consistent-hash-exchange

An internal message exchange that distributes asynchronous requests into serializable, but concurrently running queues using consistent hashing as the routing mechanism


Version published
Weekly downloads
2
Maintainers
1
Install size
4.89 kB
Created
Weekly downloads
 

Readme

Source

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

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)
})

Keywords

FAQs

Last updated on 28 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc