mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 11:45:02 +01:00
consume prototype
This commit is contained in:
parent
beb2187cd6
commit
93ce632b5d
21 changed files with 328 additions and 108 deletions
23
test-js/src/consume-message.js
Normal file
23
test-js/src/consume-message.js
Normal 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;
|
||||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue