amqp-wrapper
Advanced tools
Comparing version 7.0.0-es6.5 to 7.0.0
@@ -82,2 +82,4 @@ const amqp = require('amqplib'); | ||
} | ||
// NB: amqplib's ConfirmChannel.publish does not actually return a promise. | ||
// See https://www.squaremobius.net/amqp.node/channel_api.html#flowcontrol | ||
return promisify(this.channel.publish.bind(this.channel, this.config.exchange, routingKey, Buffer.from(message), options))(); | ||
@@ -120,4 +122,4 @@ } | ||
try { | ||
var messagePayload = message.content.toString(); | ||
var parsedPayload = JSON.parse(messagePayload); | ||
const messagePayload = message.content.toString(); | ||
const parsedPayload = JSON.parse(messagePayload); | ||
handleMessage(parsedPayload, done); | ||
@@ -124,0 +126,0 @@ } catch (error) { |
@@ -13,6 +13,7 @@ async function bindRoutingKeys (channel, exchange, queueName, keys = []) { | ||
var qName = queue.name + (queue.options.deadLetterQueueSuffix || '-dead-letter'); | ||
const qName = queue.name + (queue.options.deadLetterQueueSuffix || '-dead-letter'); | ||
await channel.assertExchange(queue.options.deadLetterExchange, 'topic', {}); | ||
await channel.assertQueue(qName, {}); | ||
await bindRoutingKeys(channel, queue.options.deadLetterExchange, qName, queue.options.deadLetterExchangeRoutingKey || queue.routingKey); | ||
await bindRoutingKeys(channel, queue.options.deadLetterExchange, qName, | ||
queue.options.deadLetterExchangeRoutingKey || queue.routingKey); | ||
} | ||
@@ -25,3 +26,3 @@ | ||
exports.setupForConsume = async function (channel, params) { | ||
var { queue } = params; | ||
const { queue } = params; | ||
await maybeDeclareDeadLetters(channel, queue); | ||
@@ -28,0 +29,0 @@ await channel.assertQueue(queue.name, queue.options); |
{ | ||
"name": "amqp-wrapper", | ||
"version": "7.0.0-es6.5", | ||
"version": "7.0.0", | ||
"engines": { | ||
@@ -41,3 +41,3 @@ "node": ">= 8" | ||
"sandboxed-module": "^0.3.0", | ||
"semistandard": "^14.0.1", | ||
"semistandard": "^14.1.0", | ||
"sinon": "^7.3.2", | ||
@@ -44,0 +44,0 @@ "sinon-chai": "^3.3.0" |
amqp-wrapper | ||
---------------- | ||
A simple wrapper to https://github.com/squaremo/amqp.node. | ||
> Simple consuming and publishing from/to a RabbitMQ broker. | ||
@@ -9,18 +9,6 @@ Allows you to have any number of publish queues, one consume queue and to perform | ||
- You can specify a queue which will be declared (made to exist). This will be | ||
the queue from which you will consume. | ||
- If you specify a routing key for the queue, then a binding will be set up | ||
(I.e. a mapping that tells AMQP to route message with that routing key to that | ||
queue on the exchange you have specified). | ||
- Any options you specify at the per-queue level are passed directly through to | ||
ch.assertQueue in the underlying library. If you want to set up dead lettering, | ||
for example, then pass the `deadLetterExchange` option which will cause the queue | ||
to be declared with that dead letter exchange. | ||
- `deadLetterExchange` and `deadLetterRoutingKey` are special options, in that | ||
as well as being passed through to `ch.assertQueue()` to ensure the dead | ||
lettering behaviour occurs, a queue will be declared of the same name with | ||
the `-dead-letter` suffix, with a binding declared on the dead letter | ||
exchange for the dead letter routing key. This means that when a message is dead | ||
lettered on that queue it will have somewhere to go without you having to set up | ||
a dead lettering queue manually. | ||
- Auto queue declaration & binding | ||
- Dead lettering support | ||
- Easy publishing | ||
- Simple promise based API | ||
@@ -37,7 +25,7 @@ # Example usage | ||
routingKey: process.env.AMQP_ROUTING_KEY, // If supplied, queue is bound to | ||
// this key (or keys) on the exchange. NB Can be an array of string or just | ||
// this key (or keys) on the exchange. NB Can be an array of strings or just | ||
// a string. | ||
options: {/* ... */} // options passed to ch.assertQueue() in wrapped lib. | ||
options: {/* ... */} // Advanced: options passed to ch.assertQueue() in wrapped `amqplib`. | ||
}, | ||
// Set the QOS/prefetch. | ||
// Set the QOS/prefetch (defaults to 1) | ||
prefetch: 100 | ||
@@ -54,3 +42,4 @@ }; | ||
var handleMessage = function(message, callback) { | ||
//... | ||
//... Do things | ||
callback(); | ||
}; | ||
@@ -74,2 +63,26 @@ // You must call: | ||
# Details | ||
- You can specify a queue which will be declared (made to exist). This will be | ||
the queue from which you will consume. | ||
- If you specify a routing key for the queue, then a binding will be set up | ||
(I.e. a mapping that tells AMQP to route message with that routing key to that | ||
queue on the exchange you have specified). | ||
- Any options you specify at the per-queue level are passed directly through to | ||
ch.assertQueue in the underlying library. If you want to set up dead lettering, | ||
for example, then pass the `deadLetterExchange` option which will cause the queue | ||
to be declared with that dead letter exchange. | ||
- `deadLetterExchange` and `deadLetterRoutingKey` are special options, in that | ||
as well as being passed through to `ch.assertQueue()` to ensure the dead | ||
lettering behaviour occurs, a queue will be declared of the same name with | ||
the `-dead-letter` suffix, with a binding declared on the dead letter | ||
exchange for the dead letter routing key. This means that when a message is dead | ||
lettered on that queue it will have somewhere to go without you having to set up | ||
a dead lettering queue manually. | ||
# Thanks to | ||
This is a wrapper to https://github.com/squaremo/amqp.node (`amqplib`). | ||
# Tests | ||
@@ -98,3 +111,3 @@ Start a rabbit server, preferably a 'throw away' one with fresh state. You can | ||
**Kind**: global class | ||
**Kind**: global class | ||
@@ -130,3 +143,3 @@ * [AMQPWrapper](#AMQPWrapper) | ||
**Kind**: instance method of [<code>AMQPWrapper</code>](#AMQPWrapper) | ||
**Kind**: instance method of [<code>AMQPWrapper</code>](#AMQPWrapper) | ||
<a name="AMQPWrapper+close"></a> | ||
@@ -137,3 +150,3 @@ | ||
**Kind**: instance method of [<code>AMQPWrapper</code>](#AMQPWrapper) | ||
**Kind**: instance method of [<code>AMQPWrapper</code>](#AMQPWrapper) | ||
<a name="AMQPWrapper+publish"></a> | ||
@@ -144,9 +157,9 @@ | ||
**Kind**: instance method of [<code>AMQPWrapper</code>](#AMQPWrapper) | ||
**Kind**: instance method of [<code>AMQPWrapper</code>](#AMQPWrapper) | ||
| Param | Type | | ||
| --- | --- | | ||
| routingKey | <code>string</code> | | ||
| message | <code>object</code> \| <code>string</code> | | ||
| options | <code>object</code> | | ||
| routingKey | <code>string</code> | | ||
| message | <code>object</code> \| <code>string</code> | | ||
| options | <code>object</code> | | ||
@@ -168,8 +181,8 @@ <a name="AMQPWrapper+consume"></a> | ||
**Kind**: instance method of [<code>AMQPWrapper</code>](#AMQPWrapper) | ||
**Kind**: instance method of [<code>AMQPWrapper</code>](#AMQPWrapper) | ||
| Param | Type | | ||
| --- | --- | | ||
| handleMessage | <code>function</code> | | ||
| options | <code>object</code> | | ||
| handleMessage | <code>function</code> | | ||
| options | <code>object</code> | | ||
@@ -176,0 +189,0 @@ # License |
require('chai').use(require('sinon-chai')); | ||
require('chai').use(require('chai-as-promised')); | ||
require('chai').use(require('dirty-chai')); |
@@ -34,5 +34,5 @@ const SandboxedModule = require('sandboxed-module'); | ||
}); | ||
it('should call the callback successfully', function (done) { | ||
it('should return a promise', async function () { | ||
var amqp = new AMQP(config.good); | ||
amqp.connect().then(() => done()); | ||
expect(amqp.connect()).to.be.fulfilled(); | ||
}); | ||
@@ -39,0 +39,0 @@ it('should declare your queue, and bind it', async function () { |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
23508
1
204
13
397
1