Skip to content

Instantly share code, notes, and snippets.

@b3tts32
Created October 12, 2017 15:30
Show Gist options
  • Save b3tts32/e2d5acb47d48ed67b4269c338fb7d35b to your computer and use it in GitHub Desktop.
Save b3tts32/e2d5acb47d48ed67b4269c338fb7d35b to your computer and use it in GitHub Desktop.
var context = require('rabbit.js').createContext('amqp://localhost');
var async = require('async');
//var sub = context.socket('SUBSCRIBE', {noCreate: true});
var worker = context.socket('WORKER', {
prefetch: 1
});
worker.setEncoding('utf8');
worker.connect('hello');
queue = async.queue(function(task, next) {
var data;
data = task.data;
console.log(data);
worker.ack();
next();
}, 1);
worker.once('data', function(data) {
console.log("Begin Bill read: " + new Date);
})
worker.on('data', function(data) {
worker.pause();
queue.push({
data: data
});
});
queue.drain = function() {
worker.resume();
};
worker.on('end', function() {
console.log("End Bill read: " + new Date);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment