amqplib 0.10.3 → 0.10.5
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 +7 -4
- package/.github/workflows/publish.yml +59 -0
- package/.github/workflows/test.yml +15 -2
- package/CHANGELOG.md +14 -1
- package/Makefile +22 -20
- package/README.md +1 -2
- package/bin/amqp-rabbitmq-0.9.1.json +483 -0
- 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 +26 -2
- package/lib/connection.js +544 -532
- package/lib/credentials.js +1 -1
- package/lib/defs.js +2568 -2457
- package/lib/format.js +0 -1
- package/lib/heartbeat.js +32 -29
- package/lib/mux.js +96 -99
- package/package.json +3 -5
- package/test/callback_api.js +182 -174
- package/test/channel_api.js +455 -445
- package/test/codec.js +15 -15
- package/test/data.js +15 -0
- package/test/frame.js +6 -7
- package/test/mux.js +1 -2
- package/test/util.js +1 -3
|
@@ -1,56 +1,57 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const amqp = require('amqplib/callback_api');
|
|
4
|
+
const { basename } = require('path');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var severities = process.argv.slice(2);
|
|
6
|
+
const exchange = 'direct_logs';
|
|
7
|
+
const severities = process.argv.slice(2);
|
|
8
8
|
if (severities.length < 1) {
|
|
9
|
-
console.log('Usage %s [info] [warning] [error]',
|
|
10
|
-
basename(process.argv[1]));
|
|
9
|
+
console.log('Usage %s [info] [warning] [error]', basename(process.argv[1]));
|
|
11
10
|
process.exit(1);
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function on_connect(err, conn) {
|
|
20
|
-
if (err !== null) return bail(err);
|
|
21
|
-
process.once('SIGINT', function() { conn.close(); });
|
|
22
|
-
|
|
23
|
-
conn.createChannel(function(err, ch) {
|
|
24
|
-
if (err !== null) return bail(err, conn);
|
|
25
|
-
var ex = 'direct_logs', exopts = {durable: false};
|
|
26
|
-
|
|
27
|
-
ch.assertExchange(ex, 'direct', exopts);
|
|
28
|
-
ch.assertQueue('', {exclusive: true}, function(err, ok) {
|
|
29
|
-
if (err !== null) return bail(err, conn);
|
|
30
|
-
|
|
31
|
-
var queue = ok.queue, i = 0;
|
|
13
|
+
amqp.connect((err, connection) => {
|
|
14
|
+
if (err) return bail(err);
|
|
15
|
+
connection.createChannel((err, channel) => {
|
|
16
|
+
if (err) return bail(err, connection);
|
|
32
17
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
}
|
|
18
|
+
process.once('SIGINT', () => {
|
|
19
|
+
channel.close(() => {
|
|
20
|
+
connection.close();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
40
23
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
channel.assertExchange(exchange, 'direct', { durable: false }, (err) => {
|
|
25
|
+
if (err) return bail(err, connection);
|
|
26
|
+
channel.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
|
27
|
+
if (err) return bail(err, connection);
|
|
28
|
+
channel.consume(queue, (message) => {
|
|
29
|
+
if (message) console.log(" [x] %s:'%s'", message.fields.routingKey, message.content.toString());
|
|
30
|
+
else console.warn(' [x] Consumer cancelled');
|
|
31
|
+
}, {noAck: true}, function(err) {
|
|
32
|
+
if (err) return bail(err, connection);
|
|
33
|
+
console.log(' [*] Waiting for logs. To exit press CTRL+C.');
|
|
34
|
+
subscribeAll(channel, queue, severities, (err) => {
|
|
35
|
+
if (err) return bail(err, connection);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
45
38
|
});
|
|
46
39
|
});
|
|
47
40
|
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function subscribeAll(channel, queue, bindingKeys, cb) {
|
|
44
|
+
if (bindingKeys.length === 0) return cb();
|
|
45
|
+
const bindingKey = bindingKeys.shift();
|
|
46
|
+
channel.bindQueue(queue, exchange, bindingKey, {}, (err) => {
|
|
47
|
+
if (err) return cb(err);
|
|
48
|
+
subscribeAll(channel, queue, bindingKeys, cb);
|
|
49
|
+
});
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
function
|
|
51
|
-
console.
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
function bail(err, connection) {
|
|
53
|
+
console.error(err);
|
|
54
|
+
if (connection) connection.close(() => {
|
|
55
|
+
process.exit(1);
|
|
56
|
+
});
|
|
54
57
|
}
|
|
55
|
-
|
|
56
|
-
amqp.connect(on_connect);
|
|
@@ -1,55 +1,58 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const amqp = require('amqplib/callback_api');
|
|
4
|
+
const { basename } = require('path');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const exchange = 'topic_logs';
|
|
7
|
+
const severities = process.argv.slice(2);
|
|
8
|
+
if (severities.length < 1) {
|
|
9
|
+
console.log('Usage %s [info] [warning] [error]', basename(process.argv[1]));
|
|
10
10
|
process.exit(1);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function on_connect(err, conn) {
|
|
19
|
-
if (err !== null) return bail(err);
|
|
20
|
-
process.once('SIGINT', function() { conn.close(); });
|
|
21
|
-
|
|
22
|
-
conn.createChannel(function(err, ch) {
|
|
23
|
-
if (err !== null) return bail(err, conn);
|
|
24
|
-
var ex = 'topic_logs', exopts = {durable: false};
|
|
25
|
-
|
|
26
|
-
ch.assertExchange(ex, 'topic', exopts);
|
|
27
|
-
ch.assertQueue('', {exclusive: true}, function(err, ok) {
|
|
28
|
-
if (err !== null) return bail(err, conn);
|
|
29
|
-
|
|
30
|
-
var queue = ok.queue, i = 0;
|
|
13
|
+
amqp.connect((err, connection) => {
|
|
14
|
+
if (err) return bail(err);
|
|
15
|
+
connection.createChannel((err, channel) => {
|
|
16
|
+
if (err) return bail(err, connection);
|
|
31
17
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
}
|
|
18
|
+
process.once('SIGINT', () => {
|
|
19
|
+
channel.close(() => {
|
|
20
|
+
connection.close();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
39
23
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
channel.assertExchange(exchange, 'topic', { durable: false }, (err) => {
|
|
25
|
+
if (err) return bail(err, connection);
|
|
26
|
+
channel.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
|
27
|
+
if (err) return bail(err, connection);
|
|
28
|
+
channel.consume(queue, (message) => {
|
|
29
|
+
if (message) console.log(" [x] %s:'%s'", message.fields.routingKey, message.content.toString());
|
|
30
|
+
else console.warn(' [x] Consumer cancelled');
|
|
31
|
+
}, {noAck: true}, function(err) {
|
|
32
|
+
if (err) return bail(err, connection);
|
|
33
|
+
console.log(' [*] Waiting for logs. To exit press CTRL+C.');
|
|
34
|
+
subscribeAll(channel, queue, severities, (err) => {
|
|
35
|
+
if (err) return bail(err, connection);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
44
38
|
});
|
|
45
39
|
});
|
|
46
40
|
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function subscribeAll(channel, queue, bindingKeys, cb) {
|
|
44
|
+
if (bindingKeys.length === 0) return cb();
|
|
45
|
+
const bindingKey = bindingKeys.shift();
|
|
46
|
+
channel.bindQueue(queue, exchange, bindingKey, {}, (err) => {
|
|
47
|
+
if (err) return cb(err);
|
|
48
|
+
subscribeAll(channel, queue, bindingKeys, cb);
|
|
49
|
+
});
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
function
|
|
50
|
-
console.
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
function bail(err, connection) {
|
|
53
|
+
console.error(err);
|
|
54
|
+
if (connection) connection.close(() => {
|
|
55
|
+
process.exit(1);
|
|
56
|
+
});
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
amqp.connect(on_connect);
|
|
@@ -1,49 +1,51 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
catch (e) {
|
|
13
|
-
console.error(e);
|
|
3
|
+
const amqp = require('amqplib/callback_api');
|
|
4
|
+
const { basename } = require('path');
|
|
5
|
+
const { v4: uuid } = require('uuid');
|
|
6
|
+
|
|
7
|
+
const queue = 'rpc_queue';
|
|
8
|
+
|
|
9
|
+
const n = parseInt(process.argv[2], 10);
|
|
10
|
+
if (isNaN(n)) {
|
|
14
11
|
console.warn('Usage: %s number', basename(process.argv[1]));
|
|
15
12
|
process.exit(1);
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
amqp.connect((err, connection) => {
|
|
16
|
+
if (err) return bail(err);
|
|
17
|
+
connection.createChannel((err, channel) => {
|
|
18
|
+
if (err) return bail(err, connection);
|
|
19
|
+
channel.assertQueue('', { exclusive: true }, (err, { queue: replyTo }) => {
|
|
20
|
+
if (err) return bail(err, connection);
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
console.log(' [x] Requesting fib(%d)', n);
|
|
42
|
-
ch.sendToQueue('rpc_queue', Buffer.from(n.toString()), {
|
|
43
|
-
replyTo: queue, correlationId: correlationId
|
|
22
|
+
const correlationId = uuid();
|
|
23
|
+
channel.consume(replyTo, (message) => {
|
|
24
|
+
if (!message) console.warn(' [x] Consumer cancelled');
|
|
25
|
+
else if (message.properties.correlationId === correlationId) {
|
|
26
|
+
console.log(' [.] Got %d', message.content.toString());
|
|
27
|
+
channel.close(() => {
|
|
28
|
+
connection.close();
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
}, { noAck: true });
|
|
32
|
+
|
|
33
|
+
channel.assertQueue(queue, { durable: false }, (err) => {
|
|
34
|
+
if (err) return bail(err, connection);
|
|
35
|
+
console.log(' [x] Requesting fib(%d)', n);
|
|
36
|
+
channel.sendToQueue(queue, Buffer.from(n.toString()), {
|
|
37
|
+
correlationId,
|
|
38
|
+
replyTo
|
|
39
|
+
});
|
|
44
40
|
});
|
|
45
41
|
});
|
|
46
42
|
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
function bail(err, connection) {
|
|
46
|
+
console.error(err);
|
|
47
|
+
if (connection) connection.close(() => {
|
|
48
|
+
process.exit(1);
|
|
49
|
+
});
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
amqp.connect(on_connect);
|
|
@@ -1,45 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const amqp = require('amqplib/callback_api');
|
|
4
|
+
|
|
5
|
+
const queue = 'rpc_queue';
|
|
6
|
+
|
|
7
|
+
amqp.connect((err, connection) => {
|
|
8
|
+
if (err) return bail(err);
|
|
9
|
+
connection.createChannel((err, channel) => {
|
|
10
|
+
if (err) return bail(err, connection);
|
|
11
|
+
|
|
12
|
+
process.once('SIGINT', () => {
|
|
13
|
+
channel.close(() => {
|
|
14
|
+
connection.close();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
channel.assertQueue(queue, { durable: false }, (err) => {
|
|
19
|
+
if (err) return bail(err, connection);
|
|
20
|
+
channel.prefetch(1);
|
|
21
|
+
channel.consume(queue, (message) => {
|
|
22
|
+
const n = parseInt(message.content.toString(), 10);
|
|
23
|
+
console.log(' [.] fib(%d)', n);
|
|
24
|
+
const response = fib(n);
|
|
25
|
+
channel.sendToQueue(message.properties.replyTo, Buffer.from(response.toString()), {
|
|
26
|
+
correlationId: message.properties.correlationId
|
|
27
|
+
});
|
|
28
|
+
channel.ack(message);
|
|
29
|
+
}, { noAck: false }, function(err) {
|
|
30
|
+
if (err) return bail(err, conn);
|
|
31
|
+
console.log(' [x] Awaiting RPC requests. To exit press CTRL+C.');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
4
36
|
|
|
5
37
|
function fib(n) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
38
|
+
// Do it the ridiculous, but not most ridiculous, way. For better,
|
|
39
|
+
// see http://nayuki.eigenstate.org/page/fast-fibonacci-algorithms
|
|
40
|
+
let a = 0, b = 1;
|
|
41
|
+
for (let i=0; i < n; i++) {
|
|
42
|
+
let c = a + b;
|
|
9
43
|
a = b; b = c;
|
|
10
44
|
}
|
|
11
45
|
return a;
|
|
12
46
|
}
|
|
13
47
|
|
|
14
|
-
function bail(err, conn) {
|
|
15
|
-
console.error(err);
|
|
16
|
-
if (conn) conn.close(function() { process.exit(1); });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function on_connect(err, conn) {
|
|
20
|
-
if (err !== null) return bail(err);
|
|
21
|
-
|
|
22
|
-
process.once('SIGINT', function() { conn.close(); });
|
|
23
|
-
|
|
24
|
-
var q = 'rpc_queue';
|
|
25
48
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (err !== null) return bail(err, conn);
|
|
31
|
-
console.log(' [x] Awaiting RPC requests');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
function reply(msg) {
|
|
35
|
-
var n = parseInt(msg.content.toString());
|
|
36
|
-
console.log(' [.] fib(%d)', n);
|
|
37
|
-
ch.sendToQueue(msg.properties.replyTo,
|
|
38
|
-
Buffer.from(fib(n).toString()),
|
|
39
|
-
{correlationId: msg.properties.correlationId});
|
|
40
|
-
ch.ack(msg);
|
|
41
|
-
}
|
|
49
|
+
function bail(err, connection) {
|
|
50
|
+
console.error(err);
|
|
51
|
+
if (connection) connection.close(() => {
|
|
52
|
+
process.exit(1);
|
|
42
53
|
});
|
|
43
54
|
}
|
|
44
55
|
|
|
45
|
-
amqp.connect(on_connect);
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const amqp = require('amqplib/callback_api');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (conn) conn.close(function() { process.exit(1); });
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function on_connect(err, conn) {
|
|
11
|
-
if (err !== null) return bail(err);
|
|
5
|
+
const queue = 'hello';
|
|
6
|
+
const text = 'Hello World!';
|
|
12
7
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
amqp.connect((err, connection) => {
|
|
9
|
+
if (err) return bail(err);
|
|
10
|
+
connection.createChannel((err, channel) => {
|
|
11
|
+
if (err) return bail(err, connection);
|
|
12
|
+
channel.assertQueue(queue, { durable: false }, (err) => {
|
|
13
|
+
if (err) return bail(err, connection);
|
|
14
|
+
channel.sendToQueue(queue, Buffer.from(text));
|
|
15
|
+
console.log(" [x] Sent '%s'", text);
|
|
16
|
+
channel.close(() => {
|
|
17
|
+
connection.close();
|
|
18
|
+
});
|
|
23
19
|
});
|
|
24
|
-
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
function bail(err, connection) {
|
|
24
|
+
console.error(err);
|
|
25
|
+
if (connection) connection.close(() => {
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
amqp.connect(on_connect);
|
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const amqp = require('amqplib/callback_api');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
console.error(err);
|
|
7
|
-
if (conn) conn.close(function() { process.exit(1); });
|
|
8
|
-
}
|
|
5
|
+
const queue = 'task_queue';
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
if (err
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
amqp.connect((err, connection) => {
|
|
8
|
+
if (err) return bail(err);
|
|
9
|
+
connection.createChannel((err, channel) => {
|
|
10
|
+
if (err) return bail(err, connection);
|
|
11
|
+
|
|
12
|
+
process.once('SIGINT', () => {
|
|
13
|
+
channel.close(() => {
|
|
14
|
+
connection.close();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
channel.assertQueue(queue, { durable: true }, (err, { queue }) => {
|
|
19
|
+
if (err) return bail(err, connection);
|
|
20
|
+
channel.consume(queue, (message) => {
|
|
21
|
+
const text = message.content.toString();
|
|
22
|
+
console.log(" [x] Received '%s'", text);
|
|
23
|
+
const seconds = text.split('.').length - 1;
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
console.log(" [x] Done");
|
|
26
|
+
channel.ack(message);
|
|
27
|
+
}, seconds * 1000);
|
|
28
|
+
}, { noAck: false });
|
|
20
29
|
console.log(" [*] Waiting for messages. To exit press CTRL+C");
|
|
21
30
|
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
22
33
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
setTimeout(function() {
|
|
28
|
-
console.log(" [x] Done");
|
|
29
|
-
ch.ack(msg);
|
|
30
|
-
}, secs * 1000);
|
|
31
|
-
}
|
|
34
|
+
function bail(err, connection) {
|
|
35
|
+
console.error(err);
|
|
36
|
+
if (connection) connection.close(() => {
|
|
37
|
+
process.exit(1);
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
|
-
|
|
35
|
-
amqp.connect(on_connect);
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const amqp = require('amqplib');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var ex = 'logs';
|
|
8
|
-
var ok = ch.assertExchange(ex, 'fanout', {durable: false})
|
|
5
|
+
const exchange = 'logs';
|
|
6
|
+
const text = process.argv.slice(2).join(' ') || 'info: Hello World!';
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
8
|
+
(async () => {
|
|
9
|
+
let connection;
|
|
10
|
+
try {
|
|
11
|
+
connection = await amqp.connect('amqp://localhost');
|
|
12
|
+
const channel = await connection.createChannel();
|
|
13
|
+
await channel.assertExchange(exchange, 'fanout', { durable: false });
|
|
14
|
+
channel.publish(exchange, '', Buffer.from(text));
|
|
15
|
+
console.log(" [x] Sent '%s'", text);
|
|
16
|
+
await channel.close();
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
console.warn(err);
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
if (connection) await connection.close();
|
|
23
|
+
};
|
|
24
|
+
})();
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const amqp = require('amqplib');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const exchange = 'direct_logs';
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const routingKey = (args.length > 0) ? args[0] : 'info';
|
|
8
|
+
const text = args.slice(1).join(' ') || 'Hello World!';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
(async () => {
|
|
11
|
+
let connection;
|
|
12
|
+
try {
|
|
13
|
+
connection = await amqp.connect('amqp://localhost');
|
|
14
|
+
const channel = await connection.createChannel();
|
|
15
|
+
await channel.assertExchange(exchange, 'direct', { durable: false });
|
|
16
|
+
channel.publish(exchange, routingKey, Buffer.from(text));
|
|
17
|
+
console.log(" [x] Sent %s:'%s'", routingKey, text);
|
|
18
|
+
await channel.close();
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
console.warn(err);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
if (connection) await connection.close();
|
|
25
|
+
};
|
|
26
|
+
})();
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const amqp = require('amqplib');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const exchange = 'topic_logs';
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const routingKeys = (args.length > 0) ? args[0] : 'info';
|
|
8
|
+
const text = args.slice(1).join(' ') || 'Hello World!';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
10
|
+
(async () => {
|
|
11
|
+
let connection;
|
|
12
|
+
try {
|
|
13
|
+
connection = await amqp.connect('amqp://localhost');
|
|
14
|
+
const channel = await connection.createChannel();
|
|
15
|
+
await channel.assertExchange(exchange, 'topic', { durable: false });
|
|
16
|
+
channel.publish(exchange, routingKeys, Buffer.from(text));
|
|
17
|
+
console.log(" [x] Sent %s:'%s'", routingKeys, text);
|
|
18
|
+
await channel.close();
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
console.warn(err);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
if (connection) await connection.close();
|
|
25
|
+
};
|
|
26
|
+
})();
|