update mq cotroller

This commit is contained in:
2026-03-17 10:30:31 +08:00
parent 0c013a8c10
commit 2ce5fb4f3e
@@ -8,6 +8,7 @@ use App\Controller\AbstractController;
use App\Middleware\AuthMiddleware; use App\Middleware\AuthMiddleware;
use App\Middleware\PermissionMiddleware; use App\Middleware\PermissionMiddleware;
use App\Service\MqStatusService; use App\Service\MqStatusService;
use App\Utils\Log;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
@@ -86,9 +87,25 @@ class MqStatusController extends AbstractController
'data' => $data, 'data' => $data,
]; ];
} catch (\Throwable $e) { } catch (\Throwable $e) {
Log::get()->error('MQ status query failed', [
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
]);
// 脱敏:mask 异常消息中的敏感信息(IP、端口、认证凭证)
$safe_message = preg_replace(
[
'/\/\/[^:]+:[^@]+@/', // user:pass@ → //***:***@
'/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', // IP 地址
'/:\d{4,5}(?=[\/\s\)]|$)/', // 端口号
],
['//***:***@', '***.***.***.***', ':****'],
$e->getMessage()
);
return $this->response->json([ return $this->response->json([
'code' => 500, 'code' => 500,
'message' => 'RabbitMQ 连接异常: ' . $e->getMessage(), 'message' => 'RabbitMQ 连接异常: ' . $safe_message,
'data' => null, 'data' => null,
])->withStatus(500); ])->withStatus(500);
} }