Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
585 changes: 579 additions & 6 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion app/koi-server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
- 8080:8080
environment:
- DYNAMIC_CONFIG_ENABLED=true
- KAFKA_CLUSTERS_0_NAME=koi_kafka
- KAFKA_CLUSTERS_0_NAME=stock-service

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdc-stock 으로 변경해도 괜찮을까요?

- KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=kafka:9092

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 카프카 서버 9092와 9094 서버의 차이가 무엇인가요? 각자 역할이 뭔지 궁금해요


mongo:
Expand Down
11 changes: 11 additions & 0 deletions app/koi-server/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: '../coverage',
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'src',
testEnvironment: 'node',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
};
11 changes: 7 additions & 4 deletions app/koi-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test": "jest --config jest.config.js",
"test:watch": "jest --config jest.config.js --watch",
"test:cov": "jest --config jest.config.js --coverage",
"test:e2e": "jest --config ./test/jest-e2e.json",
"turbo:dev": "turbo run dev",
"turbo:build": "turbo run build"
},
"dependencies": {
"@codegenie/serverless-express": "^4.13.0",
"@confluentinc/kafka-javascript": "^1.2.0",
"@nestjs/common": "^10.3.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.3.0",
"@nestjs/microservices": "^11.0.7",
"@nestjs/mongoose": "^10.0.2",
"@nestjs/platform-express": "^10.3.0",
"@nestjs/schedule": "^5.0.1",
"@toss/date": "^1.1.7",
"@toss/utils": "^1.4.4",
"aws-lambda": "^1.0.7",
Expand All @@ -34,6 +36,7 @@
"express": "^4.18.2",
"feature-nest-poll": "workspace:*",
"feature-nest-stock": "workspace:*",
"kafkajs": "^2.2.4",
"mongoose": "^8.1.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0"
Expand Down
10 changes: 9 additions & 1 deletion app/koi-server/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Controller, Post, Query } from '@nestjs/common';
import { Controller, Get, Post, Query } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Post('log')
log(@Query('msg') msg: string): boolean {
fetch(
Expand All @@ -19,4 +22,9 @@ export class AppController {
console.warn(`${decodeURIComponent(msg)} (${new Date()})`);
return true;
}

@Get()
getHello(): string {
return this.appService.getHello();
}
}
18 changes: 18 additions & 0 deletions app/koi-server/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { PollModule } from 'feature-nest-poll';
import { StockModule } from 'feature-nest-stock';
import { ScheduleModule } from '@nestjs/schedule';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PartyModule } from './party/party.module';
import { KafkaModule } from '../../../../package/feature/feature-nest-stock/src/kafka/kafka.module';
import kafkaConfig from '../config/kafka.config';

@Module({
controllers: [AppController],
imports: [
ScheduleModule.forRoot(),
ConfigModule.forRoot({
isGlobal: true,
load: [kafkaConfig],
}),
MongooseModule.forRoot(process.env.MONGO_URI, {
ignoreUndefined: true,
maxIdleTimeMS: 60000,
}),
PollModule,
StockModule,
PartyModule,
KafkaModule.forRootAsync({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feature-nest-stock 에서 KafkaModule.forFeature 쓸 수 있을까요?

imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
brokers: configService.get<string[]>('kafka.brokers') || [],
clientId: configService.get<string>('kafka.clientId') || '',
groupId: configService.get<string>('kafka.groupId') || '',
}),
}),
],
providers: [AppService],
})
Expand Down
4 changes: 3 additions & 1 deletion app/koi-server/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
constructor() {}
getHello(): string {
return 'Hello World!';
}
}
7 changes: 7 additions & 0 deletions app/koi-server/src/config/kafka.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default (): Record<string, unknown> => ({
kafka: {
brokers: process.env.KAFKA_BROKERS?.split(',') || ['localhost:9094'],
clientId: process.env.KAFKA_CLIENT_ID || 'stock-service',
groupId: process.env.KAFKA_GROUP_ID || 'stock_service_group',
},
});
4 changes: 2 additions & 2 deletions app/koi-server/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from '../src/app.module';
import request from 'supertest';
import { AppModule } from '../src/app/app.module';

describe('AppController (e2e)', () => {
let app: INestApplication;
Expand Down
11 changes: 11 additions & 0 deletions package/feature/feature-nest-stock/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: '.',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: './coverage',
testEnvironment: 'node',
};
14 changes: 12 additions & 2 deletions package/feature/feature-nest-stock/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
{
"name": "feature-nest-stock",
"main": "./dist/index.js",
"main": "./dist/src/index.js",
"sideEffects": false,
"scripts": {
"build": "tsc",
"build:watch": "tsc -w"
"build:watch": "tsc -w",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:integration": "jest --testPathPattern=test/integration",
"test:outbox": "jest --testPathPattern=test/unit/outbox"
},
"dependencies": {
"@nestjs/common": "^10.3.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.3.0",
"@nestjs/mongoose": "^10.0.2",
"@nestjs/platform-express": "^10.3.0",
"@nestjs/schedule": "^5.0.1",
"@toss/date": "^1.1.7",
"@toss/utils": "^1.4.4",
"class-transformer": "^0.5.1",
"cross-env": "^7.0.3",
"dayjs": "^1.11.10",
"kafkajs": "^2.2.4",
"lodash": "^4.17.21",
"mongoose": "^8.1.0",
"openai": "^4.85.1",
Expand Down Expand Up @@ -48,6 +57,7 @@
"eslint-plugin-unused-imports": "^2.0.0",
"jest": "29.5.0",
"mongodb": "6.3.0",
"mongodb-memory-server": "^10.1.4",
"prettier": "^2.6.1",
"shared~type-stock": "workspace:*",
"source-map-support": "^0.5.20",
Expand Down
56 changes: 56 additions & 0 deletions package/feature/feature-nest-stock/src/kafka/kafka.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Module, DynamicModule, Type, ForwardReference, Abstract } from '@nestjs/common';
import { KafkaService } from './kafka.service';

export interface KafkaModuleOptions {
brokers: string[];
clientId: string;
groupId: string;
}

type ModuleType = Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference<unknown>;

export interface KafkaModuleAsyncOptions {
imports?: ModuleType[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
useFactory: (...args: any[]) => Promise<KafkaModuleOptions> | KafkaModuleOptions;
// eslint-disable-next-line @typescript-eslint/ban-types
inject?: Array<Type<unknown> | string | symbol | Abstract<unknown> | Function>;
}

@Module({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KafkaModule을 package/library/lib-nest-kafka 로 옮길 수 있을까요?

exports: [KafkaService],
providers: [KafkaService],
})
export class KafkaModule {
static forRoot(options: KafkaModuleOptions): DynamicModule {
return {
exports: [KafkaService],
global: true,
module: KafkaModule,
providers: [
{
provide: 'KAFKA_OPTIONS',
useValue: options,
},
KafkaService,
],
};
}

static forRootAsync(options: KafkaModuleAsyncOptions): DynamicModule {
return {
exports: [KafkaService],
global: true,
imports: options.imports || [],
module: KafkaModule,
providers: [
{
inject: options.inject || [],
provide: 'KAFKA_OPTIONS',
useFactory: options.useFactory,
},
KafkaService,
],
};
}
}
Loading