Ai
1 Star 1 Fork 1

zhen/hyperf_rocketmq

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Builder.php 2.30 KB
一键复制 编辑 原始数据 按行查看 历史
zhen 提交于 2022-05-25 10:12 +08:00 . 格式化代码
<?php
/**
* @Author: laoweizhen <1149243551@qq.com>,
* @Date: 2022/5/11 23:10,
* @LastEditTime: 2022/5/11 23:10
*/
declare(strict_types=1);
namespace Lwz\HyperfRocketMQ;
use Hyperf\Guzzle\PoolHandler;
use Hyperf\Logger\LoggerFactory;
use Hyperf\Utils\Coroutine;
use Lwz\HyperfRocketMQ\Library\MQClient;
use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
class Builder
{
protected ContainerInterface $container;
protected ?EventDispatcherInterface $eventDispatcher = null;
protected LoggerFactory $loggerFactory;
protected LoggerInterface $logger;
public function __construct(ContainerInterface $container, LoggerFactory $loggerFactory)
{
$this->container = $container;
$this->loggerFactory = $loggerFactory;
if ($container->has(EventDispatcherInterface::class)) {
$this->eventDispatcher = $container->get(EventDispatcherInterface::class);
}
}
protected function getClient(Config $config): MQClient
{
return new MQClient(
$config->getHost(),
$config->getAccessKey(),
$config->getSecretKey(),
null,
$this->getMQConfig($config)
);
}
protected function setLogger(string $groupName): void
{
$this->logger = $this->loggerFactory->get('rocketmq_log', $groupName ?: 'default');
}
/**
* 配置文件转换.
*/
protected function getMQConfig(Config $config): Library\Config
{
$mqConfig = new \Lwz\HyperfRocketMQ\Library\Config();
$mqConfig->setConnectTimeout($config->getConnectTimeout());
$mqConfig->setRequestTimeout($config->getWaitTimeout());
$mqConfig->setHandler(make(PoolHandler::class, [
'option' => [
'min_connections' => $config->getMinConnections(),
'max_connections' => $config->getMaxConnection(),
'connect_timeout' => $config->getConnectTimeout(),
'wait_timeout' => $config->getWaitTimeout(),
'heartbeat' => $config->getHeartBeat(),
'max_idle_time' => $config->getMaxIdleTime(),
],
]));
return $mqConfig;
}
protected function isCoroutine(): bool
{
return Coroutine::id() > 0;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/easy_code/hyperf_rocketmq.git
git@gitee.com:easy_code/hyperf_rocketmq.git
easy_code
hyperf_rocketmq
hyperf_rocketmq
master

搜索帮助