测试: 完成游戏娱乐模块 (Gomoku, HorseRace, Lottery 等) 功能全量联调测试与代码格式化
This commit is contained in:
@@ -33,16 +33,32 @@ class KafkaConsumerService
|
||||
protected string $groupId = '';
|
||||
|
||||
/**
|
||||
* 构造函数 — 从 SysParam 获取配置
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$param = SysParam::where('alias', 'wechat_bot_config')->first();
|
||||
if ($param && ! empty($param->body)) {
|
||||
$config = json_decode($param->body, true);
|
||||
$this->brokers = $config['kafka']['brokers'] ?? '';
|
||||
$this->topic = $config['kafka']['topic'] ?? '';
|
||||
$this->groupId = $config['kafka']['group_id'] ?? 'chatroom_wechat_bot';
|
||||
// 延迟加载配置
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载 Kafka 配置
|
||||
*/
|
||||
protected function loadConfig(): void
|
||||
{
|
||||
if (! empty($this->brokers)) {
|
||||
return; // 已经加载过
|
||||
}
|
||||
|
||||
try {
|
||||
$param = SysParam::where('alias', 'wechat_bot_config')->first();
|
||||
if ($param && ! empty($param->body)) {
|
||||
$config = json_decode($param->body, true);
|
||||
$this->brokers = $config['kafka']['brokers'] ?? '';
|
||||
$this->topic = $config['kafka']['topic'] ?? '';
|
||||
$this->groupId = $config['kafka']['group_id'] ?? 'chatroom_wechat_bot';
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('加载 Kafka 配置失败', ['error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +67,8 @@ class KafkaConsumerService
|
||||
*/
|
||||
public function createConsumer(): ?Consumer
|
||||
{
|
||||
$this->loadConfig();
|
||||
|
||||
if (empty($this->brokers) || empty($this->topic)) {
|
||||
Log::warning('WechatBot Kafka: brokers or topic is empty. Consumer not started.');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user