amqplib 0.10.2 → 0.10.4

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.
Files changed (55) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
  2. package/.github/workflows/test.yml +15 -2
  3. package/CHANGELOG.md +12 -1
  4. package/Makefile +3 -4
  5. package/README.md +1 -1
  6. package/bin/generate-defs.js +5 -5
  7. package/examples/direct_reply_to_client.js +22 -0
  8. package/examples/direct_reply_to_server.js +25 -0
  9. package/examples/headers.js +29 -31
  10. package/examples/ssl.js +16 -10
  11. package/examples/stream_queues/README.md +40 -0
  12. package/examples/stream_queues/package.json +14 -0
  13. package/examples/stream_queues/receive_stream.js +55 -0
  14. package/examples/stream_queues/send_stream.js +38 -0
  15. package/examples/tutorials/callback_api/emit_log.js +22 -22
  16. package/examples/tutorials/callback_api/emit_log_direct.js +24 -24
  17. package/examples/tutorials/callback_api/emit_log_topic.js +23 -20
  18. package/examples/tutorials/callback_api/new_task.js +21 -20
  19. package/examples/tutorials/callback_api/receive.js +27 -21
  20. package/examples/tutorials/callback_api/receive_logs.js +32 -26
  21. package/examples/tutorials/callback_api/receive_logs_direct.js +42 -41
  22. package/examples/tutorials/callback_api/receive_logs_topic.js +43 -40
  23. package/examples/tutorials/callback_api/rpc_client.js +39 -37
  24. package/examples/tutorials/callback_api/rpc_server.js +42 -32
  25. package/examples/tutorials/callback_api/send.js +21 -22
  26. package/examples/tutorials/callback_api/worker.js +29 -25
  27. package/examples/tutorials/emit_log.js +20 -15
  28. package/examples/tutorials/emit_log_direct.js +22 -16
  29. package/examples/tutorials/emit_log_topic.js +22 -15
  30. package/examples/tutorials/new_task.js +20 -13
  31. package/examples/tutorials/receive.js +19 -14
  32. package/examples/tutorials/receive_logs.js +25 -23
  33. package/examples/tutorials/receive_logs_direct.js +29 -35
  34. package/examples/tutorials/receive_logs_topic.js +28 -32
  35. package/examples/tutorials/rpc_client.js +37 -40
  36. package/examples/tutorials/rpc_server.js +36 -29
  37. package/examples/tutorials/send.js +26 -18
  38. package/examples/tutorials/worker.js +27 -21
  39. package/examples/waitForConfirms.js +18 -19
  40. package/lib/callback_model.js +295 -290
  41. package/lib/channel.js +353 -346
  42. package/lib/channel_model.js +5 -1
  43. package/lib/codec.js +2 -2
  44. package/lib/connection.js +542 -527
  45. package/lib/credentials.js +1 -1
  46. package/lib/defs.js +2568 -2457
  47. package/lib/format.js +0 -1
  48. package/lib/frame.js +1 -1
  49. package/lib/heartbeat.js +32 -29
  50. package/lib/mux.js +96 -99
  51. package/package.json +2 -2
  52. package/test/callback_api.js +182 -174
  53. package/test/channel_api.js +455 -445
  54. package/test/codec.js +4 -4
  55. package/test/frame.js +5 -5
package/lib/format.js CHANGED
@@ -8,7 +8,6 @@
8
8
 
9
9
  var defs = require('./defs');
10
10
  var format = require('util').format;
11
- var inherits = require('util').inherits;
12
11
  var HEARTBEAT = require('./frame').HEARTBEAT;
13
12
 
