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

sails-rabbitmq

v0.12.3

Published

sails-rabbitmq adapter for Sails / Waterline

Downloads

11

Readme

RabbitMQ Adapter

NPM version Build status Dependency Status Code Climate

RabbitMQ Adapter for Sails and Waterline (AMQP 0.9). Implements the Waterline pubsub interface. The RabbitMQ Adapter does not support persistence on its own, and should always be used with another adapter, such as sails-mongo or sails-postgresql. This module is maintained in collaboration with Michigan Community College Association.

Install

$ npm install sails-rabbitmq --save

Configure

1. Setup Connection

// config/connections.js
module.exports.connections = {
  regularPostgres: {
    // ...
  },
  rabbitCluster: {
    adapter: 'sails-rabbitmq',

    /**
     * The url of your rabbitmq installation
     */
    url: 'amqp://localhost:5672',

    /**
     * Define how persistence is managed. 'true' will subscribe to all queues
     * and persist models that are published as messages. 'false' will do
     * nothing. This lets you turn off the persistence worker feature on the
     * Sails.js web server, and enable it in separate worker processes.
     */
    persistence: true
  }
};

2. Setup Models

For Models that you'd like to be able to publish and subscribe to, add the sails-rabbitmq connection to the relevant Models, and define a routingKey.

// api/models/Message
module.exports = {
  connection: [ 'rabbitCluster', 'regularPostgres' ],
  routingKey: [ 'stream', 'parentMessage' ],
  attributes: {
    title: 'string',
    body: 'string',
    stream: {
      model: 'stream'
    },
    parentMessage: {
      model: 'message'
    }
    // ...
  }
};

routingKey

The routingKey determines how messages are routed to RabbitMQ queues. Consider an example Message object from above:

{
  title: 'yo dawg',
  body: 'I heard you like messages',
  stream: 'random',
  parentMessage: 1234
}

The [ 'stream', 'parentMessage' ] routingKey would generate a RabbitMQ Routing Key with the value random.1234.

3. Set Primary Key Format

The primary key datatype for the persistence store defaults to 'integer'. You may need to change this, for example mongodb uses strings for their primary key. This is optional depending upon your persistence store.

// config/rabbitmq.js
module.exports.rabbitmq = {
    pkFormat: 'string'
};

Usage

.create(values, callback)

.update(criteria, values, callback)

The .create() and .update() methods can be called per usual on RabbitMQ-enabled models. RabbitMQ dispatches a message to an available Persistence Worker, wherein the object is created or updated by the persistence connection (e.g. regularPostgres above), and returned to the provided callback (or Promise).

Low-level API

"Low-level" is a nice way of saying "only use these methods if you know what you're doing".

Model.getSubscribeSocket(options)

Open a rabbit.js SUBSCRIBE socket to your favorite model.

| @param | @description | required | |:---|:---|:---| | options.where | search criteria | no |

Example

Message.getSubscribeSocket({ where: { stream: 'myStream' } })
  .then(function (socket) {
    socket.on('data', function (data) {
      var message = JSON.parse(data);
      // see, I told you it was "low-level"
      
      // ...
    });
  });

Model.getWorkerSocket(options)

| @param | @description | required | |:---|:---|:---| | options.name | worker name (must match that of some 'PUSH' socket) | yes |

Message.getWorkerSocket({ name: 'encryptionWorker' })
  .then(function (socket) {
    socket.on('data', function (data) {
      var message = JSON.parse(data);
      // ...

      socket.ack()
    });
  });

License

MIT

Maintained By