rwadurian/backend/services
hailin 014ad9d19f feat(planting): implement Outbox Pattern with consumer acknowledgment (B方案)
Implement reliable event delivery using Outbox Pattern with consumer confirmation:

## planting-service (Producer)
- Add OutboxEvent table with status: PENDING → SENT → CONFIRMED
- Add OutboxRepository with transaction support and timeout handling
- Add OutboxPublisherService with polling, timeout check, and retry
- Add EventAckController to receive consumer confirmations
- Update UnitOfWork to save outbox events atomically with business data
- Update PlantingApplicationService to use outbox pattern
- Update PoolInjectionService to use outbox pattern

## Consumer Services
- Add EventAckPublisher to reward-service, referral-service, authorization-service
- Update event handlers to send acknowledgment after successful processing

## Event Flow
1. Business data + outbox events saved in same transaction
2. OutboxPublisher polls and sends to Kafka, marks as SENT
3. Consumer processes event and sends ack to planting.events.ack
4. EventAckController receives ack and marks as CONFIRMED
5. Timeout check resets SENT→PENDING for retry (max 5 times)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 21:32:16 -08:00
..
.claude fix(mpc-service): change healthcheck from wget to curl 2025-12-06 23:42:48 -08:00
admin-service fix(admin-service): exclude /downloads from API prefix 2025-12-09 07:44:53 -08:00
authorization-service feat(planting): implement Outbox Pattern with consumer acknowledgment (B方案) 2025-12-09 21:32:16 -08:00
backup-service refactor: unify docker-compose configs to use shared infrastructure 2025-12-07 00:35:56 -08:00
blockchain-service fix(blockchain): read token decimals from contract instead of hardcoding 2025-12-09 06:10:36 -08:00
docs docs(services): add MPC integration verification report 2025-12-04 23:56:21 -08:00
identity-service fix(guide): use fitWidth to prevent image stretching + add debug logs 2025-12-09 18:36:43 -08:00
leaderboard-service fix: convert deploy.sh CRLF to LF and add executable permission 2025-12-07 07:01:13 -08:00
mpc-service fix(mpc-service): reduce rebalanceTimeout from 5min to 1min 2025-12-09 03:40:14 -08:00
planting-service feat(planting): implement Outbox Pattern with consumer acknowledgment (B方案) 2025-12-09 21:32:16 -08:00
presence-service fix: convert deploy.sh CRLF to LF and add executable permission 2025-12-07 07:01:13 -08:00
referral-service feat(planting): implement Outbox Pattern with consumer acknowledgment (B方案) 2025-12-09 21:32:16 -08:00
reporting-service fix: convert deploy.sh CRLF to LF and add executable permission 2025-12-07 07:01:13 -08:00
reward-service feat(planting): implement Outbox Pattern with consumer acknowledgment (B方案) 2025-12-09 21:32:16 -08:00
scripts fix(blockchain-service): auto-create database and run migrations on startup 2025-12-07 01:14:50 -08:00
wallet-service feat(db): add Prisma migrations for wallet-service and planting-service 2025-12-09 20:30:23 -08:00
.env.example Revert "fix(mpc-service): don't block startup on Kafka consumer rebalance" 2025-12-09 03:26:05 -08:00
.gitignore refactor(mpc-system): migrate to party-driven architecture with PartyID-based routing 2025-12-05 08:11:28 -08:00
README.md refactor(mpc-system): migrate to party-driven architecture with PartyID-based routing 2025-12-05 08:11:28 -08:00
deploy.sh feat(services): add infra-clean and infra-reset commands 2025-12-07 08:56:36 -08:00
docker-compose.infra.yml feat(identity): store complete deviceInfo JSON from frontend 2025-12-07 11:08:37 -08:00
docker-compose.yml fix(docker): add BASE_URL env for admin-service 2025-12-09 07:31:32 -08:00
init-multiple-dbs.sh feat(identity): store complete deviceInfo JSON from frontend 2025-12-07 11:08:37 -08:00

README.md

RWA Backend Services

统一部署管理 RWA 后端微服务。

架构概览

