jackrabbit
Advanced tools
Comparing version 4.0.3 to 4.1.0
@@ -76,3 +76,7 @@ var amqp = require('amqplib/callback_api'); | ||
var keys = options.keys || [options.key]; | ||
keys.forEach(bindKey); | ||
bindKeys(keys) | ||
.then(function emitBoundEvent(res) { | ||
newQueue.emit('bound') | ||
}) | ||
.catch(bail); | ||
} | ||
@@ -91,8 +95,16 @@ }); | ||
function bindKey(key) { | ||
channel.bindQueue(newQueue.name, emitter.name, key, {}, onBind); | ||
} | ||
// return a promise when all keys are bound | ||
function bindKeys(keys) { | ||
return Promise.all(keys.map(bindKey)); | ||
function onBind(err, ok) { | ||
if (err) return bail(err); | ||
// returns a promise when a key is bound | ||
function bindKey(key) { | ||
var deferred = Promise.defer(); | ||
channel.bindQueue(newQueue.name, emitter.name, key, {}, function onBind(err, ok) { | ||
if (err) return deferred.reject(err); | ||
return deferred.resolve(ok); | ||
}); | ||
return deferred.promise; | ||
} | ||
} | ||
@@ -99,0 +111,0 @@ } |
{ | ||
"name": "jackrabbit", | ||
"version": "4.0.3", | ||
"version": "4.1.0", | ||
"description": "Easy RabbitMQ for node", | ||
@@ -5,0 +5,0 @@ "readme": "https://github.com/hunterloftis/jackrabbit/blob/master/readme.md", |
@@ -53,1 +53,9 @@ # Jackrabbit | ||
``` | ||
If using Docker-Machine on OSX: | ||
``` | ||
$ docker-machine start | ||
$ eval "$(docker-machine env default)" | ||
$ docker-compose run jackrabbit npm test | ||
``` |
var assert = require('chai').assert; | ||
var amqp = require('amqplib/callback_api'); | ||
var exchange = require('../lib/exchange'); | ||
var uuid = require('node-uuid'); | ||
@@ -83,7 +84,36 @@ describe('exchange', function() { | ||
}); | ||
describe('with key bindings', function () { | ||
before(function(done) { | ||
amqp.connect(process.env.RABBIT_URL, function(err, conn) { | ||
assert.ok(!err); | ||
this.exchange = exchange('test.topic.bindings', 'topic') | ||
.connect(conn) | ||
.once('connected', done); | ||
}.bind(this)); | ||
}); | ||
it('emits a "bound" event when all routing keys have been bound to the queue', function (done) { | ||
var keys = 'abcdefghijklmnopqrstuvwxyz'.split(''); | ||
var finalKey = keys[keys.length - 1]; | ||
var queue = this.exchange.queue({ keys: keys }); | ||
var message = uuid.v4(); | ||
queue.consume(function (data, ack, nack, msg) { | ||
assert.equal(message, data); | ||
assert.equal(msg.fields.routingKey, finalKey); | ||
ack(); | ||
done(); | ||
}); | ||
queue.once('bound', function () { | ||
this.exchange.publish(message, { key: finalKey }); | ||
}.bind(this)); | ||
}); | ||
}); | ||
}); | ||
describe('#publish', function() { | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25879
741
61
31