amqplib-easy
Advanced tools
Comparing version 3.0.2 to 3.1.0
@@ -27,2 +27,4 @@ - [`Create(amqpUrl)`](#createamqpurl---amqp) | ||
[amqplib](http://www.squaremobius.net/amqp.node/doc/channel_api.html#toc_60). | ||
If message is a `Buffer`, it is sent as is, otherwise, it is serialized to JSON | ||
and sent. | ||
@@ -33,2 +35,4 @@ ### `AMQP.sendToQueue(config, message, [options])` -> `Promise` | ||
[amqplib](http://www.squaremobius.net/amqp.node/doc/channel_api.html#toc_60). | ||
If message is a `Buffer`, it is sent as is, otherwise, it is serialized to JSON | ||
and sent. | ||
@@ -35,0 +39,0 @@ ### `AMQP.connect()` -> `Promise` |
11
index.js
@@ -22,2 +22,9 @@ 'use strict'; | ||
function toBuffer(obj) { | ||
if (obj instanceof Buffer) { | ||
return obj; | ||
} | ||
return new Buffer(JSON.stringify(obj)); | ||
} | ||
diehard.register(cleanup); | ||
@@ -136,3 +143,3 @@ | ||
key, | ||
new Buffer(JSON.stringify(json)), | ||
toBuffer(json), | ||
messageOptions || queueConfig.messageOptions || {persistent: true}); | ||
@@ -153,3 +160,3 @@ }); | ||
queueConfig.queue, | ||
new Buffer(JSON.stringify(json)), | ||
toBuffer(json), | ||
messageOptions || queueConfig.messageOptions || {persistent: true} | ||
@@ -156,0 +163,0 @@ ); |
{ | ||
"name": "amqplib-easy", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "Simplified API for interacting with AMQP", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=0.10", | ||
"npm": "^2" | ||
}, | ||
"scripts": { | ||
@@ -11,0 +7,0 @@ "lint": "eslint --ignore-path .gitignore .", |
@@ -34,3 +34,3 @@ /*globals it:false*/ | ||
describe('should publish, sendToQueue and receive', function () { | ||
describe('', function () { | ||
var cancel; | ||
@@ -44,3 +44,3 @@ | ||
it('', function (done) { | ||
it('should handle buffers reasonably', function (done) { | ||
var catCount = 0; | ||
@@ -68,2 +68,32 @@ amqp.consume( | ||
return BPromise.all([ | ||
amqp.publish({ exchange: 'cat' }, 'found.tawny', new Buffer('{ "name": "Sally" }')), | ||
amqp.sendToQueue({ queue: 'found_cats' }, new Buffer('{ "name": "Fred" }')) | ||
]); | ||
}) | ||
.catch(done); | ||
}); | ||
it('should publish, sendToQueue and receive', function (done) { | ||
var catCount = 0; | ||
amqp.consume( | ||
{ | ||
exchange: 'cat', | ||
queue: 'found_cats', | ||
topics: [ 'found.*' ] | ||
}, | ||
function (cat) { | ||
var name = cat.json.name; | ||
try { | ||
/*eslint-disable no-unused-expressions*/ | ||
(name === 'Sally' || name === 'Fred').should.be.ok; | ||
/*eslint-enable no-unused-expressions*/ | ||
if (++catCount === 2) { | ||
done(); | ||
} | ||
} catch (err) { done(err); } | ||
} | ||
) | ||
.then(function (c) { | ||
cancel = c; | ||
return BPromise.all([ | ||
amqp.publish({ exchange: 'cat' }, 'found.tawny', { name: 'Sally' }), | ||
@@ -70,0 +100,0 @@ amqp.sendToQueue({ queue: 'found_cats' }, { name: 'Fred' }) |
@@ -16,2 +16,2 @@ 'use strict'; | ||
diehard.listen({timeout: 8000}); | ||
diehard.listen(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
18782
324