Commit 5373c47d authored by xielei's avatar xielei
Browse files

1

No related merge requests found
Showing with 14 additions and 12 deletions
+14 -12
......@@ -23,9 +23,6 @@ $worker = new Worker();
// 设置配置文件
$worker->config_file = __DIR__ . '/config.php';
// 服务标签(供gateway自定义路由选择参考)
$worker->tag_list = [];
// 设置服务端参数 参考:http://wiki.swoole.com/#/server/setting
$worker->set([
'log_file' => __DIR__ . '/log/worker.log',
......@@ -60,6 +57,9 @@ return [
// 自动重载监听的文件或目录(配置文件已自动纳入)。
'reload_watch' => [__DIR__ . '/event/'],
// 服务标签(供gateway自定义路由选择参考)
'tag_list' => [],
// worker事件文件
'worker_file' => __DIR__ . '/event/worker.php',
......
......@@ -32,11 +32,15 @@ class RegisterWorker implements CmdInterface
{
$res = self::decode($buffer);
$address = implode(':', $conn->exportSocket()->getpeername());
$gateway->worker_list[$address] = [
'tag_list' => $res['tag_list'],
'pool' => new ConnectionPool(function () use ($conn) {
return $conn;
}, 1),
];
if (isset($gateway->worker_list[$address])) {
$gateway->worker_list[$address]['tag_list'] = $res['tag_list'];
} else {
$gateway->worker_list[$address] = [
'tag_list' => $res['tag_list'],
'pool' => new ConnectionPool(function () use ($conn) {
return $conn;
}, 1),
];
}
}
}
......@@ -21,8 +21,6 @@ class Worker extends Service
public $register_host = '127.0.0.1';
public $register_port = 9327;
public $tag_list = [];
protected $process;
protected $inner_server;
......@@ -192,7 +190,7 @@ class Worker extends Service
$client = new Client($address['lan_host'], $address['lan_port']);
$client->onConnect = function () use ($client, $address) {
Service::debug("connect to gateway {$address['lan_host']}:{$address['lan_port']} 成功");
$client->send(Protocol::encode(RegisterWorker::encode($this->tag_list)));
$client->send(Protocol::encode(RegisterWorker::encode(Config::get('tag_list', []))));
$ping_buffer = Protocol::encode(pack('C', Ping::getCommandCode()));
$client->timer_id = Timer::tick(30000, function () use ($client, $ping_buffer, $address) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment