amqplib 1.2.0 → 2.0.0
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/CHANGELOG.md +3 -0
- package/lib/connect.js +1 -1
- package/lib/connection.js +7 -1
- package/package.json +1 -1
- package/test/connection.test.js +71 -0
- package/test/lib/data.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Change log for amqplib
|
|
2
2
|
|
|
3
|
+
## v2.0.0
|
|
4
|
+
- **BREAKING**: `heartbeat: 0` now disables heartbeats, overriding any value suggested by the server. Previously, `0` was treated as "no preference" and the server's suggested value was used. If you are passing `heartbeat: 0` and want to preserve the old behaviour, omit the option or pass `null` instead (fixes #467)
|
|
5
|
+
|
|
3
6
|
## v1.2.0
|
|
4
7
|
- Add bundled TypeScript type definitions (fixes #843)
|
|
5
8
|
|
package/lib/connect.js
CHANGED
|
@@ -59,7 +59,7 @@ function openFrames(vhost, query, credentials, extraClientProperties) {
|
|
|
59
59
|
// tune-ok
|
|
60
60
|
channelMax: intOrDefault(query.channelMax, 0),
|
|
61
61
|
frameMax: intOrDefault(query.frameMax, 131072),
|
|
62
|
-
heartbeat: intOrDefault(query.heartbeat, 0),
|
|
62
|
+
heartbeat: query.heartbeat != null ? intOrDefault(query.heartbeat, 0) : null,
|
|
63
63
|
|
|
64
64
|
// open
|
|
65
65
|
virtualHost: vhost,
|
package/lib/connection.js
CHANGED
|
@@ -159,7 +159,13 @@ class Connection extends EventEmitter {
|
|
|
159
159
|
const fields = reply.fields;
|
|
160
160
|
tunedOptions.frameMax = negotiate(fields.frameMax, allFields.frameMax);
|
|
161
161
|
tunedOptions.channelMax = negotiate(fields.channelMax, allFields.channelMax);
|
|
162
|
-
|
|
162
|
+
if (allFields.heartbeat == null) {
|
|
163
|
+
tunedOptions.heartbeat = fields.heartbeat; // no preference, accept server value
|
|
164
|
+
} else if (allFields.heartbeat === 0) {
|
|
165
|
+
tunedOptions.heartbeat = 0; // explicitly disable heartbeats
|
|
166
|
+
} else {
|
|
167
|
+
tunedOptions.heartbeat = negotiate(fields.heartbeat, allFields.heartbeat);
|
|
168
|
+
}
|
|
163
169
|
try {
|
|
164
170
|
send(defs.ConnectionTuneOk);
|
|
165
171
|
send(defs.ConnectionOpen);
|
package/package.json
CHANGED
package/test/connection.test.js
CHANGED
|
@@ -696,6 +696,77 @@ describe('Connection', () => {
|
|
|
696
696
|
.then(cb, cb);
|
|
697
697
|
// conspicuously not sending anything ...
|
|
698
698
|
}));
|
|
699
|
+
|
|
700
|
+
it('without a heartbeat option, server suggested value is used', connectionTest((c, cb) => {
|
|
701
|
+
// OPEN_OPTS.heartbeat is null — no preference set by client
|
|
702
|
+
c.once('error', (err) => {
|
|
703
|
+
assert.match(err.message, /Heartbeat timeout/);
|
|
704
|
+
cb();
|
|
705
|
+
});
|
|
706
|
+
c.open(OPEN_OPTS, (err) => {
|
|
707
|
+
assert.ifError(err);
|
|
708
|
+
assert.strictEqual(c.heartbeat, 1);
|
|
709
|
+
});
|
|
710
|
+
}, (send, wait, cb) => {
|
|
711
|
+
send(defs.ConnectionStart, {
|
|
712
|
+
versionMajor: 0, versionMinor: 9,
|
|
713
|
+
serverProperties: {},
|
|
714
|
+
mechanisms: Buffer.from('PLAIN'),
|
|
715
|
+
locales: Buffer.from('en_US'),
|
|
716
|
+
});
|
|
717
|
+
wait(defs.ConnectionStartOk)()
|
|
718
|
+
.then(() => send(defs.ConnectionTune, { channelMax: 0, heartbeat: 1, frameMax: 0 }))
|
|
719
|
+
.then(wait(defs.ConnectionTuneOk))
|
|
720
|
+
.then(wait(defs.ConnectionOpen))
|
|
721
|
+
.then(() => send(defs.ConnectionOpenOk, { knownHosts: '' }))
|
|
722
|
+
.then(cb, cb);
|
|
723
|
+
}));
|
|
724
|
+
|
|
725
|
+
it('heartbeat:0 means no heartbeater is started', connectionTest((c, cb) => {
|
|
726
|
+
const opts = Object.create(OPEN_OPTS);
|
|
727
|
+
opts.heartbeat = 0;
|
|
728
|
+
c.open(opts, (err) => {
|
|
729
|
+
assert.ifError(err);
|
|
730
|
+
assert.strictEqual(c.heartbeat, 0);
|
|
731
|
+
assert.strictEqual(c.heartbeater, null);
|
|
732
|
+
cb();
|
|
733
|
+
});
|
|
734
|
+
}, (send, wait, cb) => {
|
|
735
|
+
send(defs.ConnectionStart, {
|
|
736
|
+
versionMajor: 0, versionMinor: 9,
|
|
737
|
+
serverProperties: {},
|
|
738
|
+
mechanisms: Buffer.from('PLAIN'),
|
|
739
|
+
locales: Buffer.from('en_US'),
|
|
740
|
+
});
|
|
741
|
+
wait(defs.ConnectionStartOk)()
|
|
742
|
+
.then(() => send(defs.ConnectionTune, { channelMax: 0, heartbeat: 60, frameMax: 0 }))
|
|
743
|
+
.then(wait(defs.ConnectionTuneOk))
|
|
744
|
+
.then(wait(defs.ConnectionOpen))
|
|
745
|
+
.then(() => send(defs.ConnectionOpenOk, { knownHosts: '' }))
|
|
746
|
+
.then(cb, cb);
|
|
747
|
+
}));
|
|
748
|
+
|
|
749
|
+
it('heartbeat:0 disables heartbeats even if server suggests one', connectionTest((c, cb) => {
|
|
750
|
+
const opts = Object.create(OPEN_OPTS);
|
|
751
|
+
opts.heartbeat = 0;
|
|
752
|
+
c.open(opts, cb);
|
|
753
|
+
}, (send, wait, cb) => {
|
|
754
|
+
send(defs.ConnectionStart, {
|
|
755
|
+
versionMajor: 0, versionMinor: 9,
|
|
756
|
+
serverProperties: {},
|
|
757
|
+
mechanisms: Buffer.from('PLAIN'),
|
|
758
|
+
locales: Buffer.from('en_US'),
|
|
759
|
+
});
|
|
760
|
+
wait(defs.ConnectionStartOk)()
|
|
761
|
+
.then(() => send(defs.ConnectionTune, { channelMax: 0, heartbeat: 60, frameMax: 0 }))
|
|
762
|
+
.then(wait(defs.ConnectionTuneOk))
|
|
763
|
+
.then((tuneOk) => {
|
|
764
|
+
assert.strictEqual(tuneOk.fields.heartbeat, 0);
|
|
765
|
+
})
|
|
766
|
+
.then(wait(defs.ConnectionOpen))
|
|
767
|
+
.then(() => send(defs.ConnectionOpenOk, { knownHosts: '' }))
|
|
768
|
+
.then(cb, cb);
|
|
769
|
+
}));
|
|
699
770
|
});
|
|
700
771
|
|
|
701
772
|
});
|