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
@@ -57,10 +57,18 @@ function waitForMessages(ch, q, k) {
57
57
 
58
58
  suite('connect', function() {
59
59
 
60
- test('at all', function(done) {
61
- connect(doneCallback(done));
60
+ test('at all', function(done) {
61
+ connect(doneCallback(done));
62
+ });
63
+
62
64
  });
63
65
 
66
+ suite('updateSecret', function() {
67
+ test('updateSecret', function(done) {
68
+ connect(kCallback(function(c) {
69
+ c.updateSecret(Buffer.from('new secret'), 'no reason', doneCallback(done));
70
+ }));
71
+ });
64
72
  });
65
73
 
66
74
  function channel_test_fn(method) {
@@ -79,234 +87,234 @@ var confirm_channel_test = channel_test_fn('createConfirmChannel');
79
87
 
80
88
  suite('channel open', function() {
81
89
 
82
- channel_test('at all', function(ch, done) {
83
- done();
84
- });
90
+ channel_test('at all', function(ch, done) {
91
+ done();
92
+ });
85
93
 
86
- channel_test('open and close', function(ch, done) {
87
- ch.close(doneCallback(done));
88
- });
94
+ channel_test('open and close', function(ch, done) {
95
+ ch.close(doneCallback(done));
96
+ });
89
97
 
90
98
  });
91
99
 
92
100
  suite('assert, check, delete', function() {
93
101
 
94
- channel_test('assert, check, delete queue', function(ch, done) {
95
- ch.assertQueue('test.cb.queue', {}, kCallback(function(q) {
96
- ch.checkQueue('test.cb.queue', kCallback(function(ok) {
97
- ch.deleteQueue('test.cb.queue', {}, doneCallback(done));
102
+ channel_test('assert, check, delete queue', function(ch, done) {
103
+ ch.assertQueue('test.cb.queue', {}, kCallback(function(q) {
104
+ ch.checkQueue('test.cb.queue', kCallback(function(ok) {
105
+ ch.deleteQueue('test.cb.queue', {}, doneCallback(done));
106
+ }, done));
98
107
  }, done));
99
- }, done));
100
- });
108
+ });
101
109
 
102
- channel_test('assert, check, delete exchange', function(ch, done) {
103
- ch.assertExchange(
104
- 'test.cb.exchange', 'topic', {}, kCallback(function(ex) {
105
- ch.checkExchange('test.cb.exchange', kCallback(function(ok) {
106
- ch.deleteExchange('test.cb.exchange', {}, doneCallback(done));
110
+ channel_test('assert, check, delete exchange', function(ch, done) {
111
+ ch.assertExchange(
112
+ 'test.cb.exchange', 'topic', {}, kCallback(function(ex) {
113
+ ch.checkExchange('test.cb.exchange', kCallback(function(ok) {
114
+ ch.deleteExchange('test.cb.exchange', {}, doneCallback(done));
115
+ }, done));
107
116
  }, done));
108
- }, done));
109
- });
117
+ });
110
118
 
111
- channel_test('fail on check non-queue', function(ch, done) {
112
- var both = twice(done);
113
- ch.on('error', failCallback(both.first));
114
- ch.checkQueue('test.cb.nothere', failCallback(both.second));
115
- });
119
+ channel_test('fail on check non-queue', function(ch, done) {
120
+ var both = twice(done);
121
+ ch.on('error', failCallback(both.first));
122
+ ch.checkQueue('test.cb.nothere', failCallback(both.second));
123
+ });
116
124
 
117
- channel_test('fail on check non-exchange', function(ch, done) {
118
- var both = twice(done);
119
- ch.on('error', failCallback(both.first));
120
- ch.checkExchange('test.cb.nothere', failCallback(both.second));
121
- });
125
+ channel_test('fail on check non-exchange', function(ch, done) {
126
+ var both = twice(done);
127
+ ch.on('error', failCallback(both.first));
128
+ ch.checkExchange('test.cb.nothere', failCallback(both.second));
129
+ });
122
130
 
123
131
  });
124
132
 
125
133
  suite('bindings', function() {
126
134
 
127
- channel_test('bind queue', function(ch, done) {
128
- ch.assertQueue('test.cb.bindq', {}, kCallback(function(q) {
129
- ch.assertExchange(
130
- 'test.cb.bindex', 'fanout', {}, kCallback(function(ex) {
131
- ch.bindQueue(q.queue, ex.exchange, '', {},
132
- doneCallback(done));
133
- }, done));
134
- }, done));
135
- });
136
-
137
- channel_test('bind exchange', function(ch, done) {
138
- ch.assertExchange(
139
- 'test.cb.bindex1', 'fanout', {}, kCallback(function(ex1) {
135
+ channel_test('bind queue', function(ch, done) {
136
+ ch.assertQueue('test.cb.bindq', {}, kCallback(function(q) {
140
137
  ch.assertExchange(
141
- 'test.cb.bindex2', 'fanout', {}, kCallback(function(ex2) {
142
- ch.bindExchange(ex1.exchange,
143
- ex2.exchange, '', {},
144
- doneCallback(done));
138
+ 'test.cb.bindex', 'fanout', {}, kCallback(function(ex) {
139
+ ch.bindQueue(q.queue, ex.exchange, '', {},
140
+ doneCallback(done));
145
141
  }, done));
146
142
  }, done));
147
- });
143
+ });
144
+
145
+ channel_test('bind exchange', function(ch, done) {
146
+ ch.assertExchange(
147
+ 'test.cb.bindex1', 'fanout', {}, kCallback(function(ex1) {
148
+ ch.assertExchange(
149
+ 'test.cb.bindex2', 'fanout', {}, kCallback(function(ex2) {
150
+ ch.bindExchange(ex1.exchange,
151
+ ex2.exchange, '', {},
152
+ doneCallback(done));
153
+ }, done));
154
+ }, done));
155
+ });
148
156
 
149
157
  });
150
158
 
151
159
  suite('sending messages', function() {
152
160
 
153
- channel_test('send to queue and consume noAck', function(ch, done) {
154
- var msg = randomString();
155
- ch.assertQueue('', {exclusive: true}, function(e, q) {
156
- if (e !== null) return done(e);
157
- ch.consume(q.queue, function(m) {
158
- if (m.content.toString() == msg) done();
159
- else done(new Error("message content doesn't match:" +
160
- msg + " =/= " + m.content.toString()));
161
- }, {noAck: true, exclusive: true});
162
- ch.sendToQueue(q.queue, Buffer.from(msg));
161
+ channel_test('send to queue and consume noAck', function(ch, done) {
162
+ var msg = randomString();
163
+ ch.assertQueue('', {exclusive: true}, function(e, q) {
164
+ if (e !== null) return done(e);
165
+ ch.consume(q.queue, function(m) {
166
+ if (m.content.toString() == msg) done();
167
+ else done(new Error("message content doesn't match:" +
168
+ msg + " =/= " + m.content.toString()));
169
+ }, {noAck: true, exclusive: true});
170
+ ch.sendToQueue(q.queue, Buffer.from(msg));
171
+ });
163
172
  });
164
- });
165
173
 
166
- channel_test('send to queue and consume ack', function(ch, done) {
167
- var msg = randomString();
168
- ch.assertQueue('', {exclusive: true}, function(e, q) {
169
- if (e !== null) return done(e);
170
- ch.consume(q.queue, function(m) {
171
- if (m.content.toString() == msg) {
172
- ch.ack(m);
173
- done();
174
- }
175
- else done(new Error("message content doesn't match:" +
176
- msg + " =/= " + m.content.toString()));
177
- }, {noAck: false, exclusive: true});
178
- ch.sendToQueue(q.queue, Buffer.from(msg));
174
+ channel_test('send to queue and consume ack', function(ch, done) {
175
+ var msg = randomString();
176
+ ch.assertQueue('', {exclusive: true}, function(e, q) {
177
+ if (e !== null) return done(e);
178
+ ch.consume(q.queue, function(m) {
179
+ if (m.content.toString() == msg) {
180
+ ch.ack(m);
181
+ done();
182
+ }
183
+ else done(new Error("message content doesn't match:" +
184
+ msg + " =/= " + m.content.toString()));
185
+ }, {noAck: false, exclusive: true});
186
+ ch.sendToQueue(q.queue, Buffer.from(msg));
187
+ });
179
188
  });
180
- });
181
189
 
182
- channel_test('send to and get from queue', function(ch, done) {
183
- ch.assertQueue('', {exclusive: true}, function(e, q) {
184
- if (e != null) return done(e);
185
- var msg = randomString();
186
- ch.sendToQueue(q.queue, Buffer.from(msg));
187
- waitForMessages(ch, q.queue, function(e, _) {
190
+ channel_test('send to and get from queue', function(ch, done) {
191
+ ch.assertQueue('', {exclusive: true}, function(e, q) {
188
192
  if (e != null) return done(e);
189
- ch.get(q.queue, {noAck: true}, function(e, m) {
190
- if (e != null)
191
- return done(e);
192
- else if (!m)
193
- return done(new Error('Empty (false) not expected'));
194
- else if (m.content.toString() == msg)
195
- return done();
196
- else
197
- return done(
198
- new Error('Messages do not match: ' +
199
- msg + ' =/= ' + m.content.toString()));
193
+ var msg = randomString();
194
+ ch.sendToQueue(q.queue, Buffer.from(msg));
195
+ waitForMessages(ch, q.queue, function(e, _) {
196
+ if (e != null) return done(e);
197
+ ch.get(q.queue, {noAck: true}, function(e, m) {
198
+ if (e != null)
199
+ return done(e);
200
+ else if (!m)
201
+ return done(new Error('Empty (false) not expected'));
202
+ else if (m.content.toString() == msg)
203
+ return done();
204
+ else
205
+ return done(
206
+ new Error('Messages do not match: ' +
207
+ msg + ' =/= ' + m.content.toString()));
208
+ });
200
209
  });
201
210
  });
202
211
  });
203
- });
204
212
 
205
213
  });
206
214
 
207
215
  suite('ConfirmChannel', function() {
208
216
 
209
- confirm_channel_test('Receive confirmation', function(ch, done) {
210
- // An unroutable message, on the basis that you're not allowed a
211
- // queue with an empty name, and you can't make bindings to the
212
- // default exchange. Tricky eh?
213
- ch.publish('', '', Buffer.from('foo'), {}, done);
214
- });
217
+ confirm_channel_test('Receive confirmation', function(ch, done) {
218
+ // An unroutable message, on the basis that you're not allowed a
219
+ // queue with an empty name, and you can't make bindings to the
220
+ // default exchange. Tricky eh?
221
+ ch.publish('', '', Buffer.from('foo'), {}, done);
222
+ });
215
223
 
216
- confirm_channel_test('Wait for confirms', function(ch, done) {
217
- for (var i=0; i < 1000; i++) {
218
- ch.publish('', '', Buffer.from('foo'), {});
219
- }
220
- ch.waitForConfirms(done);
221
- });
224
+ confirm_channel_test('Wait for confirms', function(ch, done) {
225
+ for (var i=0; i < 1000; i++) {
226
+ ch.publish('', '', Buffer.from('foo'), {});
227
+ }
228
+ ch.waitForConfirms(done);
229
+ });
222
230
 
223
231
  });
224
232
 
225
233
  suite("Error handling", function() {
226
234
 
227
- /*
228
- I don't like having to do this, but there appears to be something
229
- broken about domains in Node.JS v0.8 and mocha. Apparently it has to
230
- do with how mocha and domains hook into error propogation:
231
- https://github.com/visionmedia/mocha/issues/513 (summary: domains in
232
- Node.JS v0.8 don't prevent uncaughtException from firing, and that's
233
- what mocha uses to detect .. an uncaught exception).
234
-
235
- Using domains with amqplib *does* work in practice in Node.JS v0.8:
236
- that is, it's possible to throw an exception in a callback and deal
237
- with it in the active domain, and thereby avoid it crashing the
238
- program.
239
- */
240
- if (util.versionGreaterThan(process.versions.node, '0.8')) {
241
- test('Throw error in connection open callback', function(done) {
242
- var dom = domain.createDomain();
243
- dom.on('error', failCallback(done));
244
- connect(dom.bind(function(err, conn) {
245
- throw new Error('Spurious connection open callback error');
246
- }));
247
- });
248
- }
235
+ /*
236
+ I don't like having to do this, but there appears to be something
237
+ broken about domains in Node.JS v0.8 and mocha. Apparently it has to
238
+ do with how mocha and domains hook into error propogation:
239
+ https://github.com/visionmedia/mocha/issues/513 (summary: domains in
240
+ Node.JS v0.8 don't prevent uncaughtException from firing, and that's
241
+ what mocha uses to detect .. an uncaught exception).
242
+
243
+ Using domains with amqplib *does* work in practice in Node.JS v0.8:
244
+ that is, it's possible to throw an exception in a callback and deal
245
+ with it in the active domain, and thereby avoid it crashing the
246
+ program.
247
+ */
248
+ if (util.versionGreaterThan(process.versions.node, '0.8')) {
249
+ test('Throw error in connection open callback', function(done) {
250
+ var dom = domain.createDomain();
251
+ dom.on('error', failCallback(done));
252
+ connect(dom.bind(function(err, conn) {
253
+ throw new Error('Spurious connection open callback error');
254
+ }));
255
+ });
256
+ }
249
257
 
250
- // TODO: refactor {error_test, channel_test}
251
- function error_test(name, fun) {
252
- test(name, function(done) {
253
- var dom = domain.createDomain();
254
- dom.run(function() {
255
- connect(kCallback(function(c) {
256
- // Seems like there were some unironed wrinkles in 0.8's
257
- // implementation of domains; explicitly adding the connection
258
- // to the domain makes sure any exception thrown in the course
259
- // of processing frames is handled by the domain. For other
260
- // versions of Node.JS, this ends up being belt-and-braces.
261
- dom.add(c);
262
- c.createChannel(kCallback(function(ch) {
263
- fun(ch, done, dom);
258
+ // TODO: refactor {error_test, channel_test}
259
+ function error_test(name, fun) {
260
+ test(name, function(done) {
261
+ var dom = domain.createDomain();
262
+ dom.run(function() {
263
+ connect(kCallback(function(c) {
264
+ // Seems like there were some unironed wrinkles in 0.8's
265
+ // implementation of domains; explicitly adding the connection
266
+ // to the domain makes sure any exception thrown in the course
267
+ // of processing frames is handled by the domain. For other
268
+ // versions of Node.JS, this ends up being belt-and-braces.
269
+ dom.add(c);
270
+ c.createChannel(kCallback(function(ch) {
271
+ fun(ch, done, dom);
272
+ }, done));
264
273
  }, done));
265
- }, done));
274
+ });
266
275
  });
267
- });
268
- }
269
-
270
- error_test('Channel open callback throws an error', function(ch, done, dom) {
271
- dom.on('error', failCallback(done));
272
- throw new Error('Error in open callback');
273
- });
276
+ }
274
277
 
275
- error_test('RPC callback throws error', function(ch, done, dom) {
276
- dom.on('error', failCallback(done));
277
- ch.prefetch(0, false, function(err, ok) {
278
- throw new Error('Spurious callback error');
278
+ error_test('Channel open callback throws an error', function(ch, done, dom) {
279
+ dom.on('error', failCallback(done));
280
+ throw new Error('Error in open callback');
279
281
  });
280
- });
281
282
 
282
- error_test('Get callback throws error', function(ch, done, dom) {
283
- dom.on('error', failCallback(done));
284
- ch.assertQueue('test.cb.get-with-error', {}, function(err, ok) {
285
- ch.get('test.cb.get-with-error', {noAck: true}, function() {
283
+ error_test('RPC callback throws error', function(ch, done, dom) {
284
+ dom.on('error', failCallback(done));
285
+ ch.prefetch(0, false, function(err, ok) {
286
286
  throw new Error('Spurious callback error');
287
287
  });
288
288
  });
289
- });
290
289
 
291
- error_test('Consume callback throws error', function(ch, done, dom) {
292
- dom.on('error', failCallback(done));
293
- ch.assertQueue('test.cb.consume-with-error', {}, function(err, ok) {
294
- ch.consume('test.cb.consume-with-error', ignore, {noAck: true}, function() {
295
- throw new Error('Spurious callback error');
290
+ error_test('Get callback throws error', function(ch, done, dom) {
291
+ dom.on('error', failCallback(done));
292
+ ch.assertQueue('test.cb.get-with-error', {}, function(err, ok) {
293
+ ch.get('test.cb.get-with-error', {noAck: true}, function() {
294
+ throw new Error('Spurious callback error');
295
+ });
296
296
  });
297
297
  });
298
- });
299
298
 
300
- error_test('Get from non-queue invokes error k', function(ch, done, dom) {
301
- var both = twice(failCallback(done));
302
- dom.on('error', both.first);
303
- ch.get('', {}, both.second);
304
- });
299
+ error_test('Consume callback throws error', function(ch, done, dom) {
300
+ dom.on('error', failCallback(done));
301
+ ch.assertQueue('test.cb.consume-with-error', {}, function(err, ok) {
302
+ ch.consume('test.cb.consume-with-error', ignore, {noAck: true}, function() {
303
+ throw new Error('Spurious callback error');
304
+ });
305
+ });
306
+ });
305
307
 
306
- error_test('Consume from non-queue invokes error k', function(ch, done, dom) {
307
- var both = twice(failCallback(done));
308
- dom.on('error', both.first);
309
- ch.consume('', both.second);
310
- });
308
+ error_test('Get from non-queue invokes error k', function(ch, done, dom) {
309
+ var both = twice(failCallback(done));
310
+ dom.on('error', both.first);
311
+ ch.get('', {}, both.second);
312
+ });
313
+
314
+ error_test('Consume from non-queue invokes error k', function(ch, done, dom) {
315
+ var both = twice(failCallback(done));
316
+ dom.on('error', both.first);
317
+ ch.consume('', both.second);
318
+ });
311
319
 
312
320
  });