┌─────────────────────────────────────────────────────────────────┐
│                    192.168.1.100 (Gateway)                       │
│  ┌─────────────┐  ┌─────────────────────────────────────────┐  │
│  │   Nginx     │  │          MPC-System (Go)                 │  │
│  │  (Reverse   │  │  - session-coordinator (:8081)           │  │
│  │   Proxy)    │  │  - message-router (:8082)                │  │
│  │             │  │  - server-party-1/2/3 (:8083-8085)       │  │
│  └─────────────┘  │  - account-service (:8080)               │  │
│                   └─────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────────┘
                              │
                              │ Internal Network
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                    192.168.1.111 (Backend)                       │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │              Docker Compose Services                     │    │
│  │  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐       │    │
│  │  │  PostgreSQL │ │    Redis    │ │    Kafka    │       │    │
│  │  │   (:5432)   │ │   (:6379)   │ │   (:9092)   │       │    │
│  │  └─────────────┘ └─────────────┘ └─────────────┘       │    │
│  │                                                          │    │
│  │  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐       │    │
│  │  │  identity   │ │   wallet    │ │   backup    │       │    │
│  │  │  (:3000)    │ │  (:3001)    │ │  (:3002)    │       │    │
│  │  └─────────────┘ └─────────────┘ └─────────────┘       │    │
│  │                                                          │    │
│  │  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐       │    │
│  │  │  planting   │ │  referral   │ │   reward    │       │    │
│  │  │  (:3003)    │ │  (:3004)    │ │  (:3005)    │       │    │
│  │  └─────────────┘ └─────────────┘ └─────────────┘       │    │
│  │                                                          │    │
│  │  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐       │    │
│  │  │    mpc      │ │ leaderboard │ │  reporting  │       │    │
│  │  │  (:3006)    │ │  (:3007)    │ │  (:3008)    │       │    │
│  │  └─────────────┘ └─────────────┘ └─────────────┘       │    │
│  │                                                          │    │
│  │  ┌─────────────┐ ┌─────────────┐                        │    │
│  │  │authorization│ │   admin     │                        │    │
│  │  │  (:3009)    │ │  (:3010)    │                        │    │
│  │  └─────────────┘ └─────────────┘                        │    │
│  └─────────────────────────────────────────────────────────┘    │
└─────────────────────────────────────────────────────────────────┘

快速开始

1. 首次安装

# 进入服务目录
cd ~/rwadurian/backend/services

# 运行安装(自动生成安全密钥)
./deploy.sh install

2. 构建镜像

./deploy.sh build

3. 启动服务

./deploy.sh up

4. 检查状态

./deploy.sh status
./deploy.sh health

常用命令

命令 说明
./deploy.sh install 首次安装,生成配置
./deploy.sh build 构建所有 Docker 镜像
./deploy.sh up 启动所有服务
./deploy.sh down 停止所有服务
./deploy.sh restart 重启所有服务
./deploy.sh status 查看服务状态
./deploy.sh health 检查服务健康
./deploy.sh logs 查看所有日志
./deploy.sh logs <service> 查看指定服务日志
./deploy.sh migrate 运行数据库迁移
./deploy.sh rebuild-svc <name> 重建指定服务

服务列表

服务 端口 说明
identity-service 3000 身份认证服务
wallet-service 3001 钱包账本服务
backup-service 3002 MPC 备份服务
planting-service 3003 认种服务
referral-service 3004 推荐系统服务
reward-service 3005 奖励服务
mpc-service 3006 MPC 中间层服务
leaderboard-service 3007 排行榜服务
reporting-service 3008 报表服务
authorization-service 3009 授权服务
admin-service 3010 管理后台服务

基础设施

服务 端口 说明
PostgreSQL 5432 主数据库
Redis 6379 缓存/会话
Kafka 9092 消息队列
Zookeeper 2181 Kafka 协调

环境配置

配置文件 .env./deploy.sh install 自动生成,包含:

  • 数据库密码
  • JWT 密钥
  • 加密密钥
  • MPC 系统地址

重要: .env 文件包含敏感信息,请勿提交到 Git

与 MPC-System 集成

mpc-service 需要连接到运行在 192.168.1.100 上的 MPC-System

  • Session Coordinator: http://192.168.1.100:8081
  • Message Router: ws://192.168.1.100:8082

确保 192.168.1.111 能够访问 192.168.1.100 的这些端口。

故障排除

查看服务日志

./deploy.sh logs identity-service

重建单个服务

./deploy.sh rebuild-svc mpc-service

数据库连接问题

# 进入 postgres 容器
docker exec -it rwa-postgres psql -U rwa_user -d rwa_identity

清理重新开始

./deploy.sh clean  # 删除所有容器和数据
./deploy.sh install
./deploy.sh build
./deploy.sh up