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/test/callback_api.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
84
|
-
});
|
|
90
|
+
channel_test('at all', function(ch, done) {
|
|
91
|
+
done();
|
|
92
|
+
});
|
|
85
93
|
|
|
86
|
-
channel_test('open and close', function(ch, done) {
|
|
87
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
}
|
|
100
|
-
});
|
|
108
|
+
});
|
|
101
109
|
|
|
102
|
-
channel_test('assert, check, delete exchange', function(ch, done) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
109
|
-
});
|
|
117
|
+
});
|
|
110
118
|
|
|
111
|
-
channel_test('fail on check non-queue', function(ch, done) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
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.
|
|
142
|
-
ch.
|
|
143
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
}
|
|
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('
|
|
276
|
-
|
|
277
|
-
|
|
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('
|
|
283
|
-
|
|
284
|
-
|
|
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('
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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('
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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('
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
});
|