From 1baed76d8e610cfd2b0eec8d519d42341841a203 Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 3 Feb 2026 06:08:48 -0800 Subject: [PATCH] =?UTF-8?q?fix(injection):=20docker-compose=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B3=A8=E5=85=A5=E9=92=B1=E5=8C=85=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=20+=20=E6=9C=AA=E9=85=8D=E7=BD=AE=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E5=90=AF=E7=94=A8=E6=B6=88=E8=B4=B9=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: .env 配置了 FUSDT_INJECTION_WALLET_USERNAME 和 FUSDT_INJECTION_WALLET_ADDRESS, 但 docker-compose.2.0.yml 没有将这两个变量传入容器,导致容器内 process.env 拿不到值,Adoption Injection Consumer 启动后报错。 修复: 1. docker-compose.2.0.yml: 添加 FUSDT_INJECTION_WALLET_USERNAME/ADDRESS 和 CDC_TOPIC_CONTRIBUTION_OUTBOX 环境变量传递 2. AdoptionInjectionConsumerService: onModuleInit 检查钱包是否配置, 未配置时跳过 Kafka 连接(不浪费消费者组资源) 3. AdoptionInjectionHandler: 检查 Consumer 是否启用,未启用时不注册 Co-Authored-By: Claude Opus 4.5 --- backend/services/docker-compose.2.0.yml | 5 +++++ .../event-handlers/adoption-injection.handler.ts | 4 ++++ .../kafka/adoption-injection-consumer.service.ts | 14 ++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/backend/services/docker-compose.2.0.yml b/backend/services/docker-compose.2.0.yml index 7810b940..f943f117 100644 --- a/backend/services/docker-compose.2.0.yml +++ b/backend/services/docker-compose.2.0.yml @@ -460,6 +460,11 @@ services: BURN_POOL_WALLET_ADDRESS: ${BURN_POOL_WALLET_ADDRESS:-} MINING_POOL_WALLET_USERNAME: ${MINING_POOL_WALLET_USERNAME:-} MINING_POOL_WALLET_ADDRESS: ${MINING_POOL_WALLET_ADDRESS:-} + # fUSDT 注入钱包 (MPC) - 认种自动转积分值到做市商 + FUSDT_INJECTION_WALLET_USERNAME: ${FUSDT_INJECTION_WALLET_USERNAME:-} + FUSDT_INJECTION_WALLET_ADDRESS: ${FUSDT_INJECTION_WALLET_ADDRESS:-} + # CDC 主题配置(Debezium CDC outbox) + CDC_TOPIC_CONTRIBUTION_OUTBOX: ${CDC_TOPIC_CONTRIBUTION_OUTBOX:-cdc.contribution.outbox} # 区块扫描配置 BLOCK_SCAN_INTERVAL_MS: ${BLOCK_SCAN_INTERVAL_MS:-5000} BLOCK_CONFIRMATIONS_REQUIRED: ${BLOCK_CONFIRMATIONS_REQUIRED:-12} diff --git a/backend/services/mining-blockchain-service/src/application/event-handlers/adoption-injection.handler.ts b/backend/services/mining-blockchain-service/src/application/event-handlers/adoption-injection.handler.ts index 02d607db..a5ea81d5 100644 --- a/backend/services/mining-blockchain-service/src/application/event-handlers/adoption-injection.handler.ts +++ b/backend/services/mining-blockchain-service/src/application/event-handlers/adoption-injection.handler.ts @@ -40,6 +40,10 @@ export class AdoptionInjectionHandler implements OnModuleInit { ) {} onModuleInit() { + if (!this.injectionConsumer.isEnabled()) { + this.logger.warn(`[INIT] Adoption Injection Consumer 未启用,Handler 不注册`); + return; + } this.injectionConsumer.onAdoptionInjectionRequested( this.handleInjection.bind(this), ); diff --git a/backend/services/mining-blockchain-service/src/infrastructure/kafka/adoption-injection-consumer.service.ts b/backend/services/mining-blockchain-service/src/infrastructure/kafka/adoption-injection-consumer.service.ts index 44d18cac..ccb8d4fa 100644 --- a/backend/services/mining-blockchain-service/src/infrastructure/kafka/adoption-injection-consumer.service.ts +++ b/backend/services/mining-blockchain-service/src/infrastructure/kafka/adoption-injection-consumer.service.ts @@ -30,6 +30,7 @@ export class AdoptionInjectionConsumerService implements OnModuleInit, OnModuleD private readonly topic: string; private injectionHandler?: AdoptionInjectionEventHandler; + private enabled = false; constructor(private readonly configService: ConfigService) { this.topic = this.configService.get( @@ -38,7 +39,19 @@ export class AdoptionInjectionConsumerService implements OnModuleInit, OnModuleD ); } + isEnabled(): boolean { + return this.enabled; + } + async onModuleInit() { + // 未配置注入钱包时不启用消费者 + const walletUsername = this.configService.get('FUSDT_INJECTION_WALLET_USERNAME'); + const walletAddress = this.configService.get('FUSDT_INJECTION_WALLET_ADDRESS'); + if (!walletUsername || !walletAddress) { + this.logger.warn(`[INIT] fUSDT 注入钱包未配置,Adoption Injection Consumer 不启用`); + return; + } + const brokers = this.configService.get('KAFKA_BROKERS')?.split(',') || ['localhost:9092']; const clientId = this.configService.get('KAFKA_CLIENT_ID') || 'mining-blockchain-service'; const groupId = 'mining-blockchain-adoption-injection'; @@ -81,6 +94,7 @@ export class AdoptionInjectionConsumerService implements OnModuleInit, OnModuleD this.logger.log(`[SUBSCRIBE] Subscribed to ${this.topic}`); await this.startConsuming(); + this.enabled = true; } catch (error) { this.logger.error(`[ERROR] Failed to connect Adoption Injection consumer`, error); }