rwadurian/backend/services/wallet-service/src/infrastructure/kafka/kafka.module.ts

64 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Module, Global } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { EventPublisherService } from './event-publisher.service';
import { DepositEventConsumerService } from './deposit-event-consumer.service';
import { PlantingEventConsumerService } from './planting-event-consumer.service';
import { WithdrawalEventConsumerService } from './withdrawal-event-consumer.service';
// [2026-01-07] 新增Outbox Pattern 实现
import { OutboxPublisherService } from './outbox-publisher.service';
import { OutboxRepository } from '../persistence/repositories/outbox.repository';
// [已屏蔽] 前端直接从 reward-service 查询,不再订阅 reward-service 消息
// import { RewardEventConsumerController } from './reward-event-consumer.controller';
// import { EventAckPublisher } from './event-ack.publisher';
import { PrismaService } from '../persistence/prisma/prisma.service';
@Global()
@Module({
imports: [
ClientsModule.registerAsync([
{
name: 'KAFKA_SERVICE',
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
transport: Transport.KAFKA,
options: {
client: {
clientId: configService.get<string>('KAFKA_CLIENT_ID', 'wallet-service'),
brokers: configService.get<string>('KAFKA_BROKERS', 'localhost:9092').split(','),
},
consumer: {
groupId: configService.get<string>('KAFKA_GROUP_ID', 'wallet-service-group'),
},
},
}),
inject: [ConfigService],
},
]),
],
// [已屏蔽] 前端直接从 reward-service 查询,不再订阅 reward-service 消息
// controllers: [RewardEventConsumerController],
controllers: [],
providers: [
PrismaService,
EventPublisherService,
DepositEventConsumerService,
PlantingEventConsumerService,
WithdrawalEventConsumerService,
// [2026-01-07] 新增Outbox Pattern
OutboxRepository,
OutboxPublisherService,
],
exports: [
EventPublisherService,
DepositEventConsumerService,
PlantingEventConsumerService,
WithdrawalEventConsumerService,
ClientsModule,
// [2026-01-07] 新增:导出 Outbox 相关服务
OutboxRepository,
OutboxPublisherService,
],
})
export class KafkaModule {}