This commit is contained in:
2021-12-02 15:48:32 +08:00
parent 7293e24f9d
commit 9a6575b438
2 changed files with 18 additions and 6 deletions
+1
View File
@@ -113,6 +113,7 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa
*/ */
public function register(OnServerBeforeStart $server) public function register(OnServerBeforeStart $server)
{ {
$this->manager->tableInit();
$this->manager->register(); $this->manager->register();
} }
+17 -6
View File
@@ -2,10 +2,12 @@
namespace Kiri\Rpc; namespace Kiri\Rpc;
use Kiri\Abstracts\Config;
use Kiri\Consul\Agent; use Kiri\Consul\Agent;
use Kiri\Consul\Health; use Kiri\Consul\Health;
use Kiri\Kiri; use Kiri\Kiri;
use ReflectionException; use ReflectionException;
use Swoole\Table;
class RpcManager class RpcManager
{ {
@@ -17,6 +19,17 @@ class RpcManager
private array $_rpc = []; private array $_rpc = [];
private Table $table;
public function tableInit()
{
$this->table = new Table((int)Config::get('rpc.total', 10));
$this->table->column('content', Table::TYPE_STRING);
$this->table->create();
}
/** /**
* @param $serviceName * @param $serviceName
* @return void * @return void
@@ -30,12 +43,10 @@ class RpcManager
return; return;
} }
$body = json_decode($lists->getBody(), true); $body = json_decode($lists->getBody(), true);
$file = storage('.rpc.clients.' . md5($serviceName), 'rpc');
if (!empty($body) && is_array($body)) { if (!empty($body) && is_array($body)) {
file_put_contents($file, json_encode(array_column($body, 'Service'))); $this->table->set($serviceName, ['content' => json_encode(array_column($body, 'Service'))]);
} else { } else {
file_put_contents($file, json_encode([])); $this->table->set($serviceName, ['content' => json_encode([])]);
} }
} }
@@ -59,10 +70,10 @@ class RpcManager
public function getServices($serviceName): array public function getServices($serviceName): array
{ {
$file = storage('.rpc.clients.' . md5($serviceName), 'rpc'); $file = storage('.rpc.clients.' . md5($serviceName), 'rpc');
if (!file_exists($file)) { if (!$this->table->exist($file)) {
return []; return [];
} }
$content = json_decode(file_get_contents($file), true); $content = json_decode($this->table->get($serviceName), true);
if (empty($content) || !is_array($content)) { if (empty($content) || !is_array($content)) {
return []; return [];
} }