🔌 Socket + RabbitMQ setup for download-client touched folders/files
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import express, { Request, Response, Router, Express } from "express";
|
||||
import bodyParser from "body-parser";
|
||||
import { createServer } from "http";
|
||||
import { Server, Socket } from "socket.io";
|
||||
import { Server } from "socket.io";
|
||||
import router from "./route";
|
||||
const amqp = require("amqplib/callback_api");
|
||||
|
||||
// call express
|
||||
const app: Express = express(); // define our app using express
|
||||
@@ -42,6 +43,35 @@ io.on("connection", (socket) => {
|
||||
});
|
||||
});
|
||||
|
||||
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(`Connected to ${queue} queue.`);
|
||||
console.log(`Waiting for comic book cover data in ${queue}`);
|
||||
|
||||
channel.consume(
|
||||
queue,
|
||||
(data) => {
|
||||
//Socket Trigger All Clients
|
||||
io.sockets.emit("coverExtracted", JSON.parse(data.content.toString()));
|
||||
},
|
||||
{
|
||||
noAck: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// socket server
|
||||
httpServer.listen(8051);
|
||||
console.log(`Socket server is listening on 8051`);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import router from "../router";
|
||||
import { Request, Response } from "express";
|
||||
const amqp = require("amqplib/callback_api");
|
||||
import axios from "axios";
|
||||
import { io } from "../../index";
|
||||
|
||||
router.route("/getComicCovers").post(async (req: Request, res: Response) => {
|
||||
typeof req.body === "object" ? req.body : {};
|
||||
@@ -14,41 +12,7 @@ router.route("/getComicCovers").post(async (req: Request, res: Response) => {
|
||||
walkedFolders: req.body.walkedFolders,
|
||||
},
|
||||
});
|
||||
const queueConsumer = 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(`Connected to ${queue} queue.`);
|
||||
console.log(`Waiting for comic book cover data in ${queue}`);
|
||||
|
||||
channel.consume(
|
||||
queue,
|
||||
(data) => {
|
||||
//Socket Trigger All Clients
|
||||
io.sockets.emit(
|
||||
"coverExtracted",
|
||||
JSON.parse(data.content.toString()),
|
||||
);
|
||||
},
|
||||
{
|
||||
noAck: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
res.send({ queue: queueConsumer });
|
||||
res.send({ po: "jo" });
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user