🔑 Added credentials for rabbitMQ connection
This commit is contained in:
@@ -19,6 +19,9 @@ app.use(bodyParser.urlencoded({ extended: true }));
|
|||||||
const port: number = Number(process.env.PORT) || 8050; // set our port
|
const port: number = Number(process.env.PORT) || 8050; // set our port
|
||||||
// set rabbitMQ host
|
// set rabbitMQ host
|
||||||
const rabbitMQHost = process.env.RABBITMQHOST || "localhost";
|
const rabbitMQHost = process.env.RABBITMQHOST || "localhost";
|
||||||
|
const rabbitMQCredentials =
|
||||||
|
`${process.env.RABBITMQ_USERNAME}:${process.env.RABBITMQ_PASSWORD}` ||
|
||||||
|
`guest:guest`;
|
||||||
|
|
||||||
// Send index.html on root request
|
// Send index.html on root request
|
||||||
app.use(express.static("dist"));
|
app.use(express.static("dist"));
|
||||||
@@ -45,34 +48,40 @@ io.on("connection", (socket) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
amqp.connect(`amqp://${rabbitMQHost}`, (error0, connection) => {
|
amqp.connect(
|
||||||
if (error0) {
|
`amqp://${rabbitMQCredentials}@${rabbitMQHost}`,
|
||||||
throw error0;
|
(error0, connection) => {
|
||||||
}
|
if (error0) {
|
||||||
connection.createChannel((error1, channel) => {
|
throw error0;
|
||||||
if (error1) {
|
|
||||||
throw error1;
|
|
||||||
}
|
}
|
||||||
const queue = "comicBookCovers";
|
connection.createChannel((error1, channel) => {
|
||||||
channel.assertQueue(queue, {
|
if (error1) {
|
||||||
durable: false,
|
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(`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,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// socket server
|
// socket server
|
||||||
httpServer.listen(8051);
|
httpServer.listen(8051);
|
||||||
|
|||||||
Reference in New Issue
Block a user