|
|
|
@ -6,6 +6,7 @@ var util = require('util'); |
|
|
|
|
|
|
|
var consumer = function( queue, options ){ |
|
|
|
this._queue = queue; |
|
|
|
this._options = new client(options); |
|
|
|
this._client = new client(options); |
|
|
|
this._client.connect(); |
|
|
|
|
|
|
|
@ -15,11 +16,11 @@ var consumer = function( queue, options ){ |
|
|
|
|
|
|
|
var self = this; |
|
|
|
this._client.on('message', function(message){ |
|
|
|
|
|
|
|
|
|
|
|
if( typeof self._callback == 'function' ){ |
|
|
|
self._callback(message); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( self._consume ){ |
|
|
|
self.get(self._timeout); |
|
|
|
} |
|
|
|
@ -41,6 +42,10 @@ consumer.prototype.get = function( timeout ){ |
|
|
|
} |
|
|
|
|
|
|
|
consumer.prototype.consume = function( callback ){ |
|
|
|
if(!this._client){ |
|
|
|
this._client = client(this._options); |
|
|
|
this.client.connect(); |
|
|
|
} |
|
|
|
if( typeof(callback) == 'function' ){ |
|
|
|
this._callback = callback; |
|
|
|
} |
|
|
|
@ -50,6 +55,8 @@ consumer.prototype.consume = function( callback ){ |
|
|
|
|
|
|
|
consumer.prototype.stopConsuming = function(){ |
|
|
|
this._consume = false; |
|
|
|
this._client.close(); |
|
|
|
this._client = null; |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = consumer; |
|
|
|
module.exports = consumer; |