Created
October 12, 2017 15:30
-
-
Save b3tts32/e2d5acb47d48ed67b4269c338fb7d35b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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