🔧 Changes to support BullMQ on the service layer

1. Removed socket connection from context
2. Added Redux middleware to persist socket connection
3. Removed amqplib and RabbitMQ support
4. Removed RabbitMQ from docker-compose configuration
5. Removed a proxy route to IMS from the facade
6. Refactored file actions to support the new way of socket event emitting and listening
This commit is contained in:
2021-10-27 07:46:21 -07:00
parent 8fbea27fb2
commit 56d22a28a0
16 changed files with 151 additions and 270 deletions

View File

@@ -1,14 +1,9 @@
import express, { Request, Response, Router, Express } from "express";
import bodyParser from "body-parser";
import { createServer } from "http";
import router from "./route";
import cors from "cors";
const amqp = require("amqplib/callback_api");
// call express
const app: Express = express(); // define our app using express
app.use(cors({ origin: "*" }));
// configure app to use bodyParser for
// Getting data from body of requests
@@ -16,10 +11,6 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const port: number = Number(process.env.PORT) || 8050; // set our port
// set rabbitMQ host
const rabbitMQConnectionString =
process.env.RABBITMQ_URI || "amqp://localhost:5672";
app.get("/", (req: Request, res: Response) => {
console.log("sending index.html");
@@ -37,33 +28,4 @@ app.use(express.static("public"));
app.listen(port);
amqp.connect(`${rabbitMQConnectionString}`, (error0, connection) => {
if (error0) {
throw error0;
}
connection.createChannel((error1, channel) => {
if (error1) {
throw error1;
}
const queue = "comicBookCovers";
channel.assertQueue(queue, {
durable: false,
});
console.log(`RabbitMQ: Connected to ${queue} queue.`);
console.log(`RabbitMQ: 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,
},
);
});
});
console.log(`Server is listening on ${port}`);

View File

@@ -1,4 +1,3 @@
import extra from "./routes/importComics.routes";
import opds from "./routes/opds.routes";
export default { extra, opds };
export default { opds };

View File

@@ -1,45 +0,0 @@
import router from "../router";
import { Request, Response } from "express";
import axios, { AxiosPromise } from "axios";
router.route("/getComicCovers").post(async (req: Request, res: Response) => {
typeof req.body === "object" ? req.body : {};
const importServiceURI = process.env.DOCKER_HOST
? `http://${process.env.DOCKER_HOST}:3000/api/import`
: "http://localhost:3000/api/import";
const axiosArray: AxiosPromise[] = [];
for (let x = 0; x < req.body.walkedFolders.length; x++) {
const newPromise = axios({
method: "POST",
url: `${importServiceURI}/processAndImportToDB`,
data: {
extractionOptions: req.body.extractionOptions,
walkedFolders: req.body.walkedFolders[x],
},
});
axiosArray.push(newPromise);
}
axios
.all(axiosArray)
.then(
axios.spread((...responses) => {
responses.forEach((res) => console.log("Success"));
console.log("submitted all axios calls");
}),
)
.catch((error) => {});
// await axios.request({
// url: `${importServiceURI}/processAndImportToDB`,
// method: "POST",
// data: {
// extractionOptions: req.body.extractionOptions,
// walkedFolders: req.body.walkedFolders,
// },
// });
res.send({ message: "Scan and import initiated." });
});
export default router;