amqplib-easy
Advanced tools
Comparing version 4.5.0 to 5.0.0
18
API.md
@@ -67,3 +67,19 @@ - [`Create(amqpUrl)`](#createamqpurl-socketoptions---amqp) | ||
Defaults to an empty object | ||
- `parse`: (function) parse string content of message. Defaults to `JSON.parse` | ||
- `parse`: (function) a function which accepts raw message as an argument and returns decoded message content. | ||
Defaults to `jsonDecoder` which simply converts json encoded message content to `Object` by calling `JSON.parse`. | ||
The raw message passed as an argument have the following properties: | ||
```javascript | ||
{ | ||
content: Buffer, | ||
fields: Object, | ||
properties: Object | ||
} | ||
``` | ||
See | ||
[amqplib.channelConsume](http://www.squaremobius.net/amqp.node/channel_api.html#channel_consume) | ||
for more information. | ||
- `prefetch`: (number) of messages to fetch when consuming. Defaults to `1` | ||
@@ -70,0 +86,0 @@ - `arguments`: (object) containing any binding arguments for the queue. Defaults to `{}` |
@@ -37,2 +37,7 @@ 'use strict' | ||
function jsonDecoder (message) { | ||
if (!(message && message.content)) return null | ||
return JSON.parse(message.content.toString()) | ||
} | ||
diehard.register(cleanup) | ||
@@ -82,3 +87,3 @@ | ||
exchangeOptions: {durable: true}, | ||
parse: JSON.parse, | ||
parse: jsonDecoder, | ||
queueOptions: {durable: true}, | ||
@@ -125,3 +130,3 @@ prefetch: 1, | ||
try { | ||
msg.json = options.parse(msg.content.toString()) | ||
msg.payload = msg.json = options.parse(msg) | ||
return handler(msg, ch) | ||
@@ -128,0 +133,0 @@ } catch (err) { |
{ | ||
"name": "amqplib-easy", | ||
"version": "4.5.0", | ||
"version": "5.0.0", | ||
"description": "Simplified API for interacting with AMQP", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -55,4 +55,7 @@ /* globals it:false */ | ||
var name = cat.json.name | ||
var payload = cat.payload | ||
try { | ||
cat.should.have.properties(['content', 'fields', 'properties']) | ||
name.should.equal('Fred') | ||
payload.should.be.deepEqual(cat.json) | ||
done() | ||
@@ -59,0 +62,0 @@ } catch (err) { |
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
29003
652