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/channel_api.js
CHANGED
|
@@ -49,94 +49,104 @@ var chtest = channel_test.bind(null, 'createChannel');
|
|
|
49
49
|
|
|
50
50
|
suite("connect", function() {
|
|
51
51
|
|
|
52
|
-
test("at all", function(done) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
52
|
+
test("at all", function(done) {
|
|
53
|
+
connect(URL).then(function(c) {
|
|
54
|
+
return c.close()
|
|
55
|
+
;}).then(succeed(done), fail(done));
|
|
56
|
+
});
|
|
57
57
|
|
|
58
|
-
chtest("create channel", ignore); // i.e., just don't bork
|
|
58
|
+
chtest("create channel", ignore); // i.e., just don't bork
|
|
59
59
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
+
suite("updateSecret", function() {
|
|
63
|
+
test("updateSecret", function(done) {
|
|
64
|
+
connect().then(function(c) {
|
|
65
|
+
c.updateSecret(Buffer.from("new secret"), "no reason")
|
|
66
|
+
.then(succeed(done), fail(done))
|
|
67
|
+
.finally(function() { c.close(); });
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
62
72
|
var QUEUE_OPTS = {durable: false};
|
|
63
73
|
var EX_OPTS = {durable: false};
|
|
64
74
|
|
|
65
75
|
suite("assert, check, delete", function() {
|
|
66
76
|
|
|
67
|
-
chtest("assert and check queue", function(ch) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
77
|
+
chtest("assert and check queue", function(ch) {
|
|
78
|
+
return ch.assertQueue('test.check-queue', QUEUE_OPTS)
|
|
79
|
+
.then(function(qok) {
|
|
80
|
+
return ch.checkQueue('test.check-queue');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
73
83
|
|
|
74
|
-
chtest("assert and check exchange", function(ch) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
84
|
+
chtest("assert and check exchange", function(ch) {
|
|
85
|
+
return ch.assertExchange('test.check-exchange', 'direct', EX_OPTS)
|
|
86
|
+
.then(function(eok) {
|
|
87
|
+
assert.equal('test.check-exchange', eok.exchange);
|
|
88
|
+
return ch.checkExchange('test.check-exchange');
|
|
89
|
+
});
|
|
90
|
+
});
|
|
81
91
|
|
|
82
|
-
chtest("fail on reasserting queue with different options",
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
chtest("fail on checking a queue that's not there", function(ch) {
|
|
95
|
-
|
|
96
|
-
});
|
|
92
|
+
chtest("fail on reasserting queue with different options",
|
|
93
|
+
function(ch) {
|
|
94
|
+
var q = 'test.reassert-queue';
|
|
95
|
+
return ch.assertQueue(
|
|
96
|
+
q, {durable: false, autoDelete: true})
|
|
97
|
+
.then(function() {
|
|
98
|
+
return expectFail(
|
|
99
|
+
ch.assertQueue(q, {durable: false,
|
|
100
|
+
autoDelete: false}));
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
chtest("fail on checking a queue that's not there", function(ch) {
|
|
105
|
+
return expectFail(ch.checkQueue('test.random-' + randomString()));
|
|
106
|
+
});
|
|
97
107
|
|
|
98
|
-
chtest("fail on checking an exchange that's not there", function(ch) {
|
|
99
|
-
|
|
100
|
-
});
|
|
108
|
+
chtest("fail on checking an exchange that's not there", function(ch) {
|
|
109
|
+
return expectFail(ch.checkExchange('test.random-' + randomString()));
|
|
110
|
+
});
|
|
101
111
|
|
|
102
|
-
chtest("fail on reasserting exchange with different type",
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
chtest("channel break on publishing to non-exchange", function(ch) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
chtest("fail on reasserting exchange with different type",
|
|
113
|
+
function(ch) {
|
|
114
|
+
var ex = 'test.reassert-ex';
|
|
115
|
+
return ch.assertExchange(ex, 'fanout', EX_OPTS)
|
|
116
|
+
.then(function() {
|
|
117
|
+
return expectFail(
|
|
118
|
+
ch.assertExchange(ex, 'direct', EX_OPTS));
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
chtest("channel break on publishing to non-exchange", function(ch) {
|
|
123
|
+
return new Promise(function(resolve) {
|
|
124
|
+
ch.on('error', resolve);
|
|
125
|
+
ch.publish(randomString(), '', Buffer.from('foobar'));
|
|
126
|
+
});
|
|
116
127
|
});
|
|
117
|
-
});
|
|
118
128
|
|
|
119
|
-
chtest("delete queue", function(ch) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
+
chtest("delete queue", function(ch) {
|
|
130
|
+
var q = 'test.delete-queue';
|
|
131
|
+
return Promise.all([
|
|
132
|
+
ch.assertQueue(q, QUEUE_OPTS),
|
|
133
|
+
ch.checkQueue(q)])
|
|
134
|
+
.then(function() {
|
|
135
|
+
return ch.deleteQueue(q);})
|
|
136
|
+
.then(function() {
|
|
137
|
+
return expectFail(ch.checkQueue(q));});
|
|
138
|
+
});
|
|
129
139
|
|
|
130
|
-
chtest("delete exchange", function(ch) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
140
|
+
chtest("delete exchange", function(ch) {
|
|
141
|
+
var ex = 'test.delete-exchange';
|
|
142
|
+
return Promise.all([
|
|
143
|
+
ch.assertExchange(ex, 'fanout', EX_OPTS),
|
|
144
|
+
ch.checkExchange(ex)])
|
|
145
|
+
.then(function() {
|
|
146
|
+
return ch.deleteExchange(ex);})
|
|
147
|
+
.then(function() {
|
|
148
|
+
return expectFail(ch.checkExchange(ex));});
|
|
149
|
+
});
|
|
140
150
|
|
|
141
151
|
});
|
|
142
152
|
|
|
@@ -173,347 +183,347 @@ function waitForMessages(q, num) {
|
|
|
173
183
|
|
|
174
184
|
suite("sendMessage", function() {
|
|
175
185
|
|
|
176
|
-
// publish different size messages
|
|
177
|
-
chtest("send to queue and get from queue", function(ch) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
});
|
|
186
|
+
// publish different size messages
|
|
187
|
+
chtest("send to queue and get from queue", function(ch) {
|
|
188
|
+
var q = 'test.send-to-q';
|
|
189
|
+
var msg = randomString();
|
|
190
|
+
return Promise.all([ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
|
|
191
|
+
.then(function() {
|
|
192
|
+
ch.sendToQueue(q, Buffer.from(msg));
|
|
193
|
+
return waitForMessages(q);
|
|
194
|
+
})
|
|
195
|
+
.then(function() {
|
|
196
|
+
return ch.get(q, {noAck: true});
|
|
197
|
+
})
|
|
198
|
+
.then(function(m) {
|
|
199
|
+
assert(m);
|
|
200
|
+
assert.equal(msg, m.content.toString());
|
|
201
|
+
});
|
|
202
|
+
});
|
|
193
203
|
|
|
194
|
-
chtest("send (and get) zero content to queue", function(ch) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
});
|
|
204
|
+
chtest("send (and get) zero content to queue", function(ch) {
|
|
205
|
+
var q = 'test.send-to-q';
|
|
206
|
+
var msg = Buffer.alloc(0);
|
|
207
|
+
return Promise.all([
|
|
208
|
+
ch.assertQueue(q, QUEUE_OPTS),
|
|
209
|
+
ch.purgeQueue(q)])
|
|
210
|
+
.then(function() {
|
|
211
|
+
ch.sendToQueue(q, msg);
|
|
212
|
+
return waitForMessages(q);})
|
|
213
|
+
.then(function() {
|
|
214
|
+
return ch.get(q, {noAck: true});})
|
|
215
|
+
.then(function(m) {
|
|
216
|
+
assert(m);
|
|
217
|
+
assert.deepEqual(msg, m.content);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
210
220
|
|
|
211
221
|
});
|
|
212
222
|
|
|
213
223
|
suite("binding, consuming", function() {
|
|
214
224
|
|
|
215
|
-
// bind, publish, get
|
|
216
|
-
chtest("route message", function(ch) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return Promise.all([
|
|
222
|
-
ch.assertExchange(ex, 'fanout', EX_OPTS),
|
|
223
|
-
ch.assertQueue(q, QUEUE_OPTS),
|
|
224
|
-
ch.purgeQueue(q),
|
|
225
|
-
ch.bindQueue(q, ex, '', {})])
|
|
226
|
-
.then(function() {
|
|
227
|
-
ch.publish(ex, '', Buffer.from(msg));
|
|
228
|
-
return waitForMessages(q);})
|
|
229
|
-
.then(function() {
|
|
230
|
-
return ch.get(q, {noAck: true});})
|
|
231
|
-
.then(function(m) {
|
|
232
|
-
assert(m);
|
|
233
|
-
assert.equal(msg, m.content.toString());
|
|
234
|
-
});
|
|
235
|
-
});
|
|
225
|
+
// bind, publish, get
|
|
226
|
+
chtest("route message", function(ch) {
|
|
227
|
+
var ex = 'test.route-message';
|
|
228
|
+
var q = 'test.route-message-q';
|
|
229
|
+
var msg = randomString();
|
|
236
230
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
// bind again, unbind, publish, get-empty
|
|
253
|
-
chtest("unbind queue", function(ch) {
|
|
254
|
-
var ex = 'test.unbind-queue-ex';
|
|
255
|
-
var q = 'test.unbind-queue';
|
|
256
|
-
var viabinding = randomString();
|
|
257
|
-
var direct = randomString();
|
|
258
|
-
|
|
259
|
-
return Promise.all([
|
|
260
|
-
ch.assertExchange(ex, 'fanout', EX_OPTS),
|
|
261
|
-
ch.assertQueue(q, QUEUE_OPTS),
|
|
262
|
-
ch.purgeQueue(q),
|
|
263
|
-
ch.bindQueue(q, ex, '', {})])
|
|
264
|
-
.then(function() {
|
|
265
|
-
ch.publish(ex, '', Buffer.from('foobar'));
|
|
266
|
-
return waitForMessages(q);})
|
|
267
|
-
.then(function() { // message got through!
|
|
268
|
-
return ch.get(q, {noAck:true})
|
|
269
|
-
.then(function(m) {assert(m);});})
|
|
270
|
-
.then(function() {
|
|
271
|
-
return ch.unbindQueue(q, ex, '', {});})
|
|
272
|
-
.then(function() {
|
|
273
|
-
// via the no-longer-existing binding
|
|
274
|
-
ch.publish(ex, '', Buffer.from(viabinding));
|
|
275
|
-
// direct to the queue
|
|
276
|
-
ch.sendToQueue(q, Buffer.from(direct));
|
|
277
|
-
return waitForMessages(q);})
|
|
278
|
-
.then(function() {return ch.get(q)})
|
|
279
|
-
.then(function(m) {
|
|
280
|
-
// the direct to queue message got through, the via-binding
|
|
281
|
-
// message (sent first) did not
|
|
282
|
-
assert.equal(direct, m.content.toString());
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// To some extent this is now just testing semantics of the server,
|
|
287
|
-
// but we can at least try out a few settings, and consume.
|
|
288
|
-
chtest("consume via exchange-exchange binding", function(ch) {
|
|
289
|
-
var ex1 = 'test.ex-ex-binding1', ex2 = 'test.ex-ex-binding2';
|
|
290
|
-
var q = 'test.ex-ex-binding-q';
|
|
291
|
-
var rk = 'test.routing.key', msg = randomString();
|
|
292
|
-
return Promise.all([
|
|
293
|
-
ch.assertExchange(ex1, 'direct', EX_OPTS),
|
|
294
|
-
ch.assertExchange(ex2, 'fanout',
|
|
295
|
-
{durable: false, internal: true}),
|
|
296
|
-
ch.assertQueue(q, QUEUE_OPTS),
|
|
297
|
-
ch.purgeQueue(q),
|
|
298
|
-
ch.bindExchange(ex2, ex1, rk, {}),
|
|
299
|
-
ch.bindQueue(q, ex2, '', {})])
|
|
300
|
-
.then(function() {
|
|
301
|
-
return new Promise(function(resolve, reject) {
|
|
302
|
-
function delivery(m) {
|
|
303
|
-
if (m.content.toString() === msg) resolve();
|
|
304
|
-
else reject(new Error("Wrong message"));
|
|
305
|
-
}
|
|
306
|
-
ch.consume(q, delivery, {noAck: true})
|
|
307
|
-
.then(function() {
|
|
308
|
-
ch.publish(ex1, rk, Buffer.from(msg));
|
|
309
|
-
});
|
|
231
|
+
return Promise.all([
|
|
232
|
+
ch.assertExchange(ex, 'fanout', EX_OPTS),
|
|
233
|
+
ch.assertQueue(q, QUEUE_OPTS),
|
|
234
|
+
ch.purgeQueue(q),
|
|
235
|
+
ch.bindQueue(q, ex, '', {})])
|
|
236
|
+
.then(function() {
|
|
237
|
+
ch.publish(ex, '', Buffer.from(msg));
|
|
238
|
+
return waitForMessages(q);})
|
|
239
|
+
.then(function() {
|
|
240
|
+
return ch.get(q, {noAck: true});})
|
|
241
|
+
.then(function(m) {
|
|
242
|
+
assert(m);
|
|
243
|
+
assert.equal(msg, m.content.toString());
|
|
310
244
|
});
|
|
311
|
-
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
// bind again, unbind, publish, get-empty
|
|
315
|
-
chtest("unbind exchange", function(ch) {
|
|
316
|
-
var source = 'test.unbind-ex-source';
|
|
317
|
-
var dest = 'test.unbind-ex-dest';
|
|
318
|
-
var q = 'test.unbind-ex-queue';
|
|
319
|
-
var viabinding = randomString();
|
|
320
|
-
var direct = randomString();
|
|
321
|
-
|
|
322
|
-
return Promise.all([
|
|
323
|
-
ch.assertExchange(source, 'fanout', EX_OPTS),
|
|
324
|
-
ch.assertExchange(dest, 'fanout', EX_OPTS),
|
|
325
|
-
ch.assertQueue(q, QUEUE_OPTS),
|
|
326
|
-
ch.purgeQueue(q),
|
|
327
|
-
ch.bindExchange(dest, source, '', {}),
|
|
328
|
-
ch.bindQueue(q, dest, '', {})])
|
|
329
|
-
.then(function() {
|
|
330
|
-
ch.publish(source, '', Buffer.from('foobar'));
|
|
331
|
-
return waitForMessages(q);})
|
|
332
|
-
.then(function() { // message got through!
|
|
333
|
-
return ch.get(q, {noAck:true})
|
|
334
|
-
.then(function(m) {assert(m);});})
|
|
335
|
-
.then(function() {
|
|
336
|
-
return ch.unbindExchange(dest, source, '', {});})
|
|
337
|
-
.then(function() {
|
|
338
|
-
// via the no-longer-existing binding
|
|
339
|
-
ch.publish(source, '', Buffer.from(viabinding));
|
|
340
|
-
// direct to the queue
|
|
341
|
-
ch.sendToQueue(q, Buffer.from(direct));
|
|
342
|
-
return waitForMessages(q);})
|
|
343
|
-
.then(function() {return ch.get(q)})
|
|
344
|
-
.then(function(m) {
|
|
345
|
-
// the direct to queue message got through, the via-binding
|
|
346
|
-
// message (sent first) did not
|
|
347
|
-
assert.equal(direct, m.content.toString());
|
|
348
|
-
});
|
|
349
|
-
});
|
|
245
|
+
});
|
|
350
246
|
|
|
351
|
-
//
|
|
352
|
-
chtest("
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
.then(function(
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
})]);
|
|
247
|
+
// send to queue, purge, get-empty
|
|
248
|
+
chtest("purge queue", function(ch) {
|
|
249
|
+
var q = 'test.purge-queue';
|
|
250
|
+
return ch.assertQueue(q, {durable: false})
|
|
251
|
+
.then(function() {
|
|
252
|
+
ch.sendToQueue(q, Buffer.from('foobar'));
|
|
253
|
+
return waitForMessages(q);})
|
|
254
|
+
.then(function() {
|
|
255
|
+
ch.purgeQueue(q);
|
|
256
|
+
return ch.get(q, {noAck: true});})
|
|
257
|
+
.then(function(m) {
|
|
258
|
+
assert(!m); // get-empty
|
|
259
|
+
});
|
|
365
260
|
});
|
|
366
261
|
|
|
367
|
-
//
|
|
368
|
-
|
|
369
|
-
var
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
262
|
+
// bind again, unbind, publish, get-empty
|
|
263
|
+
chtest("unbind queue", function(ch) {
|
|
264
|
+
var ex = 'test.unbind-queue-ex';
|
|
265
|
+
var q = 'test.unbind-queue';
|
|
266
|
+
var viabinding = randomString();
|
|
267
|
+
var direct = randomString();
|
|
268
|
+
|
|
269
|
+
return Promise.all([
|
|
270
|
+
ch.assertExchange(ex, 'fanout', EX_OPTS),
|
|
271
|
+
ch.assertQueue(q, QUEUE_OPTS),
|
|
272
|
+
ch.purgeQueue(q),
|
|
273
|
+
ch.bindQueue(q, ex, '', {})])
|
|
375
274
|
.then(function() {
|
|
376
|
-
|
|
377
|
-
|
|
275
|
+
ch.publish(ex, '', Buffer.from('foobar'));
|
|
276
|
+
return waitForMessages(q);})
|
|
277
|
+
.then(function() { // message got through!
|
|
278
|
+
return ch.get(q, {noAck:true})
|
|
279
|
+
.then(function(m) {assert(m);});})
|
|
280
|
+
.then(function() {
|
|
281
|
+
return ch.unbindQueue(q, ex, '', {});})
|
|
282
|
+
.then(function() {
|
|
283
|
+
// via the no-longer-existing binding
|
|
284
|
+
ch.publish(ex, '', Buffer.from(viabinding));
|
|
285
|
+
// direct to the queue
|
|
286
|
+
ch.sendToQueue(q, Buffer.from(direct));
|
|
287
|
+
return waitForMessages(q);})
|
|
288
|
+
.then(function() {return ch.get(q)})
|
|
378
289
|
.then(function(m) {
|
|
379
|
-
//
|
|
380
|
-
//
|
|
381
|
-
|
|
382
|
-
throw new Error();
|
|
383
|
-
}
|
|
290
|
+
// the direct to queue message got through, the via-binding
|
|
291
|
+
// message (sent first) did not
|
|
292
|
+
assert.equal(direct, m.content.toString());
|
|
384
293
|
});
|
|
294
|
+
});
|
|
385
295
|
|
|
386
|
-
|
|
296
|
+
// To some extent this is now just testing semantics of the server,
|
|
297
|
+
// but we can at least try out a few settings, and consume.
|
|
298
|
+
chtest("consume via exchange-exchange binding", function(ch) {
|
|
299
|
+
var ex1 = 'test.ex-ex-binding1', ex2 = 'test.ex-ex-binding2';
|
|
300
|
+
var q = 'test.ex-ex-binding-q';
|
|
301
|
+
var rk = 'test.routing.key', msg = randomString();
|
|
302
|
+
return Promise.all([
|
|
303
|
+
ch.assertExchange(ex1, 'direct', EX_OPTS),
|
|
304
|
+
ch.assertExchange(ex2, 'fanout',
|
|
305
|
+
{durable: false, internal: true}),
|
|
306
|
+
ch.assertQueue(q, QUEUE_OPTS),
|
|
307
|
+
ch.purgeQueue(q),
|
|
308
|
+
ch.bindExchange(ex2, ex1, rk, {}),
|
|
309
|
+
ch.bindQueue(q, ex2, '', {})])
|
|
310
|
+
.then(function() {
|
|
311
|
+
return new Promise(function(resolve, reject) {
|
|
312
|
+
function delivery(m) {
|
|
313
|
+
if (m.content.toString() === msg) resolve();
|
|
314
|
+
else reject(new Error("Wrong message"));
|
|
315
|
+
}
|
|
316
|
+
ch.consume(q, delivery, {noAck: true})
|
|
317
|
+
.then(function() {
|
|
318
|
+
ch.publish(ex1, rk, Buffer.from(msg));
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
});
|
|
387
322
|
});
|
|
388
|
-
});
|
|
389
323
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
324
|
+
// bind again, unbind, publish, get-empty
|
|
325
|
+
chtest("unbind exchange", function(ch) {
|
|
326
|
+
var source = 'test.unbind-ex-source';
|
|
327
|
+
var dest = 'test.unbind-ex-dest';
|
|
328
|
+
var q = 'test.unbind-ex-queue';
|
|
329
|
+
var viabinding = randomString();
|
|
330
|
+
var direct = randomString();
|
|
331
|
+
|
|
393
332
|
return Promise.all([
|
|
394
|
-
ch.
|
|
333
|
+
ch.assertExchange(source, 'fanout', EX_OPTS),
|
|
334
|
+
ch.assertExchange(dest, 'fanout', EX_OPTS),
|
|
335
|
+
ch.assertQueue(q, QUEUE_OPTS),
|
|
395
336
|
ch.purgeQueue(q),
|
|
396
|
-
ch.
|
|
397
|
-
|
|
398
|
-
else reject(new Error('Message not expected'));
|
|
399
|
-
})])
|
|
337
|
+
ch.bindExchange(dest, source, '', {}),
|
|
338
|
+
ch.bindQueue(q, dest, '', {})])
|
|
400
339
|
.then(function() {
|
|
401
|
-
|
|
340
|
+
ch.publish(source, '', Buffer.from('foobar'));
|
|
341
|
+
return waitForMessages(q);})
|
|
342
|
+
.then(function() { // message got through!
|
|
343
|
+
return ch.get(q, {noAck:true})
|
|
344
|
+
.then(function(m) {assert(m);});})
|
|
345
|
+
.then(function() {
|
|
346
|
+
return ch.unbindExchange(dest, source, '', {});})
|
|
347
|
+
.then(function() {
|
|
348
|
+
// via the no-longer-existing binding
|
|
349
|
+
ch.publish(source, '', Buffer.from(viabinding));
|
|
350
|
+
// direct to the queue
|
|
351
|
+
ch.sendToQueue(q, Buffer.from(direct));
|
|
352
|
+
return waitForMessages(q);})
|
|
353
|
+
.then(function() {return ch.get(q)})
|
|
354
|
+
.then(function(m) {
|
|
355
|
+
// the direct to queue message got through, the via-binding
|
|
356
|
+
// message (sent first) did not
|
|
357
|
+
assert.equal(direct, m.content.toString());
|
|
402
358
|
});
|
|
403
359
|
});
|
|
404
|
-
});
|
|
405
360
|
|
|
406
|
-
//
|
|
407
|
-
chtest("
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
ch.
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
return ch.get(q, {noAck: false})
|
|
421
|
-
})
|
|
422
|
-
.then(function(m) {
|
|
423
|
-
assert.equal(msg1, m.content.toString());
|
|
424
|
-
ch.ack(m);
|
|
425
|
-
// %%% is there a race here? may depend on
|
|
426
|
-
// rabbitmq-sepcific semantics
|
|
427
|
-
return ch.get(q);
|
|
428
|
-
})
|
|
429
|
-
.then(function(m) {
|
|
430
|
-
assert(m);
|
|
431
|
-
assert.equal(msg2, m.content.toString());
|
|
361
|
+
// This is a bit convoluted. Sorry.
|
|
362
|
+
chtest("cancel consumer", function(ch) {
|
|
363
|
+
var q = 'test.consumer-cancel';
|
|
364
|
+
var ctag;
|
|
365
|
+
var recv1 = new Promise(function (resolve, reject) {
|
|
366
|
+
Promise.all([
|
|
367
|
+
ch.assertQueue(q, QUEUE_OPTS),
|
|
368
|
+
ch.purgeQueue(q),
|
|
369
|
+
// My callback is 'resolve the promise in `arrived`'
|
|
370
|
+
ch.consume(q, resolve, {noAck:true})
|
|
371
|
+
.then(function(ok) {
|
|
372
|
+
ctag = ok.consumerTag;
|
|
373
|
+
ch.sendToQueue(q, Buffer.from('foo'));
|
|
374
|
+
})]);
|
|
432
375
|
});
|
|
433
|
-
});
|
|
434
376
|
|
|
435
|
-
//
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
assert(m);
|
|
456
|
-
assert.equal(msg1, m.content.toString());
|
|
377
|
+
// A message should arrive because of the consume
|
|
378
|
+
return recv1.then(function() {
|
|
379
|
+
var recv2 = Promise.all([
|
|
380
|
+
ch.cancel(ctag).then(function() {
|
|
381
|
+
return ch.sendToQueue(q, Buffer.from('bar'));
|
|
382
|
+
}),
|
|
383
|
+
// but check a message did arrive in the queue
|
|
384
|
+
waitForMessages(q)])
|
|
385
|
+
.then(function() {
|
|
386
|
+
return ch.get(q, {noAck:true});
|
|
387
|
+
})
|
|
388
|
+
.then(function(m) {
|
|
389
|
+
// I'm going to reject it, because I flip succeed/fail
|
|
390
|
+
// just below
|
|
391
|
+
if (m.content.toString() === 'bar') {
|
|
392
|
+
throw new Error();
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
return expectFail(recv2);
|
|
457
397
|
});
|
|
458
|
-
});
|
|
398
|
+
});
|
|
459
399
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
.then(function(m) {
|
|
474
|
-
assert.equal(msg1, m.content.toString());
|
|
475
|
-
ch.reject(m);
|
|
476
|
-
return waitForMessages(q);})
|
|
477
|
-
.then(function() {
|
|
478
|
-
return ch.get(q);})
|
|
479
|
-
.then(function(m) {
|
|
480
|
-
assert(m);
|
|
481
|
-
assert.equal(msg1, m.content.toString());
|
|
400
|
+
chtest("cancelled consumer", function(ch) {
|
|
401
|
+
var q = 'test.cancelled-consumer';
|
|
402
|
+
return new Promise(function(resolve, reject) {
|
|
403
|
+
return Promise.all([
|
|
404
|
+
ch.assertQueue(q),
|
|
405
|
+
ch.purgeQueue(q),
|
|
406
|
+
ch.consume(q, function(msg) {
|
|
407
|
+
if (msg === null) resolve();
|
|
408
|
+
else reject(new Error('Message not expected'));
|
|
409
|
+
})])
|
|
410
|
+
.then(function() {
|
|
411
|
+
return ch.deleteQueue(q);
|
|
412
|
+
});
|
|
482
413
|
});
|
|
483
|
-
});
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
// ack, by default, removes a single message from the queue
|
|
417
|
+
chtest("ack", function(ch) {
|
|
418
|
+
var q = 'test.ack';
|
|
419
|
+
var msg1 = randomString(), msg2 = randomString();
|
|
420
|
+
|
|
421
|
+
return Promise.all([
|
|
422
|
+
ch.assertQueue(q, QUEUE_OPTS),
|
|
423
|
+
ch.purgeQueue(q)])
|
|
424
|
+
.then(function() {
|
|
425
|
+
ch.sendToQueue(q, Buffer.from(msg1));
|
|
426
|
+
ch.sendToQueue(q, Buffer.from(msg2));
|
|
427
|
+
return waitForMessages(q, 2);
|
|
428
|
+
})
|
|
429
|
+
.then(function() {
|
|
430
|
+
return ch.get(q, {noAck: false})
|
|
431
|
+
})
|
|
432
|
+
.then(function(m) {
|
|
433
|
+
assert.equal(msg1, m.content.toString());
|
|
434
|
+
ch.ack(m);
|
|
435
|
+
// %%% is there a race here? may depend on
|
|
436
|
+
// rabbitmq-sepcific semantics
|
|
437
|
+
return ch.get(q);
|
|
438
|
+
})
|
|
439
|
+
.then(function(m) {
|
|
440
|
+
assert(m);
|
|
441
|
+
assert.equal(msg2, m.content.toString());
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// Nack, by default, puts a message back on the queue (where in the
|
|
446
|
+
// queue is up to the server)
|
|
447
|
+
chtest("nack", function(ch) {
|
|
448
|
+
var q = 'test.nack';
|
|
449
|
+
var msg1 = randomString();
|
|
450
|
+
|
|
451
|
+
return Promise.all([
|
|
452
|
+
ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
|
|
453
|
+
.then(function() {
|
|
454
|
+
ch.sendToQueue(q, Buffer.from(msg1));
|
|
455
|
+
return waitForMessages(q);})
|
|
456
|
+
.then(function() {
|
|
457
|
+
return ch.get(q, {noAck: false})})
|
|
458
|
+
.then(function(m) {
|
|
459
|
+
assert.equal(msg1, m.content.toString());
|
|
460
|
+
ch.nack(m);
|
|
461
|
+
return waitForMessages(q);})
|
|
462
|
+
.then(function() {
|
|
463
|
+
return ch.get(q);})
|
|
464
|
+
.then(function(m) {
|
|
465
|
+
assert(m);
|
|
466
|
+
assert.equal(msg1, m.content.toString());
|
|
467
|
+
});
|
|
468
|
+
});
|
|
484
469
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
ch.
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
470
|
+
// reject is a near-synonym for nack, the latter of which is not
|
|
471
|
+
// available in earlier RabbitMQ (or in AMQP proper).
|
|
472
|
+
chtest("reject", function(ch) {
|
|
473
|
+
var q = 'test.reject';
|
|
474
|
+
var msg1 = randomString();
|
|
475
|
+
|
|
476
|
+
return Promise.all([
|
|
477
|
+
ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
|
|
478
|
+
.then(function() {
|
|
479
|
+
ch.sendToQueue(q, Buffer.from(msg1));
|
|
480
|
+
return waitForMessages(q);})
|
|
481
|
+
.then(function() {
|
|
482
|
+
return ch.get(q, {noAck: false})})
|
|
483
|
+
.then(function(m) {
|
|
484
|
+
assert.equal(msg1, m.content.toString());
|
|
485
|
+
ch.reject(m);
|
|
486
|
+
return waitForMessages(q);})
|
|
487
|
+
.then(function() {
|
|
488
|
+
return ch.get(q);})
|
|
489
|
+
.then(function(m) {
|
|
490
|
+
assert(m);
|
|
491
|
+
assert.equal(msg1, m.content.toString());
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
chtest("prefetch", function(ch) {
|
|
496
|
+
var q = 'test.prefetch';
|
|
497
|
+
return Promise.all([
|
|
498
|
+
ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q),
|
|
499
|
+
ch.prefetch(1)])
|
|
500
|
+
.then(function() {
|
|
501
|
+
ch.sendToQueue(q, Buffer.from('foobar'));
|
|
502
|
+
ch.sendToQueue(q, Buffer.from('foobar'));
|
|
503
|
+
return waitForMessages(q, 2);
|
|
504
|
+
})
|
|
505
|
+
.then(function() {
|
|
506
|
+
return new Promise(function(resolve) {
|
|
507
|
+
var messageCount = 0;
|
|
508
|
+
function receive(msg) {
|
|
509
|
+
ch.ack(msg);
|
|
510
|
+
if (++messageCount > 1) {
|
|
511
|
+
resolve(messageCount);
|
|
512
|
+
}
|
|
502
513
|
}
|
|
503
|
-
|
|
504
|
-
|
|
514
|
+
return ch.consume(q, receive, {noAck: false})
|
|
515
|
+
});
|
|
516
|
+
})
|
|
517
|
+
.then(function(c) {
|
|
518
|
+
return assert.equal(2, c);
|
|
505
519
|
});
|
|
506
|
-
|
|
507
|
-
.then(function(c) {
|
|
508
|
-
return assert.equal(2, c);
|
|
509
|
-
});
|
|
510
|
-
});
|
|
520
|
+
});
|
|
511
521
|
|
|
512
|
-
chtest('close', function(ch) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
});
|
|
522
|
+
chtest('close', function(ch) {
|
|
523
|
+
// Resolving promise guarantees
|
|
524
|
+
// channel is closed
|
|
525
|
+
return ch.close();
|
|
526
|
+
});
|
|
517
527
|
|
|
518
528
|
});
|
|
519
529
|
|
|
@@ -521,76 +531,76 @@ var confirmtest = channel_test.bind(null, 'createConfirmChannel');
|
|
|
521
531
|
|
|
522
532
|
suite("confirms", function() {
|
|
523
533
|
|
|
524
|
-
confirmtest('message is confirmed', function(ch) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
// Usually one can provoke the server into confirming more than one
|
|
534
|
-
// message in an ack by simply sending a few messages in quick
|
|
535
|
-
// succession; a bit unscientific I know. Luckily we can eavesdrop on
|
|
536
|
-
// the acknowledgements coming through to see if we really did get a
|
|
537
|
-
// multi-ack.
|
|
538
|
-
confirmtest('multiple confirms', function(ch) {
|
|
539
|
-
var q = 'test.multiple-confirms';
|
|
540
|
-
return Promise.all([
|
|
541
|
-
ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
|
|
542
|
-
.then(function() {
|
|
543
|
-
var multipleRainbows = false;
|
|
544
|
-
ch.on('ack', function(a) {
|
|
545
|
-
if (a.multiple) multipleRainbows = true;
|
|
534
|
+
confirmtest('message is confirmed', function(ch) {
|
|
535
|
+
var q = 'test.confirm-message';
|
|
536
|
+
return Promise.all([
|
|
537
|
+
ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
|
|
538
|
+
.then(function() {
|
|
539
|
+
return ch.sendToQueue(q, Buffer.from('bleep'));
|
|
546
540
|
});
|
|
541
|
+
});
|
|
547
542
|
|
|
548
|
-
|
|
549
|
-
|
|
543
|
+
// Usually one can provoke the server into confirming more than one
|
|
544
|
+
// message in an ack by simply sending a few messages in quick
|
|
545
|
+
// succession; a bit unscientific I know. Luckily we can eavesdrop on
|
|
546
|
+
// the acknowledgements coming through to see if we really did get a
|
|
547
|
+
// multi-ack.
|
|
548
|
+
confirmtest('multiple confirms', function(ch) {
|
|
549
|
+
var q = 'test.multiple-confirms';
|
|
550
|
+
return Promise.all([
|
|
551
|
+
ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
|
|
552
|
+
.then(function() {
|
|
553
|
+
var multipleRainbows = false;
|
|
554
|
+
ch.on('ack', function(a) {
|
|
555
|
+
if (a.multiple) multipleRainbows = true;
|
|
556
|
+
});
|
|
550
557
|
|
|
551
|
-
function
|
|
552
|
-
var
|
|
553
|
-
return ch.sendToQueue(q, Buffer.from('bleep'), {}, cb);
|
|
554
|
-
})();
|
|
555
|
-
cs.push(conf);
|
|
556
|
-
}
|
|
558
|
+
function prod(num) {
|
|
559
|
+
var cs = [];
|
|
557
560
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
"Couldn't provoke the server" +
|
|
564
|
-
" into multi-acking with " + num +
|
|
565
|
-
" messages; giving up");
|
|
566
|
-
else {
|
|
567
|
-
//console.warn("Failed with " + num + "; trying " + num * 2);
|
|
568
|
-
return prod(num * 2);
|
|
561
|
+
function sendAndPushPromise() {
|
|
562
|
+
var conf = promisify(function(cb) {
|
|
563
|
+
return ch.sendToQueue(q, Buffer.from('bleep'), {}, cb);
|
|
564
|
+
})();
|
|
565
|
+
cs.push(conf);
|
|
569
566
|
}
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
return prod(5);
|
|
573
|
-
});
|
|
574
|
-
});
|
|
575
567
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
568
|
+
for (var i=0; i < num; i++) sendAndPushPromise();
|
|
569
|
+
|
|
570
|
+
return Promise.all(cs).then(function() {
|
|
571
|
+
if (multipleRainbows) return true;
|
|
572
|
+
else if (num > 500) throw new Error(
|
|
573
|
+
"Couldn't provoke the server" +
|
|
574
|
+
" into multi-acking with " + num +
|
|
575
|
+
" messages; giving up");
|
|
576
|
+
else {
|
|
577
|
+
//console.warn("Failed with " + num + "; trying " + num * 2);
|
|
578
|
+
return prod(num * 2);
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
return prod(5);
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
confirmtest('wait for confirms', function(ch) {
|
|
587
|
+
for (var i=0; i < 1000; i++) {
|
|
588
|
+
ch.publish('', '', Buffer.from('foobar'), {});
|
|
589
|
+
}
|
|
590
|
+
return ch.waitForConfirms();
|
|
591
|
+
})
|
|
592
|
+
|
|
593
|
+
confirmtest('works when channel is closed', function(ch) {
|
|
594
|
+
for (var i=0; i < 1000; i++) {
|
|
595
|
+
ch.publish('', '', Buffer.from('foobar'), {});
|
|
596
|
+
}
|
|
597
|
+
return ch.close().then(function () {
|
|
598
|
+
return ch.waitForConfirms()
|
|
599
|
+
}).then(function () {
|
|
600
|
+
assert.strictEqual(true, false, 'Wait should have failed.')
|
|
601
|
+
}, function (e) {
|
|
602
|
+
assert.strictEqual(e.message, 'channel closed')
|
|
603
|
+
});
|
|
593
604
|
});
|
|
594
|
-
});
|
|
595
605
|
|
|
596
606
|
});
|