amqp.channel
Advanced tools
Comparing version 0.0.8 to 0.0.9
var noop = function(){}, | ||
Promise = require('bluebird'); | ||
amqp = require('amqplib'), | ||
Promise = require('bluebird'); | ||
@@ -8,3 +9,3 @@ module.exports = function createChannel(url, assertions, log){ | ||
return require('amqplib').connect(url).then(openChannel, log.error); | ||
return amqp.connect(url).then(openChannel); | ||
@@ -18,12 +19,9 @@ function openChannel(connection) { | ||
process.once('SIGTERM', close); | ||
return connection.createConfirmChannel().then(assertChannelMethods, close); | ||
return connection.createConfirmChannel().then(setupChannel, close); | ||
} | ||
function assertChannelMethods(channel) { | ||
function setupChannel(channel) { | ||
var setup = []; | ||
for (var fn in assertions) { | ||
setup.push.apply(setup, assertions[fn].map(function invocation(args){ | ||
log.info('- Channel %s(%j)', fn, args); | ||
return channel[fn].apply(channel, args); | ||
})); | ||
for (var method in assertions) { | ||
setup.push.apply(setup, assertions[method].map(applyToChannel(method))); | ||
}; | ||
@@ -36,6 +34,11 @@ | ||
return Promise.all(setup) | ||
.then(returnChannel) | ||
.catch(closeChannel); | ||
return Promise.all(setup).then(returnChannel, closeChannel); | ||
function applyToChannel(method){ | ||
return function invocation(args){ | ||
log.info('- Channel %s(%j)', method, args); | ||
return channel[method].apply(channel, args); | ||
} | ||
} | ||
function returnChannel(){ | ||
@@ -49,9 +52,9 @@ log.info('- Channel setup complete'); | ||
channel.close(); | ||
throw error; | ||
return Promise.reject(error); | ||
} | ||
function blocked(isBlocked){ | ||
var state = isBlocked ? 'blocked' : 'unblocked'; | ||
var level = isBlocked ? 'warn' : 'info'; | ||
return function changeState(){ | ||
var state = isBlocked ? 'blocked' : 'unblocked'; | ||
var level = isBlocked ? 'warn' : 'info'; | ||
log[level]('- Channel %s', state); | ||
@@ -58,0 +61,0 @@ channel.isBlocked = isBlocked; |
{ | ||
"name": "amqp.channel", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "A simplified way to setup an AMQP connection/channel with amqplib", | ||
"main": "channel.js", | ||
"dependencies": { | ||
"amqplib": "^0.3.0", | ||
"bluebird": "^2.3.2" | ||
"amqplib": "^0.3.1", | ||
"bluebird": "^2.9.13" | ||
}, | ||
@@ -10,0 +10,0 @@ "devDependencies": { |
@@ -161,3 +161,3 @@ /*jslint nodejs: true, expr: true*/ | ||
getChannel = stubChannel(amqpUrl, assertions, npmlog); | ||
getChannel.then(test).catch(test); | ||
getChannel.then(test, test); | ||
}); | ||
@@ -164,0 +164,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14729
207
0
Updatedamqplib@^0.3.1
Updatedbluebird@^2.9.13