Files
wh-api/app/Amqp/Producer/BaseProducer.php
ykxiao 8a3ab17b25
Some checks failed
Build Docker / build (push) Has been cancelled
增加基础配置
2025-07-12 11:59:33 +08:00

49 lines
1.1 KiB
PHP

<?php
/**
* Author: ykxiao
* Date: 2025/6/6
* Time: 上午9:53
* Description:
*
* (c) ykxiao <yk_9001@hotmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
declare(strict_types=1);
namespace App\Amqp\Producer;
use App\Context\ApiUrlContext;
use App\Context\UserContext;
use Hyperf\Amqp\Message\ProducerMessage;
/**
* Author: ykxiao
* Date: 2025/6/6
* Time: 上午9:57
* Description: amqp生产者抽象基类.
*
* (c) ykxiao <yk_9001@hotmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
abstract class BaseProducer extends ProducerMessage
{
public function __construct(array $data)
{
// 设置用户信息上下文信息
if (UserContext::hasCurrentUser()) {
$data['user'] = UserContext::getCurrentUser();
}
if (ApiUrlContext::hasApiUrl()) {
$data['api_url'] = ApiUrlContext::getApiUrl();
}
$this->payload = $data;
$this->properties['delivery_mode'] = 2; // 消息持久化
}
}