🐰 RabbitMQ for import job first draft
This commit is contained in:
35
queue/consumer.ts
Normal file
35
queue/consumer.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
const amqp = require("amqplib/callback_api");
|
||||
export const connectQueue = (socketConnection) => {
|
||||
amqp.connect("amqp://localhost", (error0, connection) => {
|
||||
if (error0) {
|
||||
throw error0;
|
||||
}
|
||||
connection.createChannel((error1, channel) => {
|
||||
if (error1) {
|
||||
throw error1;
|
||||
}
|
||||
const queue = "comicBookCovers";
|
||||
|
||||
channel.assertQueue(queue, {
|
||||
durable: false,
|
||||
});
|
||||
|
||||
console.log(
|
||||
" [*] Waiting for comic book cover data in %s. To exit press CTRL+C",
|
||||
queue
|
||||
);
|
||||
|
||||
channel.consume(
|
||||
queue,
|
||||
(data) => {
|
||||
console.log("data", data);
|
||||
//Socket Trigger All Clients
|
||||
socketConnection.emit("coverExtracted", JSON.parse(data.content.toString()));
|
||||
},
|
||||
{
|
||||
noAck: true,
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user