diff --git a/lib/amqp_client.js b/lib/amqp_client.js index 26a699e..f173c1d 100644 --- a/lib/amqp_client.js +++ b/lib/amqp_client.js @@ -229,6 +229,9 @@ AMQPClient.prototype.createSender = function(address, options) { throw new Error('Must connect before creating links'); } + address = address || this._defaultQueue; + options = options || {}; + var linkName = address + '_TX'; var linkPolicy = u.deepMerge({ options: { @@ -269,17 +272,11 @@ AMQPClient.prototype.createSender = function(address, options) { link.on(Link.ErrorReceived, function(err) { self.emit(AMQPClient.ErrorReceived, err); - - self._resolveDeferredSenderAttaches(linkName, err); - reject(err); }); link.on(Link.Detached, function(details) { debug('sender link detached: ' + (details ? details.error : 'No details')); self._attached[linkName] = undefined; - - self._resolveDeferredSenderAttaches(linkName, details); - reject(details); }); // return the attached link @@ -321,7 +318,9 @@ AMQPClient.prototype.createSender = function(address, options) { * @return {Promise} */ AMQPClient.prototype.createReceiver = function(address, options) { - if (!this._connection) { throw new Error('Must connect before receiving'); } + if (!this._connection) { + throw new Error('Must connect before creating links'); + } address = address || this._defaultQueue; options = options || {}; @@ -375,6 +374,10 @@ AMQPClient.prototype.createReceiver = function(address, options) { link.removeListener(Link.Attached, onAttached); self._attached[linkName] = link; + link.on(Link.ErrorReceived, function(err) { + self.emit(AMQPClient.ErrorReceived, err); + }); + link.on(Link.Detached, function(details) { debug('link detached: ' + (details ? details.error : 'No details')); self._attached[linkName] = undefined;