rwadurian/backend
hailin 7ee6d633c6 fix(kafka): 修复 MPC Kafka consumer 启动订阅失败后不重试的问题
问题现象:
- blockchain-service 启动时 Kafka consumer subscribe() 抛出
  "This server does not host this topic-partition" 错误
- 原实现只 try-catch 一次就放弃,consumer 永久失效
- 后续所有 MPC 签名结果都收不到,表现为 signing timeout 300s
- 需要手动 docker restart 才能恢复

根因分析:
- 服务启动时 Kafka broker 可能尚未完成 topic-partition 分配
  (特别是容器编排环境中服务启动顺序不确定)
- onModuleInit() 中的 connect/subscribe/run 是一次性调用
- KafkaJS 的 retry 配置只作用于内部操作,不覆盖初始连接流程

修复方案:
- 新增 connectWithRetry() 方法:指数退避重试(2s→4s→8s→...→60s)
  最多 10 次,总等待约 5 分钟
- 每次重试前断开连接清理状态,避免 KafkaJS 内部状态残留
- 监听 consumer CRASH 事件:当 KafkaJS 不自动重启时(restart=false)
  手动触发 connectWithRetry() 重连
- 新增 isShuttingDown 标志:防止 onModuleDestroy 时触发无意义的重连
- 同时修复 blockchain-service 和 identity-service 两个 consumer

影响范围:
- blockchain-service: 影响 MPC 签名结果接收(热钱包转账)
- identity-service: 影响 MPC 密钥生成结果接收(用户钱包创建)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 19:18:10 -08:00
..
.claude refactor: simplify mpc-service to gateway mode 2025-12-06 17:16:14 -08:00
api-gateway feat(nginx): 添加 madmin.szaiai.com nginx 配置 2026-02-02 00:01:37 -08:00
infrastructure chore(docker): 为 mpc-system、api-gateway、infrastructure 添加时区配置 2025-12-23 18:35:09 -08:00
mpc-system fix(service-party-android): 修复导入钱包签名时 'party not registered' 错误 2026-02-02 03:24:14 -08:00
scripts fix(scripts): 修正容器名为 rwa-blockchain-service 2025-12-15 10:34:25 -08:00
services fix(kafka): 修复 MPC Kafka consumer 启动订阅失败后不重试的问题 2026-02-02 19:18:10 -08:00
.env.windows fix(referral): 修复 getMyReferralInfo 使用 userId 而不是 accountSequence 的问题 2025-12-14 05:05:03 -08:00
docker-compose.windows.yml fix(mining-service): Redis DB 11 冲突修复,迁移至 DB 16 2026-01-30 02:22:20 -08:00