-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f7769e
commit b16194c
Showing
20 changed files
with
161 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
APP_PORT=3001 | ||
|
||
RMQ_URI=amqp://localhost:5672 | ||
RMQ_BILLING_QUEUE=billing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { Controller, Get, } from '@nestjs/common'; | ||
import { BillingService } from './billing.service'; | ||
import { EventPattern, Payload, RmqContext, Ctx } from '@nestjs/microservices' | ||
import { MessagePattern, Payload, RmqContext, Ctx } from '@nestjs/microservices' | ||
import { RmqService } from '@app/common' | ||
import { RMQ_EVENTS } from '../constants/rmq.constants'; | ||
import { Observable, from } from 'rxjs'; | ||
@Controller() | ||
export class BillingController { | ||
constructor( | ||
private readonly billingService: BillingService, | ||
private readonly rmqService: RmqService | ||
) { } | ||
|
||
@Get() | ||
@Get('u') | ||
getHello(): string { | ||
return this.billingService.getHello(); | ||
} | ||
@EventPattern('order_created') | ||
order(@Payload() data: any, @Ctx() context: RmqContext) { | ||
@MessagePattern('GET_USER_BY_ID') | ||
order(@Payload() data: number[], @Ctx() context: RmqContext): Observable<number> { | ||
this.billingService.order(data); | ||
this.rmqService.ack(context) | ||
// this.rmqService.ack(context) | ||
return from(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const RMQ_SERVICE = { | ||
USERS: 'USERS' | ||
} | ||
export enum RMQ_EVENTS { | ||
NEW_USER_CREATED, | ||
GET_USER_BY_ID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
apps/gateway/src/infrastructure/controllers/user.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { Controller, Get, Param } from '@nestjs/common'; | ||
import { UserService } from '../services/user.service'; | ||
|
||
@Controller('users') | ||
export class UserController { | ||
constructor(private readonly userService: UserService) { } | ||
|
||
@Get(':id') | ||
getUserById(): string { | ||
return this.userService.getHello(); | ||
getUserById(@Param('id') id: string) { | ||
return this.userService.getUserById(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { DynamicModule, Module } from "@nestjs/common"; | ||
import { ConfigModule } from "@nestjs/config"; | ||
import { MongooseModule, MongooseModuleOptions } from "@nestjs/mongoose"; | ||
|
||
@Module({}) | ||
export class myConfigModule { | ||
static register(envPath: string): DynamicModule { | ||
return { | ||
module: myConfigModule, | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
envFilePath: envPath | ||
}), | ||
|
||
], | ||
providers: [ | ||
{ | ||
provide: 'MY_CONFIG', | ||
useFactory(mongoose: MongooseModuleOptions) { | ||
|
||
}, | ||
inject: [MongooseModule] | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ConfigurableModuleBuilder } from '@nestjs/common'; | ||
import { ConfigModuleOptions } from './configModuleOption.interface'; | ||
import { RmqOptions } from '@nestjs/microservices'; | ||
|
||
export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } = | ||
new ConfigurableModuleBuilder<RmqOptions>().build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Transport } from "@nestjs/microservices" | ||
|
||
export interface ConfigModuleOptions { | ||
transport: any | ||
options: { | ||
urls: string[] | ||
queue: string | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters