Skip to content

Commit 141ad16

Browse files
committed
#5 wishId Generated in bookingProcess instead of ItineraryDispatcher #22 Bookingprocess connected to redis
1 parent 7b70af5 commit 141ad16

9 files changed

+75
-10
lines changed

bookingProcessAPI/package-lock.json

+43-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bookingProcessAPI/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"@nestjs/core": "^7.0.0",
2626
"@nestjs/microservices": "^7.6.7",
2727
"@nestjs/platform-express": "^7.0.0",
28+
"@types/redis": "^2.8.28",
2829
"kafkajs": "^1.15.0",
30+
"redis": "^3.0.2",
2931
"reflect-metadata": "^0.1.13",
3032
"rimraf": "^3.0.2",
3133
"rxjs": "^6.5.4"

bookingProcessAPI/src/app.module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { Module } from '@nestjs/common';
22
import { AppController } from './app.controller';
33
import { AppService } from './app.service';
44
import { OffersModule } from './offers/offers.module';
5+
import { RedisModule } from './redis/redis.module';
56

67
@Module({
7-
imports: [OffersModule],
8+
imports: [OffersModule, RedisModule],
89
controllers: [AppController],
910
providers: [AppService],
1011
})

bookingProcessAPI/src/env_variable.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const PORT = process.env.PORT ? process.env.PORT : 80;
2-
export const KAFKA = process.env.KAFKA ? process.env.KAFKA : "localhost:9092";
2+
export const KAFKA = process.env.KAFKA ? process.env.KAFKA : "localhost:9092";
3+
export const REDIS_HOST = process.env.REDIS ? process.env.REDIS : "localhost:6379";

bookingProcessAPI/src/offers/offers.controller.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export class OffersController {
1414

1515
@Get()
1616
getOffers(@Body() wishes: WishDTO[]): string {
17-
Logger.log(`Searching request`);
17+
Logger.log(`Starting new search request`);
1818
console.dir(wishes);
19-
this.offersService.startSearchingProcess(wishes);
20-
return `Search initiated`;
19+
let startedWish = this.offersService.startSearchingProcess(wishes);
20+
return `Search initiated, wishId generated : ${startedWish}`;
2121
}
2222

2323
@Get('/payment')

bookingProcessAPI/src/offers/offers.module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { OffersController } from './offers.controller';
33
import { OffersService } from './offers.service';
44
import { ClientsModule, Transport } from "@nestjs/microservices";
55
import { KAFKA } from "../env_variable";
6+
import { RedisModule } from 'src/redis/redis.module';
67

78
@Module({
89
imports: [ClientsModule.register([
@@ -19,7 +20,7 @@ import { KAFKA } from "../env_variable";
1920
}
2021
}
2122
},
22-
]),],
23+
]), RedisModule],
2324
controllers: [OffersController],
2425
providers: [OffersService]
2526
})
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { Inject, Injectable } from '@nestjs/common';
22
import { ClientKafka } from "@nestjs/microservices";
3+
import { RedisClient } from 'redis';
34
import { WishDTO } from 'src/models/wish_dto';
45

56
@Injectable()
67
export class OffersService {
7-
constructor(@Inject("BOOKINGPROCESS_SERVICE") private readonly kafkaClient: ClientKafka) { }
8+
constructor(@Inject("BOOKINGPROCESS_SERVICE") private readonly kafkaClient: ClientKafka, @Inject("redis") private readonly redisClient: RedisClient) { }
89

910
startSearchingProcess(wishes: WishDTO[]) {
10-
this.kafkaClient.emit(`wish-requested`, wishes);
11+
let wishRequest = { wishId: `${Date.now()}`, wishes: wishes };
12+
this.kafkaClient.emit(`wish-requested`, wishRequest);
13+
return wishRequest.wishId
1114
}
1215

1316
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Module } from '@nestjs/common';
2+
import * as redis from 'redis';
3+
import { REDIS_HOST } from '../env_variable';
4+
5+
const RedisProvider = {
6+
provide: "redis",
7+
useFactory: () => redis.createClient(`redis://${REDIS_HOST}`)
8+
}
9+
10+
@Module({
11+
exports: ["redis"],
12+
providers: [RedisProvider]
13+
})
14+
export class RedisModule { }

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
- CAR_BOOKING_PORT=80
2222
- CAR_BOOKING_HOST=car-booking
2323
- KAFKA=kafka-service:9092
24+
- REDIS=redis:6379
25+
2426
volumes:
2527
- ./bookingProcessAPI/src/:/app/src/ # FOR HOT RELOAD ONLY
2628
depends_on:

0 commit comments

Comments
 (0)