consume prototype

This commit is contained in:
nora 2022-03-01 21:52:00 +01:00
parent beb2187cd6
commit 93ce632b5d
21 changed files with 328 additions and 108 deletions

View file

@ -0,0 +1,23 @@
import { connectAmqp } from './utils/utils.js';
const connection = await connectAmqp();
const channel = await connection.createChannel();
await channel.assertQueue('consume-queue-1415');
const consumePromise = new Promise((resolve) => {
channel
.consume('consume-queue-1415', (msg) => {
if (msg.content.toString() === 'STOP') {
resolve();
}
})
.then((response) =>
console.log(`Registered consumer, consumerTag: "${response.consumerTag}"`)
);
});
await channel.sendToQueue('consume-queue-1415', Buffer.from('STOP'));
console.log('Sent STOP message to queue');
await consumePromise;

View file

@ -6,7 +6,7 @@ const connection = await connectAmqp();
const channel = await connection.createChannel();
const reply = await channel.assertQueue(queueName, { durable: false });
const reply = await channel.assertQueue(queueName);
assert(reply.messageCount === 0, 'Message found in queue');
assert(reply.consumerCount === 0, 'Consumer listening on queue');

View file

@ -1,7 +1,6 @@
import { connectAmqp } from './utils/utils.js';
const connection = await connectAmqp();
const channel = await connection.createChannel();
channel.publish('exchange-1', 'queue-1', Buffer.from('hello'));