fix(reporting-service): 启动 Kafka 微服务消费者以记录真实活动
- 在 main.ts 添加 Kafka 微服务连接配置 - 调用 startAllMicroservices() 启动事件消费 - 支持消费 identity/authorization/planting 服务的事件 - 实现仪表板"最近活动"显示真实数据 🤖 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
e153e2144d
commit
dbba229c91
|
|
@ -260,7 +260,8 @@
|
|||
"Bash(git commit -m \"$(cat <<''EOF''\nfeat(admin-web): 实现 Dashboard 页面真实 API 接入\n\n## 概述\n将 admin-web Dashboard 页面从模拟数据改为真实 API 调用,\n使用 React Query 实现数据获取、缓存和自动刷新。\n\n## 新增文件\n- dashboardService.ts: Dashboard API 服务封装\n- useDashboard.ts: React Query hooks\n- dashboard.types.ts: Dashboard 类型定义\n\n## API 接入\n- /dashboard/stats: 统计卡片(总认种量、总用户数、省/市公司数)\n- /dashboard/charts: 趋势图表(支持 7d/30d/90d 周期切换)\n- /dashboard/region: 区域分布\n- /dashboard/activities: 最近活动\n\n## UI 优化\n- 添加加载骨架屏\n- 添加错误重试机制\n- 添加空数据提示\n- 优化图表周期切换交互\n\n🤖 Generated with [Claude Code](https://claude.com/claude-code)\n\nCo-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>\nEOF\n)\")",
|
||||
"Bash(npx next:*)",
|
||||
"Bash(npx prisma validate:*)",
|
||||
"Bash(dir /s /b \"c:\\Users\\dong\\Desktop\\rwadurian\\backend\\services\\admin-service\\Dockerfile*\")"
|
||||
"Bash(dir /s /b \"c:\\Users\\dong\\Desktop\\rwadurian\\backend\\services\\admin-service\\Dockerfile*\")",
|
||||
"Bash(dir /b \"c:\\Users\\dong\\Desktop\\rwadurian\\frontend\")"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { NestFactory } from '@nestjs/core';
|
||||
import { ValidationPipe, Logger } from '@nestjs/common';
|
||||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
|
|
@ -8,6 +9,26 @@ async function bootstrap() {
|
|||
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
// 连接 Kafka 微服务消费者
|
||||
const kafkaBrokers = (process.env.KAFKA_BROKERS || 'localhost:9092').split(',');
|
||||
app.connectMicroservice<MicroserviceOptions>({
|
||||
transport: Transport.KAFKA,
|
||||
options: {
|
||||
client: {
|
||||
clientId: process.env.KAFKA_CLIENT_ID || 'reporting-service',
|
||||
brokers: kafkaBrokers,
|
||||
},
|
||||
consumer: {
|
||||
groupId: process.env.KAFKA_GROUP_ID || 'reporting-service-group',
|
||||
},
|
||||
subscribe: {
|
||||
fromBeginning: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
logger.log(`📡 Kafka consumer connecting to: ${kafkaBrokers.join(', ')}`);
|
||||
|
||||
// Global prefix
|
||||
app.setGlobalPrefix('api/v1');
|
||||
|
||||
|
|
@ -44,6 +65,11 @@ async function bootstrap() {
|
|||
SwaggerModule.setup('api/docs', app, document);
|
||||
|
||||
const port = process.env.PORT || 3008;
|
||||
|
||||
// 启动所有微服务(包括 Kafka 消费者)
|
||||
await app.startAllMicroservices();
|
||||
logger.log('📡 Kafka microservice started - listening for events');
|
||||
|
||||
await app.listen(port);
|
||||
|
||||
logger.log(`🚀 Reporting Service is running on: http://localhost:${port}`);
|
||||
|
|
|
|||
Loading…
Reference in New Issue