Untitled
unknown
plain_text
a year ago
955 B
10
Indexable
const amqp = require('amqplib/callback_api');
const QUEUE_A = 'QueueA';
const QUEUE_B = 'QueueB';
const PREFETCH_COUNT = 3;
amqp.connect('amqp://localhost', (error0, connection) => {
if (error0) {
throw error0;
}
connection.createChannel((error1, channel) => {
if (error1) {
throw error1;
}
channel.assertQueue(QUEUE_A, {
durable: true
});
channel.assertQueue(QUEUE_B, {
durable: true
});
channel.prefetch(PREFETCH_COUNT);
const consumeMessage = (queue) => {
return (msg) => {
if (msg !== null) {
console.log(`Received ${msg.content.toString()} from ${queue}`);
setTimeout(() => {
channel.ack(msg);
}, 1000 * (1+Math.random()));
}
};
};
channel.consume(QUEUE_A, consumeMessage(QUEUE_A), {
noAck: false
});
channel.consume(QUEUE_B, consumeMessage(QUEUE_B), {
noAck: false
});
});
});
Editor is loading...
Leave a Comment