Skip to content

Commit a8ae444

Browse files
committed
Merge branch 'development' into feat/users
2 parents af8bb81 + 6e696fd commit a8ae444

File tree

35 files changed

+1730
-262
lines changed

35 files changed

+1730
-262
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ docker-compose down
2828

2929
- User Service: http://localhost:3001
3030
- Question Service: http://localhost:3000
31+
- Matching Service: http://localhost:3002
3132
- Frontend: http://localhost:5173

backend/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
2. Set-up Firebase.
88

9+
3. Follow the instructions [here](https://nodejs.org/en/download/package-manager) to set up Node v20.
10+
911
## Setting-up local MongoDB (only if you are using Docker)
1012

1113
1. In the `backend` directory, create a copy of the `.env.sample` file and name it `.env`.

backend/matching-service/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
# Matching Service
1+
# Matching Service Guide
2+
3+
> Please ensure that you have completed the backend set-up [here](../README.md) before proceeding.
24
35
## Setting-up Matching Service
46

57
1. In the `matching-service` directory, create a copy of the `.env.sample` file and name it `.env`. If you are looking to run matching service with the other services using docker-compose, comment out the variable `RABBITMQ_ADDR` under use case (1) in the .env file. Otherwise, if you are looking to run matching service individually, comment out the variables `RABBITMQ_DEFAULT_USER`, `RABBITMQ_DEFAULT_PASS` and `RABBITMQ_ADDR` under use case (2) in the .env file.
68

7-
2. If you are running matching service together with other services using docker-compose, to set up credentials for RabbitMq, update the RabbitMq variables in the `.env` file. Update `RABBITMQ_DEFAULT_USER` and `RABBITMQ_DEFAULT_PASS` to what you want, then update `RABBITMQ_ADDR` to be `amqp://<RABBITMQ_DEFAULT_USER>:<RABBITMQ_DEFAULT_PASS>@rabbitmq:5672`.
8-
You can access RabbitMq management user interface locally with the username in `RABBITMQ_DEFAULT_USER` and password in `RABBITMQ_DEFAULT_PASS` at http://localhost:15672.
9+
2. If you are running matching service together with other services using docker-compose, to set up credentials for RabbitMq, update the RabbitMq variables in the `.env` file. Update `RABBITMQ_DEFAULT_USER` and `RABBITMQ_DEFAULT_PASS` to what you want, then update `RABBITMQ_ADDR` to be `amqp://<RABBITMQ_DEFAULT_USER>:<RABBITMQ_DEFAULT_PASS>@rabbitmq:5672`. You can access RabbitMq management user interface locally with the username in `RABBITMQ_DEFAULT_USER` and password in `RABBITMQ_DEFAULT_PASS` at http://localhost:15672.
910

1011
3. If you are running matching service individually, you do not need to make any changes to `RABBITMQ_ADDR`. You can access RabbitMq management user interface locally with the username `guest` and password `guest` at http://localhost:15672.
1112

1213
## Running Matching Service Individually with Docker
1314

1415
1. Set up and run RabbitMq locally on your computer with the command `docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:4.0-management`.
1516

16-
2. Follow the instructions [here](https://nodejs.org/en/download/package-manager) to set up Node v20.
17-
18-
3. Open Command Line/Terminal and navigate into the `matching-service` directory.
17+
2. Open Command Line/Terminal and navigate into the `matching-service` directory.
1918

20-
4. Run the command: `npm install`. This will install all the necessary dependencies.
19+
3. Run the command: `npm install`. This will install all the necessary dependencies.
2120

22-
5. Run the command `npm start` to start the Matching Service in production mode, or use `npm run dev` for development mode, which includes features like automatic server restart when you make code changes.
21+
4. Run the command `npm start` to start the Matching Service in production mode, or use `npm run dev` for development mode, which includes features like automatic server restart when you make code changes. If you encounter connection errors, please wait for a few minutes before running `npm start` again as RabbitMq may take some time to start up.
2322

2423
## After running
2524

backend/matching-service/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import matchingRoutes from "./src/routes/matchingRoutes.ts";
99

1010
dotenv.config();
1111

12-
const allowedOrigins = process.env.ORIGINS
12+
export const allowedOrigins = process.env.ORIGINS
1313
? process.env.ORIGINS.split(",")
1414
: ["http://localhost:5173", "http://127.0.0.1:5173"];
1515

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import amqplib, { Connection } from "amqplib";
22
import dotenv from "dotenv";
3-
import { matchUsers } from "../utils/mq_utils";
3+
import { matchUsers } from "../src/utils/mq_utils";
4+
import { MatchRequestItem } from "../src/handlers/matchHandler";
45

56
dotenv.config();
67

@@ -13,13 +14,9 @@ export const connectRabbitMq = async () => {
1314
const consumerChannel = await mrConnection.createChannel();
1415
await consumerChannel.assertQueue(queue);
1516

16-
consumerChannel.consume(queue, async (msg) => {
17+
consumerChannel.consume(queue, (msg) => {
1718
if (msg !== null) {
18-
try {
19-
await matchUsers(msg.content.toString());
20-
} catch (error) {
21-
console.error(error);
22-
}
19+
matchUsers(msg.content.toString());
2320
consumerChannel.ack(msg);
2421
}
2522
});
@@ -29,20 +26,15 @@ export const connectRabbitMq = async () => {
2926
}
3027
};
3128

32-
type MatchRequestMessage = {
33-
userId: string;
34-
categories: string[] | string;
35-
complexities: string[] | string;
36-
sentTimestamp: number;
37-
ttlInSecs: number;
38-
};
39-
40-
export const sendRabbitMq = async (data: MatchRequestMessage) => {
29+
export const sendRabbitMq = async (
30+
data: MatchRequestItem
31+
): Promise<boolean> => {
4132
try {
4233
const senderChannel = await mrConnection.createChannel();
4334
senderChannel.sendToQueue(queue, Buffer.from(JSON.stringify(data)));
35+
return true;
4436
} catch (error) {
4537
console.log(error);
46-
throw new Error("Failed to send match request");
38+
return false;
4739
}
4840
};

0 commit comments

Comments
 (0)