sails-hook-amqplib

0.0.7 • Public • Published

sails-hook-amqplib

sails hook for easy amqplib integration.

By default jobs are defined in api/workers. They should look like this:

// api/queues/MyTestQueue.js
module.exports = {
    name: 'my:test', // not required, by default equals filename without .js
    contentType:'json',
    process(content) { // required
        console.log(content)
        return Promise.resolve()
    },
    durable: true, // optional, defaults to true
    prefetch: 3 // optional, defaults to 10
}

A config file is also required, it should look something like this:

module.exports.amqplib = {
    url:process.env.AMQP_URL
}

Once this is set up, you can create a new job like this:

sails.hooks.amqplib.publish('my:queue', 'foo bar');
sails.hooks.amqplib.publish('my:queue', { foo: 'bar' });

Also you can get pure amqplib connection or create new pure amqplib channel at any moment:

sails.hooks.amqplib.getConnection()
    .then(connection => console.log(connection));
sails.hooks.amqplib.createChannel()
    .then(channel => createChannel.prefetch(100))

Readme

Keywords

none

Package Sidebar

Install

npm i sails-hook-amqplib

Weekly Downloads

0

Version

0.0.7

License

ISC

Last publish

Collaborators

  • dilame