🎮 Added a rabbitMQ connection string URL
This commit is contained in:
@@ -1 +1 @@
|
|||||||
RABBITMQHOST=rabbitmq
|
RABBITMQ_URI=amqp://user:bitnami@rabbitmq:5672
|
||||||
@@ -18,10 +18,8 @@ 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 rabbitMQCredentials =
|
const rabbitMQConnectionString = rabbitMQDockerConnectionString || "localhost";
|
||||||
`${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"));
|
||||||
@@ -48,40 +46,34 @@ io.on("connection", (socket) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
amqp.connect(
|
amqp.connect(`amqp://${rabbitMQConnectionString}`, (error0, connection) => {
|
||||||
`amqp://${rabbitMQCredentials}@${rabbitMQHost}`,
|
if (error0) {
|
||||||
(error0, connection) => {
|
throw error0;
|
||||||
if (error0) {
|
}
|
||||||
throw error0;
|
connection.createChannel((error1, channel) => {
|
||||||
|
if (error1) {
|
||||||
|
throw error1;
|
||||||
}
|
}
|
||||||
connection.createChannel((error1, channel) => {
|
const queue = "comicBookCovers";
|
||||||
if (error1) {
|
channel.assertQueue(queue, {
|
||||||
throw error1;
|
durable: false,
|
||||||
}
|
|
||||||
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