npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rabbitmq_minionpool

v0.0.10

Published

A RabbitMQ minionpool

Downloads

3

Readme

About

rabbitmq_minionpool is a specialized minionpool that will let you process tasks coming in via RabbitMQ (it uses de node-amqp library).

How it works

You need to provide some key pieces of information:

  • An exchange name (the "worker's exchange" from now on)
  • A queue name (the "worker's queue" from now on)
  • A routing key (will default to the queue name if missing)
  • A retry timeout for failed operations.

When you create a rabbitmq_minionpool, 2 exchanges are created in the rabbitmq server:

  • The exchange name specified (let's say "workers").
  • A dead letter exchange for failed operations, automatically named as the original exchange name and with a suffix ".retry" (e.g: "workers.retry").

Both exchanges are created as 'topic', durable', 'not passive'. Also, the channel is set in 'confirm' mode (in case you want to publish your own messages).

Also, some queues are created:

  • The worker's queue name specified in the given worker's exchange, and binded to the given routing key. The pool will subscribe to this queue to get messages. This queue is created with the arguments:

  • x-dead-letter-exchange = exchangeName.retry

  • x-dead-letter-routing-key = queueName.retry

  • Another queue in the dead letter exchange, so failed operations can get there. This queue is created with the arguments:

  • x-dead-letter-exchange = exchangeName

  • x-dead-letter-routing-key = queueName

  • x-message-ttl = retryTimeout

Both queue will subscribe to 'routingKey' but also to their respectively queueName. So they will get messages directed to 'routingKey' but will also get dead-lettered messages (and these messages will reach the correct consumer, the one that rejected them.)

When messages are routed to the specified worker's queue, the minionpool will dispatch them to the minions. Each minion will get access to the message and the queue object where it came from. If the minion rejects the message, the message will be routed to the queue in the dead letter exchange with the given TTL. When the TTL expires, the message will go back automatically to the original queue, where the operation can be retried.

Example

var options = {
  name: 'test',
  debug: true,
  concurrency: 5,
  logger: console.log,
  mqOptions: {
    host: '127.0.0.1',
    login: 'guest',
    password: 'guest',
    authMechanism: 'AMQPLAIN',
    vhost: '/',
    reconnect: true,
    reconnectBackoffStrategy: 'linear',
    reconnectExponentialLimit: 120000,
    reconnectBackoffTime: 1000,
    exchangeName: 'workers',  // Will also create workers.retry
    queueName: 'myWorkers',   // Will also create myWorkers.retry
    routingKey: 'myWorkers',  // Optional. Equals to queueName if missing
    retryTimeout: 20000
  },
  minionTaskHandler: function(msg, state, callback) {
    var payload = msg.payload;
    var headers = msg.headers;
    var deliveryInfo = msg.deliveryInfo;
    var message = msg.message;
    var queue = msg.queue;
    console.log('got task: %s', util.inspect(payload));
    // See the node-amqp doc for more info.
    message.reject(); // or message.acknowledge();
    callback(undefined, state);
  },
  poolEnd: function() {
    process.exit(0);
  }
};

var pool = new minionsMod.RabbitMqMinionPool(options);
process.on('SIGINT', function() {
  pool.end();
});
pool.start();

Tips

  • Design your apps and architecture in such a way that operations are idempotent to max the benefits of this.

Using multiple cores

In the case of having rabbitmq and mysql workers, it's very useful to take advantage of multicore cpu's. For this, you can use taskset and launch multiple minionpool instances on different cores.