qqq
This commit is contained in:
+12
-20
@@ -2,15 +2,9 @@
|
||||
|
||||
namespace Kiri\Rpc;
|
||||
|
||||
use Kiri\Annotation\Inject;
|
||||
use Exception;
|
||||
use Kiri\Message\Response;
|
||||
use Kiri\Message\Stream;
|
||||
use Kiri\Abstracts\Config;
|
||||
use Kiri\Di\Inject\Container;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Swoole\Coroutine\Client;
|
||||
|
||||
class JsonRpcPoolTransporter implements JsonRpcTransporterInterface
|
||||
{
|
||||
@@ -19,16 +13,18 @@ class JsonRpcPoolTransporter implements JsonRpcTransporterInterface
|
||||
use TraitTransporter;
|
||||
|
||||
|
||||
#[Inject(ClientPool::class)]
|
||||
#[Container(ClientPool::class)]
|
||||
public ClientPool $pool;
|
||||
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @param string $service
|
||||
* @return string|bool
|
||||
* @throws ConfigException|RpcServiceException
|
||||
*/
|
||||
/**
|
||||
* @param string $content
|
||||
* @param string $service
|
||||
* @return string|bool
|
||||
* @throws ConfigException
|
||||
* @throws RpcServiceException
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function push(string $content, string $service): string|bool
|
||||
{
|
||||
$client = $this->get_consul($service)->getClient();
|
||||
@@ -42,16 +38,12 @@ class JsonRpcPoolTransporter implements JsonRpcTransporterInterface
|
||||
|
||||
|
||||
/**
|
||||
* @return Client|\Swoole\Client
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getClient(): Client|\Swoole\Client
|
||||
private function getClient()
|
||||
{
|
||||
$this->config['pool'] = Config::get('rpc.pool', ['max' => 10, 'min' => 1, 'waite' => 60]);
|
||||
return $this->pool->get($this->config, function () {
|
||||
return $this->newClient();
|
||||
});
|
||||
return $this->pool->get($this->config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user