Skip to content

Commit cbe2f29

Browse files
committedDec 10, 2022
Add direct reply to example
1 parent 169e157 commit cbe2f29

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
 

‎examples/direct_reply_to_client.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env node
2+
3+
const amqp = require('../');
4+
5+
const queue = 'rpc_queue';
6+
7+
(async () => {
8+
const connection = await amqp.connect();
9+
const channel = await connection.createChannel();
10+
11+
await channel.consume('amq.rabbitmq.reply-to', async (message) => {
12+
console.log(message.content.toString());
13+
await channel.close();
14+
await connection.close();
15+
}, { noAck: true });
16+
17+
await channel.assertQueue(queue, { durable: false });
18+
19+
channel.sendToQueue(queue, Buffer.from(' [X] ping'), {
20+
replyTo: 'amq.rabbitmq.reply-to',
21+
});
22+
})();

‎examples/direct_reply_to_server.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
3+
const amqp = require('../');
4+
const { v4: uuid } = require('uuid');
5+
6+
const queue = 'rpc_queue';
7+
8+
(async () => {
9+
const connection = await amqp.connect();
10+
const channel = await connection.createChannel();
11+
12+
process.once('SIGINT', async () => {
13+
await channel.close();
14+
await connection.close();
15+
});
16+
17+
await channel.assertQueue(queue, { durable: false });
18+
await channel.consume(queue, (message) => {
19+
console.log(message.content.toString());
20+
channel.sendToQueue(message.properties.replyTo, Buffer.from(' [.] pong'));
21+
}, { noAck: true });
22+
23+
console.log(' [x] To exit press CTRL+C.');
24+
25+
})();

0 commit comments

Comments
 (0)
Please sign in to comment.