fix(authorization): add Kafka microservice for @EventPattern to work
authorization-service uses @EventPattern('planting-events') to consume
planting events but was missing connectMicroservice() configuration.
Without this, the service could not receive planting events, causing:
- Province team benefits (20 USDT) not distributed
- City team benefits (40 USDT) not distributed
- Community benefits (80 USDT) not distributed
- Monthly assessment data not updated
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f36fc0e8b7
commit
adc063eb7a
|
|
@ -1,6 +1,7 @@
|
||||||
import { NestFactory } from '@nestjs/core'
|
import { NestFactory } from '@nestjs/core'
|
||||||
import { ValidationPipe, Logger } from '@nestjs/common'
|
import { ValidationPipe, Logger } from '@nestjs/common'
|
||||||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'
|
||||||
|
import { MicroserviceOptions, Transport } from '@nestjs/microservices'
|
||||||
import { AppModule } from './app.module'
|
import { AppModule } from './app.module'
|
||||||
import { GlobalExceptionFilter } from '@/shared/filters'
|
import { GlobalExceptionFilter } from '@/shared/filters'
|
||||||
import { TransformInterceptor } from '@/shared/interceptors'
|
import { TransformInterceptor } from '@/shared/interceptors'
|
||||||
|
|
@ -47,6 +48,26 @@ async function bootstrap() {
|
||||||
const document = SwaggerModule.createDocument(app, config)
|
const document = SwaggerModule.createDocument(app, config)
|
||||||
SwaggerModule.setup('api/docs', app, document)
|
SwaggerModule.setup('api/docs', app, document)
|
||||||
|
|
||||||
|
// Kafka 微服务 - 用于 @EventPattern 消费认种事件
|
||||||
|
const kafkaBrokers = process.env.KAFKA_BROKERS?.split(',') || ['localhost:9092']
|
||||||
|
const kafkaGroupId = process.env.KAFKA_GROUP_ID || 'authorization-service-group'
|
||||||
|
|
||||||
|
app.connectMicroservice<MicroserviceOptions>({
|
||||||
|
transport: Transport.KAFKA,
|
||||||
|
options: {
|
||||||
|
client: {
|
||||||
|
clientId: 'authorization-service',
|
||||||
|
brokers: kafkaBrokers,
|
||||||
|
},
|
||||||
|
consumer: {
|
||||||
|
groupId: kafkaGroupId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await app.startAllMicroservices()
|
||||||
|
logger.log('Kafka microservice started for planting event consumption')
|
||||||
|
|
||||||
const port = parseInt(process.env.APP_PORT || '3009', 10)
|
const port = parseInt(process.env.APP_PORT || '3009', 10)
|
||||||
await app.listen(port)
|
await app.listen(port)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue