amqplib 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,7 @@ jobs:
20
20
 
21
21
  strategy:
22
22
  matrix:
23
- node-version: [10.x, 12.x, 14.x, 16.x]
23
+ node-version: [10.x, 12.x, 14.x, 16.x, 18.x]
24
24
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
25
25
 
26
26
  steps:
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Change log for amqplib
2
2
 
3
+ ## Changes in v0.9.1
4
+
5
+ git log v0.9.0..v0.9.1
6
+
7
+ * Assorted readme changes
8
+ * Use Array.prototype.push.apply instead of concat in Mux ([PR
9
+ 658](https://github.com/squaremo/amqp.node/pull/658), thank you
10
+ @Uzlopak and @kibertoad)
11
+ * Use Map instead of Object for BaseChannel.consumers ([PR
12
+ 660](https://github.com/squaremo/amqp.node/pull/660), thank you
13
+ @Uzlopak)
14
+ * Delete consumer callback after cancellation to free memory ([PR
15
+ 659](https://github.com/squaremo/amqp.node/pull/659), thank you
16
+ @Uzlopak and @kibertoad)
17
+
18
+
3
19
  ## Changes in v0.9.0
4
20
 
5
21
  git log v0.8.0..v0.9.0
package/Makefile CHANGED
@@ -3,7 +3,7 @@ JSON=amqp-rabbitmq-0.9.1.json
3
3
  RABBITMQ_CODEGEN=https://raw.githubusercontent.com/rabbitmq/rabbitmq-codegen
4
4
  AMQP_JSON=$(RABBITMQ_CODEGEN)/$(RABBITMQ_SRC_VERSION)/$(JSON)
5
5
 
6
- NODEJS_VERSIONS='10.21' '11.15' '12.18' '13.14' '14.5' '15.8'
6
+ NODEJS_VERSIONS='10.21' '11.15' '12.18' '13.14' '14.5' '15.8' '16.3.0' '18.1.0'
7
7
 
8
8
  MOCHA=./node_modules/.bin/mocha
9
9
  _MOCHA=./node_modules/.bin/_mocha
package/README.md CHANGED
@@ -1,14 +1,19 @@
1
1
  # AMQP 0-9-1 library and client for Node.JS
2
2
 
3
- [![Build Status](https://travis-ci.org/squaremo/amqp.node.png)](https://travis-ci.org/squaremo/amqp.node)
3
+ [![NPM version](https://img.shields.io/npm/v/amqplib.svg?style=flat-square)](https://www.npmjs.com/package/amqplib)
4
+ [![NPM downloads](https://img.shields.io/npm/dm/amqplib.svg?style=flat-square)](https://www.npmjs.com/package/amqplib)
5
+ [![Node.js CI](https://github.com/amqp-node/amqplib/workflows/Node.js%20CI/badge.svg)](https://github.com/amqp-node/amqplib/actions?query=workflow%3A%22Node.js+CI%22)
6
+ [![amqplib](https://snyk.io/advisor/npm-package/amqplib/badge.svg)](https://snyk.io/advisor/npm-package/amqplib)
4
7
 
5
8
  npm install amqplib
6
9
 
7
10
  * [Change log][changelog]
8
11
  * [GitHub pages][gh-pages]
9
12
  * [API reference][gh-pages-apiref]
13
+ * [Troubleshooting][gh-pages-trouble]
10
14
  * [Examples from RabbitMQ tutorials][tutes]
11
15
 
16
+
12
17
  A library for making AMQP 0-9-1 clients for Node.JS, and an AMQP 0-9-1 client for Node.JS v10+.
13
18
 
14
19
  This library does not implement [AMQP
@@ -32,75 +37,71 @@ Still working on:
32
37
  ## Callback API example
33
38
 
34
39
  ```javascript
35
- var q = 'tasks';
36
-
37
- function bail(err) {
38
- console.error(err);
39
- process.exit(1);
40
- }
41
-
42
- // Publisher
43
- function publisher(conn) {
44
- conn.createChannel(on_open);
45
- function on_open(err, ch) {
46
- if (err != null) bail(err);
47
- ch.assertQueue(q);
48
- ch.sendToQueue(q, Buffer.from('something to do'));
49
- }
50
- }
51
-
52
- // Consumer
53
- function consumer(conn) {
54
- var ok = conn.createChannel(on_open);
55
- function on_open(err, ch) {
56
- if (err != null) bail(err);
57
- ch.assertQueue(q);
58
- ch.consume(q, function(msg) {
40
+ const amqplib = require('amqplib/callback_api');
41
+ const queue = 'tasks';
42
+
43
+ amqplib.connect('amqp://localhost', (err, conn) => {
44
+ if (err) throw err;
45
+
46
+ // Listener
47
+ conn.createChannel((err, ch2) => {
48
+ if (err) throw err;
49
+
50
+ ch2.assertQueue(queue);
51
+
52
+ ch2.consume(queue, (msg) => {
59
53
  if (msg !== null) {
60
54
  console.log(msg.content.toString());
61
- ch.ack(msg);
55
+ ch2.ack(msg);
56
+ } else {
57
+ console.log('Consumer cancelled by server');
62
58
  }
63
59
  });
64
- }
65
- }
66
-
67
- require('amqplib/callback_api')
68
- .connect('amqp://localhost', function(err, conn) {
69
- if (err != null) bail(err);
70
- consumer(conn);
71
- publisher(conn);
72
60
  });
61
+
62
+ // Sender
63
+ conn.createChannel((err, ch1) => {
64
+ if (err) throw err;
65
+
66
+ ch1.assertQueue(queue);
67
+
68
+ setInterval(() => {
69
+ ch1.sendToQueue(queue, Buffer.from('something to do'));
70
+ }, 1000);
71
+ });
72
+ });
73
73
  ```
74
74
 
75
- ## Promise API example
75
+ ## Promise/Async API example
76
76
 
77
77
  ```javascript
78
- var q = 'tasks';
78
+ const amqplib = require('amqplib');
79
+
80
+ (async () => {
81
+ const queue = 'tasks';
82
+ const conn = await amqplib.connect('amqp://localhost');
83
+
84
+ const ch1 = await conn.createChannel();
85
+ await ch1.assertQueue(queue);
86
+
87
+ // Listener
88
+ ch1.consume(queue, (msg) => {
89
+ if (msg !== null) {
90
+ console.log('Recieved:', msg.content.toString());
91
+ ch1.ack(msg);
92
+ } else {
93
+ console.log('Consumer cancelled by server');
94
+ }
95
+ });
79
96
 
80
- var open = require('amqplib').connect('amqp://localhost');
97
+ // Sender
98
+ const ch2 = await conn.createChannel();
99
+
100
+ setInterval(() => {
101
+ ch2.sendToQueue(queue, Buffer.from('something to do'));
102
+ }, 1000);
103
+ })();
81
104
 
82
- // Publisher
83
- open.then(function(conn) {
84
- return conn.createChannel();
85
- }).then(function(ch) {
86
- return ch.assertQueue(q).then(function(ok) {
87
- return ch.sendToQueue(q, Buffer.from('something to do'));
88
- });
89
- }).catch(console.warn);
90
-
91
- // Consumer
92
- open.then(function(conn) {
93
- return conn.createChannel();
94
- }).then(function(ch) {
95
- return ch.assertQueue(q).then(function(ok) {
96
- return ch.consume(q, function(msg) {
97
- if (msg !== null) {
98
- console.log(msg.content.toString());
99
- ch.ack(msg);
100
- }
101
- });
102
- });
103
- }).catch(console.warn);
104
105
  ```
105
106
 
106
107
  ## Running tests
@@ -127,7 +128,7 @@ dev.rabbitmq.com instance.
127
128
 
128
129
  You can run it under different versions of Node.JS using [nave][]:
129
130
 
130
- nave use 0.8 npm test
131
+ nave use 10 npm test
131
132
 
132
133
  or run the tests on all supported versions of Node.JS in one go:
133
134
 
@@ -146,10 +147,11 @@ really only useful for checking the kind and formatting of the errors.
146
147
  make coverage
147
148
  open file://`pwd`/coverage/lcov-report/index.html
148
149
 
149
- [gh-pages]: http://www.squaremobius.net/amqp.node/
150
- [gh-pages-apiref]: http://www.squaremobius.net/amqp.node/channel_api.html
150
+ [gh-pages]: https://amqp-node.github.io/amqplib/
151
+ [gh-pages-apiref]: https://amqp-node.github.io/amqplib/channel_api.html
152
+ [gh-pages-trouble]: https://amqp-node.github.io/amqplib/#troubleshooting
151
153
  [nave]: https://github.com/isaacs/nave
152
- [tutes]: https://github.com/squaremo/amqp.node/tree/main/examples/tutorials
154
+ [tutes]: https://github.com/amqp-node/amqplib/tree/main/examples/tutorials
153
155
  [rabbitmq-tutes]: http://www.rabbitmq.com/getstarted.html
154
- [changelog]: https://github.com/squaremo/amqp.node/blob/main/CHANGELOG.md
156
+ [changelog]: https://github.com/amqp-node/amqplib/blob/main/CHANGELOG.md
155
157
  [docker]: https://www.docker.com/
package/lib/channel.js CHANGED
@@ -460,7 +460,7 @@ C.onBufferDrain = function() {
460
460
  // low-level machinery.
461
461
  function BaseChannel(connection) {
462
462
  Channel.call(this, connection);
463
- this.consumers = {};
463
+ this.consumers = new Map();
464
464
  }
465
465
  inherits(BaseChannel, Channel);
466
466
 
@@ -469,16 +469,16 @@ module.exports.BaseChannel = BaseChannel;
469
469
  // Not sure I like the ff, it's going to be changing hidden classes
470
470
  // all over the place. On the other hand, whaddya do.
471
471
  BaseChannel.prototype.registerConsumer = function(tag, callback) {
472
- this.consumers[tag] = callback;
472
+ this.consumers.set(tag, callback);
473
473
  };
474
474
 
475
475
  BaseChannel.prototype.unregisterConsumer = function(tag) {
476
- delete this.consumers[tag];
476
+ this.consumers.delete(tag);
477
477
  };
478
478
 
479
479
  BaseChannel.prototype.dispatchMessage = function(fields, message) {
480
480
  var consumerTag = fields.consumerTag;
481
- var consumer = this.consumers[consumerTag];
481
+ var consumer = this.consumers.get(consumerTag);
482
482
  if (consumer) {
483
483
  return consumer(message);
484
484
  }
@@ -493,5 +493,7 @@ BaseChannel.prototype.handleDelivery = function(message) {
493
493
  };
494
494
 
495
495
  BaseChannel.prototype.handleCancel = function(fields) {
496
- return this.dispatchMessage(fields, null);
496
+ var result = this.dispatchMessage(fields, null);
497
+ this.unregisterConsumer(fields.consumerTag);
498
+ return result;
497
499
  };
package/lib/mux.js CHANGED
@@ -8,7 +8,6 @@
8
8
  // it then writes 'packets' from the upstreams to the given
9
9
  // downstream.
10
10
 
11
- var inherits = require('util').inherits;
12
11
  var assert = require('assert');
13
12
 
14
13
  var schedule = (typeof setImmediate === 'function') ?
@@ -47,7 +46,6 @@ Mux.prototype._readIncoming = function() {
47
46
  // become readable
48
47
  if (this.blocked) return;
49
48
 
50
- var self = this;
51
49
  var accepting = true;
52
50
  var out = this.out;
53
51
 
@@ -79,7 +77,7 @@ Mux.prototype._readIncoming = function() {
79
77
  }
80
78
  else { // ran out of room
81
79
  assert(this.newStreams.length > 0, "Expect some new streams to remain");
82
- this.oldStreams = this.oldStreams.concat(this.newStreams);
80
+ Array.prototype.push.apply(this.oldStreams, this.newStreams);
83
81
  this.newStreams = [];
84
82
  }
85
83
  // We may have exhausted all the old queues, or run out of room;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "amqplib",
3
- "homepage": "http://squaremo.github.io/amqp.node/",
3
+ "homepage": "http://amqp-node.github.io/amqplib/",
4
4
  "main": "./channel_api.js",
5
- "version": "0.9.0",
5
+ "version": "0.9.1",
6
6
  "description": "An AMQP 0-9-1 (e.g., RabbitMQ) library and client.",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/squaremo/amqp.node.git"
9
+ "url": "https://github.com/amqp-node/amqplib.git"
10
10
  },
11
11
  "engines": {
12
12
  "node": ">=10"