rwadurian/backend/services/blockchain-service
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 fix(mobile-app): update share link domain to rwaapi.szaiai.com 2025-12-06 21:15:55 -08:00
contracts feat(blockchain): 部署 eUSDT 和 fUSDT 代币合约 2026-01-19 05:30:25 -08:00
prisma fix(blockchain-service): 扩大充值金额字段精度 2025-12-25 18:19:48 -08:00
scripts feat(blockchain-service): KAVA EVM address derivation and system accounts support 2025-12-08 21:45:34 -08:00
src fix(kafka): 修复 MPC Kafka consumer 启动订阅失败后不重试的问题 2026-02-02 19:18:10 -08:00
.dockerignore feat(blockchain-service): implement complete blockchain service with DDD + Hexagonal architecture 2025-12-06 20:54:58 -08:00
.env.example feat(blockchain): 切换到dUSDT(绿积分)合约 - KAVA主网 2026-01-02 04:31:11 -08:00
.eslintrc.js feat(blockchain-service): implement complete blockchain service with DDD + Hexagonal architecture 2025-12-06 20:54:58 -08:00
.gitignore feat(blockchain-service): implement complete blockchain service with DDD + Hexagonal architecture 2025-12-06 20:54:58 -08:00
.prettierrc feat(blockchain-service): implement complete blockchain service with DDD + Hexagonal architecture 2025-12-06 20:54:58 -08:00
DEVELOPMENT_GUIDE.md refactor: 多项UI优化和品牌更名 2025-12-15 01:43:47 -08:00
Dockerfile fix(blockchain-service): 添加 --accept-data-loss 参数 2025-12-25 18:28:23 -08:00
deploy.sh . 2025-12-07 00:40:19 -08:00
docker-compose.yml feat(blockchain): 将提现转账从私钥签名改为 MPC 签名 2025-12-15 08:04:17 -08:00
nest-cli.json feat(blockchain-service): implement complete blockchain service with DDD + Hexagonal architecture 2025-12-06 20:54:58 -08:00
package-lock.json feat(deposit): add deposit balance API and Kafka consumer for deposit events 2025-12-09 02:29:31 -08:00
package.json feat(deposit): add deposit balance API and Kafka consumer for deposit events 2025-12-09 02:29:31 -08:00
tsconfig.json feat(blockchain-service): implement complete blockchain service with DDD + Hexagonal architecture 2025-12-06 20:54:58 -08:00