queue-commander
v0.2.0
Published
Convenient interface for amqp lib
Downloads
6
Readme
Queue Commander
AMQP for dummies
npm install queue-commander
Usage
var QueueCommander = require('queue-commander');
var qc = new QueueCommander(settings());
function settings() {
return {
consumeJobResults: false, // default: true
prefix: 'staging_', // prepend queue with prefix
};
}
- declare queue (queue-schema.js)
qc.registerQueue('fruits', {durable: false}); // configure queue here
- declare channel(s) (queue-schema.js)
var apple = qc.channel({name: 'apple', input: 'fruits'}); // RPC
var orange = qc.channel({name: 'orange', input: 'fruits', output: 'results'}); // remote job
- on server (server.js)
apple.onServer(function(args, done, ack) {
ack(true);
setTimeout(function() {
done(null, 'yummy ' + args.name);
}, 1000);
});
- on client: remote call (client-rpc.js)
// register call
var sendToAppleQueue = apple.onClient();
// make a call
sendToAppleQueue({name: 'golden apple'}).then(function(response) {
console.log(response); // yummy golden apple
});
- on client: remote job (client-job.js)
// register job
var sendToOrangeQueue = orange.onClient(function(err, res, next){
console.log(res); // yummy sweet orange
next();
});
// post a job
sendToOrangeQueue({name: 'sweet orange'}); // note that callback will not be called