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
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const amqp = require('amqplib');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var q = 'hello';
|
|
8
|
-
var msg = 'Hello World!';
|
|
5
|
+
const queue = 'hello';
|
|
6
|
+
const text = 'Hello World!';
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
(async () => {
|
|
9
|
+
let connection;
|
|
10
|
+
try {
|
|
11
|
+
connection = await amqp.connect('amqp://localhost');
|
|
12
|
+
const channel = await connection.createChannel();
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
14
|
+
await channel.assertQueue(queue, { durable: false });
|
|
15
|
+
|
|
16
|
+
// NB: `sentToQueue` and `publish` both return a boolean
|
|
17
|
+
// indicating whether it's OK to send again straight away, or
|
|
18
|
+
// (when `false`) that you should wait for the event `'drain'`
|
|
19
|
+
// to fire before writing again. We're just doing the one write,
|
|
20
|
+
// so we'll ignore it.
|
|
21
|
+
channel.sendToQueue(queue, Buffer.from(text));
|
|
22
|
+
console.log(" [x] Sent '%s'", text);
|
|
23
|
+
await channel.close();
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.warn(err);
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
if (connection) await connection.close();
|
|
30
|
+
};
|
|
31
|
+
})();
|
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Process tasks from the work queue
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const amqp = require('amqplib');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
console.log(" [*] Waiting for messages. To exit press CTRL+C");
|
|
6
|
+
const queue = 'task_queue';
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
try {
|
|
10
|
+
const connection = await amqp.connect('amqp://localhost');
|
|
11
|
+
process.once('SIGINT', async () => {
|
|
12
|
+
await connection.close();
|
|
14
13
|
});
|
|
15
|
-
return ok;
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const channel = await connection.createChannel();
|
|
16
|
+
await channel.assertQueue(queue, { durable: true });
|
|
17
|
+
|
|
18
|
+
channel.prefetch(1);
|
|
19
|
+
await channel.consume(queue, (message) => {
|
|
20
|
+
const text = message.content.toString();
|
|
21
|
+
console.log(" [x] Received '%s'", text);
|
|
22
|
+
const seconds = text.split('.').length - 1;
|
|
23
|
+
setTimeout(() => {
|
|
23
24
|
console.log(" [x] Done");
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
channel.ack(message);
|
|
26
|
+
}, seconds * 1000);
|
|
27
|
+
}, { noAck: false });
|
|
28
|
+
|
|
29
|
+
console.log(" [*] Waiting for messages. To exit press CTRL+C");
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
console.warn(err);
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
const amqp = require('../');
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
(async () => {
|
|
4
|
+
let connection;
|
|
5
|
+
try {
|
|
6
|
+
connection = await amqp.connect();
|
|
7
|
+
const channel = await connection.createConfirmChannel();
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
else { console.log('Message %d confirmed', i); }
|
|
9
|
-
} : null;
|
|
10
|
-
}
|
|
9
|
+
for (var i=0; i < 20; i++) {
|
|
10
|
+
channel.publish('amq.topic', 'whatever', Buffer.from('blah'));
|
|
11
|
+
};
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
});
|
|
13
|
+
await channel.waitForConfirms();
|
|
14
|
+
console.log('All messages done');
|
|
15
|
+
await channel.close();
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.warn(err);
|
|
18
|
+
} finally {
|
|
19
|
+
if (connection) await connection.close();
|
|
20
|
+
}
|
|
21
|
+
})();
|