fix(injection): docker-compose 添加注入钱包环境变量 + 未配置时不启用消费者
问题:
.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 <noreply@anthropic.com>
This commit is contained in:
parent
c93eeba79a
commit
1baed76d8e
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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<string>(
|
||||
|
|
@ -38,7 +39,19 @@ export class AdoptionInjectionConsumerService implements OnModuleInit, OnModuleD
|
|||
);
|
||||
}
|
||||
|
||||
isEnabled(): boolean {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
async onModuleInit() {
|
||||
// 未配置注入钱包时不启用消费者
|
||||
const walletUsername = this.configService.get<string>('FUSDT_INJECTION_WALLET_USERNAME');
|
||||
const walletAddress = this.configService.get<string>('FUSDT_INJECTION_WALLET_ADDRESS');
|
||||
if (!walletUsername || !walletAddress) {
|
||||
this.logger.warn(`[INIT] fUSDT 注入钱包未配置,Adoption Injection Consumer 不启用`);
|
||||
return;
|
||||
}
|
||||
|
||||
const brokers = this.configService.get<string>('KAFKA_BROKERS')?.split(',') || ['localhost:9092'];
|
||||
const clientId = this.configService.get<string>('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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue