diff --git a/lib/kestrelConsumer.js b/lib/kestrelConsumer.js index b7e37be..49245b6 100644 --- a/lib/kestrelConsumer.js +++ b/lib/kestrelConsumer.js @@ -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; \ No newline at end of file +module.exports = consumer; diff --git a/package.json b/package.json index 759d561..1841f6b 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "node-kestrel" - , "version": "0.0.1" + , "version": "0.0.2" , "description": "Kestrel client module for NodeJS" - , "homepage": "http://www.blangdon.com/" + , "homepage": "https://github.com/brettlangdon/node-kestrel" , "keywords": ["kestrel", "client", "messaging", "queue"] - , "author": "brett_langdon " + , "author": "brett_langdon (http://brett.is)" , "contributors": [ { "name": "brett_langdon", "email": "brett@blangdon.com" } ]