Skip to content

Commit

Permalink
废弃 Connection 注解改为废弃连接配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Oct 18, 2023
1 parent a60c786 commit d465d50
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 82 deletions.
4 changes: 2 additions & 2 deletions doc/base/version/2.1-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

* 连接配置项有所增改,参考 [连接配置项](https://doc.imiphp.com/v3.0/components/mq/amqp.html#%E8%BF%9E%E6%8E%A5%E9%85%8D%E7%BD%AE%E9%A1%B9)

* 废弃 `Imi\AMQP\Swoole\AMQPSwooleConnection` 客户端类
* `Imi\AMQP\Annotation\Connection` 注解类的连接配置全部废弃,只保留 `poolName`

* 废弃 `Imi\AMQP\Annotation\Connection` 注解类
* 废弃 `Imi\AMQP\Swoole\AMQPSwooleConnection` 客户端类
41 changes: 2 additions & 39 deletions src/Components/amqp/src/Annotation/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,7 @@
*
* @Target({"CLASS"})
*
* @property string|null $poolName 连接池名称
* @property string $host 主机
* @property int $port 端口
* @property string $user 用户名
* @property string $password 密码
* @property string $vhost
* @property bool $insist
* @property string $loginMethod
* @property null $loginResponse
* @property string $locale
* @property float $connectionTimeout 连接超时
* @property float $readWriteTimeout 读写超时
* @property null $context 上下文
* @property bool $keepalive
* @property int $heartbeat 心跳时间
* @property float $channelRpcTimeout 频道 RPC 超时时间
* @property string|null $sslProtocol ssl 协议
* @property string|null $poolName 连接池名称
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class Connection extends Base
Expand All @@ -39,30 +23,9 @@ class Connection extends Base
*/
protected ?string $defaultFieldName = 'poolName';

/**
* @param null $loginResponse
* @param null $context
*/
public function __construct(
?array $__data = null,
?string $poolName = null,
string $host = '',
int $port = 0,
string $user = '',
#[\SensitiveParameter]
string $password = '',
string $vhost = '/',
bool $insist = false,
string $loginMethod = 'AMQPLAIN',
$loginResponse = null,
string $locale = 'en_US',
float $connectionTimeout = 3.0,
float $readWriteTimeout = 3.0,
$context = null,
bool $keepalive = false,
int $heartbeat = 0,
float $channelRpcTimeout = 0.0,
?string $sslProtocol = null
?string $poolName = null
) {
parent::__construct(...\func_get_args());
}
Expand Down
42 changes: 1 addition & 41 deletions src/Components/amqp/src/Base/Traits/TAMQP.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,47 +96,7 @@ protected function initConfig(): void
*/
protected function getConnection(): AbstractConnection
{
$poolName = null;
if (null === $this->poolName)
{
$connectionByPool = false;
$connectionAnnotation = $this->connectionAnnotation;
if ($connectionAnnotation)
{
if (null === $connectionAnnotation->poolName)
{
if (!(null !== $connectionAnnotation->host && null !== $connectionAnnotation->port && null !== $connectionAnnotation->user && null !== $connectionAnnotation->password))
{
$connectionByPool = true;
}
}
else
{
$connectionByPool = true;
}
}
else
{
$connectionByPool = true;
}
if ($connectionByPool)
{
$poolName = $connectionAnnotation->poolName ?? $this->amqp->getDefaultPoolName();
}
}
else
{
$connectionByPool = true;
$poolName = $this->poolName;
}
if ($connectionByPool || $poolName)
{
return AMQPPool::getInstance($poolName);
}
else
{
throw new \RuntimeException('Connection poolName must be set');
}
return AMQPPool::getInstance($this->poolName ?? $this->connectionAnnotation->poolName ?? null);
}

/**
Expand Down

0 comments on commit d465d50

Please sign in to comment.