14
13
  module.exports.closeMessage = function(close) {
package/lib/frame.js CHANGED
@@ -8,7 +8,7 @@ var defs = require('./defs');
8
8
  var constants = defs.constants;
9
9
  var decode = defs.decode;
10
10
 
11
- var Bits = require('bitsyntax');
11
+ var Bits = require('@acuminous/bitsyntax');
12
12
 
13
13
  module.exports.PROTOCOL_HEADER = "AMQP" + String.fromCharCode(0, 0, 9, 1);
14
14
 
package/lib/heartbeat.js CHANGED
@@ -47,43 +47,46 @@
47
47
 
48
48
  'use strict';
49
49
 
50
- var inherits = require('util').inherits;
51
- var EventEmitter = require('events').EventEmitter;
50
+ var EventEmitter = require('events');
52
51
 
53
52
  // Exported so that we can mess with it in tests
54
53
  module.exports.UNITS_TO_MS = 1000;
55
54
 
56
- function Heart(interval, checkSend, checkRecv) {
57
- EventEmitter.call(this);
58
- this.interval = interval;
55
+ class Heart extends EventEmitter {
56
+ constructor (interval, checkSend, checkRecv) {
57
+ super();
59
58
 
60
- var intervalMs = interval * module.exports.UNITS_TO_MS;
61
- // Function#bind is my new best friend
62
- var beat = this.emit.bind(this, 'beat');
63
- var timeout = this.emit.bind(this, 'timeout');
59
+ this.interval = interval;
64
60
 
65
- this.sendTimer = setInterval(
66
- this.runHeartbeat.bind(this, checkSend, beat), intervalMs / 2);
61
+ var intervalMs = interval * module.exports.UNITS_TO_MS;
62
+ // Function#bind is my new best friend
63
+ var beat = this.emit.bind(this, 'beat');
64
+ var timeout = this.emit.bind(this, 'timeout');
67
65
 
68
- // A timeout occurs if I see nothing for *two consecutive* intervals
69
- var recvMissed = 0;
70
- function missedTwo() {
71
- if (!checkRecv()) return (++recvMissed < 2);
72
- else { recvMissed = 0; return true; }
66
+ this.sendTimer = setInterval(
67
+ this.runHeartbeat.bind(this, checkSend, beat), intervalMs / 2);
68
+
69
+ // A timeout occurs if I see nothing for *two consecutive* intervals
70
+ var recvMissed = 0;
71
+ function missedTwo () {
72
+ if (!checkRecv())
73
+ return (++recvMissed < 2);
74
+ else { recvMissed = 0; return true; }
75
+ }
76
+ this.recvTimer = setInterval(
77
+ this.runHeartbeat.bind(this, missedTwo, timeout), intervalMs);
73
78
  }
74
- this.recvTimer = setInterval(
75
- this.runHeartbeat.bind(this, missedTwo, timeout), intervalMs);
76
- }
77
- inherits(Heart, EventEmitter);
78
79
 
79
- module.exports.Heart = Heart;
80
+ clear () {
81
+ clearInterval(this.sendTimer);
82
+ clearInterval(this.recvTimer);
83
+ }
80
84
 
81
- Heart.prototype.clear = function() {
82
- clearInterval(this.sendTimer);
83
- clearInterval(this.recvTimer);
84
- };
85
+ runHeartbeat (check, fail) {
86
+ // Have we seen activity?
87
+ if (!check())
88
+ fail();
89
+ }
90
+ }
85
91
 
86
- Heart.prototype.runHeartbeat = function(check, fail) {
87
- // Have we seen activity?
88
- if (!check()) fail();
89
- };
92
+ module.exports.Heart = Heart;
package/lib/mux.js CHANGED
@@ -13,117 +13,114 @@ var assert = require('assert');
13
13
  var schedule = (typeof setImmediate === 'function') ?
14
14
  setImmediate : process.nextTick;
15
15
 
16
- function Mux(downstream) {
17
- this.newStreams = [];
18
- this.oldStreams = [];
19
- this.blocked = false;
20
- this.scheduledRead = false;
21
-
22
- this.out = downstream;
23
- var self = this;
24
- downstream.on('drain', function() {
25
- self.blocked = false;
26
- self._readIncoming();
27
- });
28
- }
29
-
30
- // There are 2 states we can be in:
31
-
32
- // - waiting for outbound capacity, which will be signalled by a
33
- // - 'drain' event on the downstream; or,
34
-
35
- // - no packets to send, waiting for an inbound buffer to have
36
- // packets, which will be signalled by a 'readable' event
37
-
38
- // If we write all packets available whenever there is outbound
39
- // capacity, we will either run out of outbound capacity (`#write`
40
- // returns false), or run out of packets (all calls to an
41
- // `inbound.read()` have returned null).
16
+ class Mux {
17
+ constructor (downstream) {
18
+ this.newStreams = [];
19
+ this.oldStreams = [];
20
+ this.blocked = false;
21
+ this.scheduledRead = false;
22
+
23
+ this.out = downstream;
24
+ var self = this;
25
+ downstream.on('drain', function () {
26
+ self.blocked = false;
27
+ self._readIncoming();
28
+ });
29
+ }
42
30
 
43
- Mux.prototype._readIncoming = function() {
31
+ // There are 2 states we can be in:
32
+ // - waiting for outbound capacity, which will be signalled by a
33
+ // - 'drain' event on the downstream; or,
34
+ // - no packets to send, waiting for an inbound buffer to have
35
+ // packets, which will be signalled by a 'readable' event
36
+ // If we write all packets available whenever there is outbound
37
+ // capacity, we will either run out of outbound capacity (`#write`
38
+ // returns false), or run out of packets (all calls to an
39
+ // `inbound.read()` have returned null).
40
+ _readIncoming () {
41
+
42
+ // We may be sent here speculatively, if an incoming stream has
43
+ // become readable
44
+ if (this.blocked) return;
45
+
46
+ var accepting = true;
47
+ var out = this.out;
48
+
49
+ // Try to read a chunk from each stream in turn, until all streams
50
+ // are empty, or we exhaust our ability to accept chunks.
51
+ function roundrobin (streams) {
52
+ var s;
53
+ while (accepting && (s = streams.shift())) {
54
+ var chunk = s.read();
55
+ if (chunk !== null) {
56
+ accepting = out.write(chunk);
57
+ streams.push(s);
58
+ }
59
+ }
60
+ }
44
61
 
45
- // We may be sent here speculatively, if an incoming stream has
46
- // become readable
47
- if (this.blocked) return;
62
+ roundrobin(this.newStreams);
63
+
64
+ // Either we exhausted the new queues, or we ran out of capacity. If
65
+ // we ran out of capacity, all the remaining new streams (i.e.,
66
+ // those with packets left) become old streams. This effectively
67
+ // prioritises streams that keep their buffers close to empty over
68
+ // those that are constantly near full.
69
+ if (accepting) { // all new queues are exhausted, write as many as
70
+ // we can from the old streams
71
+ assert.equal(0, this.newStreams.length);
72
+ roundrobin(this.oldStreams);
73
+ }
74
+ else { // ran out of room
75
+ assert(this.newStreams.length > 0, "Expect some new streams to remain");
76
+ Array.prototype.push.apply(this.oldStreams, this.newStreams);
77
+ this.newStreams = [];
78
+ }
79
+ // We may have exhausted all the old queues, or run out of room;
80
+ // either way, all we need to do is record whether we have capacity
81
+ // or not, so any speculative reads will know
82
+ this.blocked = !accepting;
83
+ }
48
84
 
49
- var accepting = true;
50
- var out = this.out;
85
+ _scheduleRead () {
86
+ var self = this;
51
87
 
52
- // Try to read a chunk from each stream in turn, until all streams
53
- // are empty, or we exhaust our ability to accept chunks.
54
- function roundrobin(streams) {
55
- var s;
56
- while (accepting && (s = streams.shift())) {
57
- var chunk = s.read();
58
- if (chunk !== null) {
59
- accepting = out.write(chunk);
60
- streams.push(s);
61
- }
88
+ if (!self.scheduledRead) {
89
+ schedule(function () {
90
+ self.scheduledRead = false;
91
+ self._readIncoming();
92
+ });
93
+ self.scheduledRead = true;
62
94
  }
63
95
  }
64
96
 
65
- roundrobin(this.newStreams);
97
+ pipeFrom (readable) {
98
+ var self = this;
66
99
 
67
- // Either we exhausted the new queues, or we ran out of capacity. If
68
- // we ran out of capacity, all the remaining new streams (i.e.,
69
- // those with packets left) become old streams. This effectively
70
- // prioritises streams that keep their buffers close to empty over
71
- // those that are constantly near full.
72
-
73
- if (accepting) { // all new queues are exhausted, write as many as
74
- // we can from the old streams
75
- assert.equal(0, this.newStreams.length);
76
- roundrobin(this.oldStreams);
77
- }
78
- else { // ran out of room
79
- assert(this.newStreams.length > 0, "Expect some new streams to remain");
80
- Array.prototype.push.apply(this.oldStreams, this.newStreams);
81
- this.newStreams = [];
82
- }
83
- // We may have exhausted all the old queues, or run out of room;
84
- // either way, all we need to do is record whether we have capacity
85
- // or not, so any speculative reads will know
86
- this.blocked = !accepting;
87
- };
88
-
89
- Mux.prototype._scheduleRead = function() {
90
- var self = this;
91
-
92
- if (!self.scheduledRead) {
93
- schedule(function() {
94
- self.scheduledRead = false;
95
- self._readIncoming();
96
- });
97
- self.scheduledRead = true;
98
- }
99
- };
100
+ function enqueue () {
101
+ self.newStreams.push(readable);
102
+ self._scheduleRead();
103
+ }
100
104
 
101
- Mux.prototype.pipeFrom = function(readable) {
102
- var self = this;
105
+ function cleanup () {
106
+ readable.removeListener('readable', enqueue);
107
+ readable.removeListener('error', cleanup);
108
+ readable.removeListener('end', cleanup);
109
+ readable.removeListener('unpipeFrom', cleanupIfMe);
110
+ }
111
+ function cleanupIfMe (dest) {
112
+ if (dest === self) cleanup();
113
+ }
103
114
 
104
- function enqueue() {
105
- self.newStreams.push(readable);
106
- self._scheduleRead();
115
+ readable.on('unpipeFrom', cleanupIfMe);
116
+ readable.on('end', cleanup);
117
+ readable.on('error', cleanup);
118
+ readable.on('readable', enqueue);
107
119
  }
108
120
 
109
- function cleanup() {
110
- readable.removeListener('readable', enqueue);
111
- readable.removeListener('error', cleanup);
112
- readable.removeListener('end', cleanup);
113
- readable.removeListener('unpipeFrom', cleanupIfMe);
114
- }
115
- function cleanupIfMe(dest) {
116
- if (dest === self) cleanup();
121
+ unpipeFrom (readable) {
122
+ readable.emit('unpipeFrom', this);
117
123
  }
118
-
119
- readable.on('unpipeFrom', cleanupIfMe);
120
- readable.on('end', cleanup);
121
- readable.on('error', cleanup);
122
- readable.on('readable', enqueue);
123
- };
124
-
125
- Mux.prototype.unpipeFrom = function(readable) {
126
- readable.emit('unpipeFrom', this);
127
- };
124
+ }
128
125
 
129
126
  module.exports.Mux = Mux;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "amqplib",
3
3
  "homepage": "http://amqp-node.github.io/amqplib/",
4
4
  "main": "./channel_api.js",
5
- "version": "0.10.2",
5
+ "version": "0.10.4",
6
6
  "description": "An AMQP 0-9-1 (e.g., RabbitMQ) library and client.",
7
7
  "repository": {
8
8
  "type": "git",
@@ -12,7 +12,7 @@
12
12
  "node": ">=10"
13
13
  },
14
14
  "dependencies": {
15
- "bitsyntax": "~0.1.0",
15
+ "@acuminous/bitsyntax": "^0.1.2",
16
16
  "buffer-more-ints": "~1.0.0",
17
17
  "readable-stream": "1.x >=1.1.9",
18
18
  "url-parse": "~1.5.10"