Skip to content

Commit 681b5b1

Browse files
authored
Merge pull request #16 from Prajualit/main
localizing redis and kafka
2 parents cd1943a + 66d5117 commit 681b5b1

12 files changed

Lines changed: 437 additions & 533 deletions

File tree

backend/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
"license": "ISC",
1414
"dependencies": {
1515
"bcryptjs": "^2.4.3",
16+
"colors": "^1.4.0",
1617
"cors": "^2.8.5",
1718
"dotenv": "^16.4.5",
1819
"express": "^4.19.2",
20+
"express-async-handler": "^1.2.0",
1921
"firebase": "^11.1.0",
2022
"firebase-admin": "^13.0.2",
2123
"ioredis": "^5.4.2",
2224
"jsonwebtoken": "^9.0.2",
2325
"kafkajs": "^2.2.4",
2426
"mongoose": "^8.4.1",
2527
"socket.io": "^4.7.5",
26-
"express-async-handler": "^1.2.0",
27-
"tls": "^0.0.1",
28-
"colors": "^1.4.0"
28+
"tls": "^0.0.1"
2929
},
3030
"devDependencies": {
3131
"nodemon": "^3.0.1"

backend/server.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
const express = require("express");
22
const dotenv = require("dotenv");
33
const path = require("path");
4-
const Connection = require("./config/db");
5-
const cors = require("cors");
6-
const NotificationService = require("./services/notificationService");
7-
8-
// Add process error handlers
9-
process.on('uncaughtException', (error) => {
10-
console.error('❌ Uncaught Exception:', error);
11-
});
12-
13-
process.on('unhandledRejection', (error) => {
14-
console.error('❌ Unhandled Rejection:', error);
15-
});
164

175
// Load environment variables with multiple path attempts
186
const envPaths = [
@@ -36,6 +24,19 @@ if (!envLoaded) {
3624
console.log('Searched paths:', envPaths);
3725
}
3826

27+
const Connection = require("./config/db");
28+
const cors = require("cors");
29+
const NotificationService = require("./services/notificationService");
30+
31+
// Add process error handlers
32+
process.on('uncaughtException', (error) => {
33+
console.error('❌ Uncaught Exception:', error);
34+
});
35+
36+
process.on('unhandledRejection', (error) => {
37+
console.error('❌ Unhandled Rejection:', error);
38+
});
39+
3940
// Verify environment variables are loaded
4041
console.log('Environment Variables Status:');
4142
console.log('DB_USERNAME exists:', !!process.env.DB_USERNAME);

backend/services/notificationService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ console.log("debugging");
1414

1515
// Redis Configuration
1616
const redisConfig = {
17-
host: process.env.REDIS_HOST || 'ec2-3-6-113-80.ap-south-1.compute.amazonaws.com',
17+
host: process.env.REDIS_HOST || '127.0.0.1',
1818
port: parseInt(process.env.REDIS_PORT) || 6379,
1919
maxRetriesPerRequest: 3,
2020
retryStrategy(times) {
@@ -65,7 +65,7 @@ async function testRedisConnection() {
6565
// Kafka Configuration
6666
const kafkaConfig = {
6767
clientId: process.env.KAFKA_CLIENT_ID || 'notification-service',
68-
brokers: [process.env.KAFKA_BROKER || 'ec2-3-6-113-80.ap-south-1.compute.amazonaws.com:9092'],
68+
brokers: [process.env.KAFKA_BROKER || 'localhost:9092'],
6969
connectionTimeout: 30000,
7070
retry: {
7171
initialRetryTime: 100,

docker-compose.yml

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
1-
version: '3.8'
2-
31
services:
2+
zookeeper:
3+
image: confluentinc/cp-zookeeper:7.4.1
4+
environment:
5+
ZOOKEEPER_CLIENT_PORT: 2181
6+
ZOOKEEPER_TICK_TIME: 2000
7+
ports:
8+
- "2181:2181"
9+
networks:
10+
- app_network
11+
12+
kafka:
13+
image: confluentinc/cp-kafka:7.4.1
14+
depends_on:
15+
- zookeeper
16+
environment:
17+
KAFKA_BROKER_ID: 1
18+
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
19+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
20+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
21+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
22+
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
23+
ports:
24+
- "9092:9092"
25+
- "29092:29092"
26+
networks:
27+
- app_network
28+
29+
redis:
30+
image: redis:7
31+
command: ["redis-server", "--appendonly", "no"]
32+
ports:
33+
- "6379:6379"
34+
healthcheck:
35+
test: ["CMD", "redis-cli", "ping"]
36+
interval: 10s
37+
timeout: 5s
38+
retries: 5
39+
networks:
40+
- app_network
41+
442
backend:
543
build:
644
context: .
@@ -11,18 +49,19 @@ services:
1149
- app_network
1250
environment:
1351
- NODE_ENV=development
14-
- KAFKA_BROKER=ec2-3-6-113-80.ap-south-1.compute.amazonaws.com:9092
52+
- KAFKA_BROKER=kafka:9092
1553
- KAFKA_CLIENT_ID=notification-service
1654
- KAFKA_GROUP_ID=notification-group
17-
- REDIS_HOST=ec2-3-6-113-80.ap-south-1.compute.amazonaws.com
55+
- REDIS_HOST=redis
1856
- REDIS_PORT=6379
1957
- MONGODB_URI=mongodb+srv://akshanshkaushal9:GRS7yWeIDcF8SEMQ@cluster0.t7rpzk9.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
2058
volumes:
2159
- ./backend:/app/backend
2260
- /app/backend/node_modules
2361
- ./.env:/app/backend/.env
24-
extra_hosts:
25-
- "ec2-3-6-113-80.ap-south-1.compute.amazonaws.com:3.6.113.80"
62+
depends_on:
63+
- kafka
64+
- redis
2665

2766
frontend:
2867
build:
@@ -35,8 +74,8 @@ services:
3574
networks:
3675
- app_network
3776
environment:
38-
- REACT_APP_API_URL=http://backend:5000
39-
- REACT_APP_SOCKET_URL=http://backend:5000
77+
- REACT_APP_API_URL=http://localhost:5000
78+
- REACT_APP_SOCKET_URL=http://localhost:5000
4079

4180
networks:
4281
app_network:

0 commit comments

Comments
 (0)