add mq user
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Hyperf\DbConnection\Db;
|
||||
|
||||
/**
|
||||
* RabbitMQ 用户配置
|
||||
*
|
||||
* 密码存储在 .env 文件中(由 bin/rabbitmq.sh 自动生成)
|
||||
* 平台列表从数据库 platforms 表动态读取
|
||||
*
|
||||
* .env 变量格式:
|
||||
* MQ_PASSWORD_CONSUMER=xxx - 消费者用户密码
|
||||
* MQ_PASSWORD_OPS=xxx - 运维用户密码
|
||||
* MQ_PASSWORD_SHOPEE=xxx - 平台用户密码(平台名大写)
|
||||
*/
|
||||
return [
|
||||
// 消费者用户
|
||||
'consumer' => [
|
||||
'user' => 'user_dataflow_consumer',
|
||||
'password' => env('MQ_PASSWORD_CONSUMER', ''),
|
||||
],
|
||||
|
||||
// 运维用户
|
||||
'ops' => [
|
||||
'user' => 'user_ops',
|
||||
'password' => env('MQ_PASSWORD_OPS', ''),
|
||||
],
|
||||
|
||||
// 平台用户(动态从数据库读取)
|
||||
'platforms' => (static function (): array {
|
||||
$platforms = [];
|
||||
|
||||
try {
|
||||
// 从数据库获取所有启用的平台
|
||||
$rows = Db::table('platforms')
|
||||
->where('enabled', true)
|
||||
->orderBy('id')
|
||||
->get(['name']);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
// 平台名称标准化:空格转下划线,全部小写
|
||||
$normalizedName = strtolower(str_replace(' ', '_', $row->name));
|
||||
// 环境变量名:大写
|
||||
$envKey = 'MQ_PASSWORD_' . strtoupper($normalizedName);
|
||||
|
||||
$platforms[$normalizedName] = [
|
||||
'user' => 'user_' . $normalizedName,
|
||||
'password' => env($envKey, ''),
|
||||
];
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// 数据库不可用时返回空数组,避免应用启动失败
|
||||
}
|
||||
|
||||
return $platforms;
|
||||
})(),
|
||||
];
|
||||
Reference in New Issue
Block a user