amqplib-easy
Advanced tools
Comparing version 3.2.0 to 3.2.1
55
index.js
@@ -39,2 +39,15 @@ 'use strict'; | ||
function createChannel() { | ||
return connect().then(function (connection) { | ||
return BPromise.resolve(connection.createChannel()); | ||
}); | ||
} | ||
function createChannelDisposer() { | ||
return createChannel() | ||
.disposer(function (channel) { | ||
return channel.close(); | ||
}); | ||
} | ||
function consume(queueConfig, handler) { | ||
@@ -61,6 +74,3 @@ var options = defaults({}, queueConfig || {}, { | ||
return connect() | ||
.then(function (conn) { | ||
return conn.createChannel(); | ||
}) | ||
return createChannel() | ||
.then(function (ch) { | ||
@@ -129,7 +139,5 @@ ch.prefetch(options.prefetch); | ||
function publish(queueConfig, key, json, messageOptions) { | ||
return connect() | ||
.then(function (conn) { | ||
return conn.createChannel(); | ||
}) | ||
.tap(function (ch) { | ||
return BPromise.using( | ||
createChannelDisposer(), | ||
function (ch) { | ||
if (queueConfig.exchange === null || queueConfig.exchange === undefined) { | ||
@@ -141,19 +149,17 @@ throw new Error('Client tries to publish to an exchange while exchange name is not undefined.'); | ||
queueConfig.queue ? ch.assertQueue(queueConfig.queue, queueConfig.queueOptions || {durable: true}) : BPromise.resolve() | ||
]); | ||
}) | ||
.then(function (ch) { | ||
return ch.publish(queueConfig.exchange, | ||
key, | ||
toBuffer(json), | ||
messageOptions || queueConfig.messageOptions || {persistent: true}); | ||
}); | ||
]) | ||
.then(function () { | ||
return ch.publish(queueConfig.exchange, | ||
key, | ||
toBuffer(json), | ||
messageOptions || queueConfig.messageOptions || {persistent: true}); | ||
}); | ||
} | ||
); | ||
} | ||
function sendToQueue(queueConfig, json, messageOptions) { | ||
return connect() | ||
.then(function (conn) { | ||
// optional future =improvement - maybe we should keep the channel open? | ||
return conn.createChannel(); | ||
}) | ||
.then(function (ch) { | ||
return BPromise.using( | ||
createChannelDisposer(), | ||
function (ch) { | ||
return ch.assertQueue(queueConfig.queue, queueConfig.queueOptions || {durable: true}) | ||
@@ -167,3 +173,4 @@ .then(function () { | ||
}); | ||
}); | ||
} | ||
); | ||
} | ||
@@ -170,0 +177,0 @@ |
{ | ||
"name": "amqplib-easy", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Simplified API for interacting with AMQP", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
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
21540
363
2