Skip to content

Commit

Permalink
improve: 优化 etcd 细节
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed May 8, 2020
1 parent de2e2c5 commit 10b49d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
14 changes: 9 additions & 5 deletions src/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class Configurator implements ConfiguratorInterface
public $namespace = '/micro/config';

/**
* @var EventDispatcherInterface
* @var int
*/
public $dispatcher;
public $interval = 5;

/**
* @var Client
Expand Down Expand Up @@ -94,14 +94,18 @@ protected function createClient()

/**
* Listen
* @param EventDispatcherInterface $dispatcher
* @throws \RuntimeException
* @throws \GuzzleHttp\Exception\BadResponseException
*/
public function listen()
public function listen(EventDispatcherInterface $dispatcher)
{
if (isset($this->listenTimer)) {
throw new \RuntimeException('Already listening');
}
if (!isset($this->dispatcher)) {
throw new \RuntimeException('Please set dispatcher first');
}
// 拉取全量
$lastConfig = $this->all();
foreach ($lastConfig as $key => $value) {
Expand Down Expand Up @@ -171,7 +175,7 @@ public function all()
* @param array $kvs
* @throws \GuzzleHttp\Exception\BadResponseException
*/
public function put(array $kvs)
protected function put(array $kvs)
{
$client = $this->client;
foreach ($kvs as $key => $value) {
Expand All @@ -183,7 +187,7 @@ public function put(array $kvs)
* Delete
* @param array $keys
*/
public function delete(array $keys)
protected function delete(array $keys)
{
$client = $this->client;
foreach ($keys as $key) {
Expand Down
15 changes: 7 additions & 8 deletions src/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class Registry implements RegistryInterface
*/
public $password = '';

/**
* @var string
*/
public $namespace = '/micro/registry';

/**
* Registrar keep alive TTL
* 注册器生存时间,会根据该时间定时延期服务的有效期
Expand All @@ -58,13 +63,7 @@ class Registry implements RegistryInterface
* 监控最大空闲时间,超过该时间将自动关闭
* @var int
*/
public $monitorMaxIdle = 30;

/**
*
* @var string
*/
public $namespace = '/micro/registry';
public $maxIdle = 30;

/**
* 负载均衡器
Expand Down Expand Up @@ -136,7 +135,7 @@ protected function getDefaultLoadBalancer()
public function service(string $name): ServiceInterface
{
if (!isset($this->monitors[$name])) {
$monitor = new Monitor($this->client, $this->monitors, $this->namespace, $name, $this->monitorMaxIdle);
$monitor = new Monitor($this->client, $this->monitors, $this->namespace, $name, $this->maxIdle);
$this->monitors[$name] = $monitor;
}
$services = $this->monitors[$name]->services();
Expand Down

0 comments on commit 10b49d0

Please sign in to comment.