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.
$ npm install waterline-rabbitmq --save
// config/connections.jsmoduleexportsconnections =regularPostgres:// ...rabbitCluster:adapter: 'waterline-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;
For Models that you'd like to be able to publish and subscribe to, add the
waterline-rabbitmq connection to the relevant Models, and define a
// api/models/Messagemoduleexports =connection: 'rabbitCluster' 'regularPostgres'routingKey: 'stream' 'parentMessage'attributes:title: 'string'body: 'string'stream:model: 'stream'parentMessage:model: 'message'// ...;
routingKey determines how messages are routed to RabbitMQ queues. Consider
Message object from above:
title: 'yo dawg'body: 'I heard you like messages'stream: 'random'parentMessage: 1234
[ 'stream', 'parentMessage' ]
routingKey would generate a RabbitMQ
Routing Key with the value
The primary key datatype for the persistence store defaults to
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.jsmoduleexportsrabbitmq =pkFormat: 'string';
.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" is a nice way of saying "only use these methods if you know what you're doing".
Open a rabbit.js
socket to your favorite model.
|options.name||worker name (must match that of some 'PUSH' socket)||yes|