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.
- package/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
- package/.github/workflows/test.yml +15 -2
- package/CHANGELOG.md +12 -1
- package/Makefile +3 -4
- package/README.md +1 -1
- package/bin/generate-defs.js +5 -5
- package/examples/direct_reply_to_client.js +22 -0
- package/examples/direct_reply_to_server.js +25 -0
- package/examples/headers.js +29 -31
- package/examples/ssl.js +16 -10
- package/examples/stream_queues/README.md +40 -0
- package/examples/stream_queues/package.json +14 -0
- package/examples/stream_queues/receive_stream.js +55 -0
- package/examples/stream_queues/send_stream.js +38 -0
- package/examples/tutorials/callback_api/emit_log.js +22 -22
- package/examples/tutorials/callback_api/emit_log_direct.js +24 -24
- package/examples/tutorials/callback_api/emit_log_topic.js +23 -20
- package/examples/tutorials/callback_api/new_task.js +21 -20
- package/examples/tutorials/callback_api/receive.js +27 -21
- package/examples/tutorials/callback_api/receive_logs.js +32 -26
- package/examples/tutorials/callback_api/receive_logs_direct.js +42 -41
- package/examples/tutorials/callback_api/receive_logs_topic.js +43 -40
- package/examples/tutorials/callback_api/rpc_client.js +39 -37
- package/examples/tutorials/callback_api/rpc_server.js +42 -32
- package/examples/tutorials/callback_api/send.js +21 -22
- package/examples/tutorials/callback_api/worker.js +29 -25
- package/examples/tutorials/emit_log.js +20 -15
- package/examples/tutorials/emit_log_direct.js +22 -16
- package/examples/tutorials/emit_log_topic.js +22 -15
- package/examples/tutorials/new_task.js +20 -13
- package/examples/tutorials/receive.js +19 -14
- package/examples/tutorials/receive_logs.js +25 -23
- package/examples/tutorials/receive_logs_direct.js +29 -35
- package/examples/tutorials/receive_logs_topic.js +28 -32
- package/examples/tutorials/rpc_client.js +37 -40
- package/examples/tutorials/rpc_server.js +36 -29
- package/examples/tutorials/send.js +26 -18
- package/examples/tutorials/worker.js +27 -21
- package/examples/waitForConfirms.js +18 -19
- package/lib/callback_model.js +295 -290
- package/lib/channel.js +353 -346
- package/lib/channel_model.js +5 -1
- package/lib/codec.js +2 -2
- package/lib/connection.js +542 -527
- package/lib/credentials.js +1 -1
- package/lib/defs.js +2568 -2457
- package/lib/format.js +0 -1
- package/lib/frame.js +1 -1
- package/lib/heartbeat.js +32 -29
- package/lib/mux.js +96 -99
- package/package.json +2 -2
- package/test/callback_api.js +182 -174
- package/test/channel_api.js +455 -445
- package/test/codec.js +4 -4
- package/test/frame.js +5 -5
package/lib/format.js
CHANGED
package/lib/frame.js
CHANGED
package/lib/heartbeat.js
CHANGED
|
@@ -47,43 +47,46 @@
|
|
|
47
47
|
|
|
48
48
|
'use strict';
|
|
49
49
|
|
|
50
|
-
var
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
class Heart extends EventEmitter {
|
|
56
|
+
constructor (interval, checkSend, checkRecv) {
|
|
57
|
+
super();
|
|
59
58
|
|
|
60
|
-
|
|
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
|
-
|
|
66
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if
|
|
72
|
-
|
|
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
|
-
|
|
80
|
+
clear () {
|
|
81
|
+
clearInterval(this.sendTimer);
|
|
82
|
+
clearInterval(this.recvTimer);
|
|
83
|
+
}
|
|
80
84
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
runHeartbeat (check, fail) {
|
|
86
|
+
// Have we seen activity?
|
|
87
|
+
if (!check())
|
|
88
|
+
fail();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
85
91
|
|
|
86
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
85
|
+
_scheduleRead () {
|
|
86
|
+
var self = this;
|
|
51
87
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
97
|
+
pipeFrom (readable) {
|
|
98
|
+
var self = this;
|
|
66
99
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
110
|
-
readable.
|
|
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.
|
|
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": "
|
|
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"
|