docs/en/nacos.md
A PHP coroutine client of Nacos, perfectly combined with the configuration center and microservice governance of Hyperf.
composer require hyperf/nacos
php bin/hyperf.php vendor:publish hyperf/nacos
<?php
declare(strict_types=1);
return [
// Developers who cannot use the IP port form can directly configure the url
// 'url' => '',
'host' => '127.0.0.1',
'port' => 8848,
'username' => null,
'password' => null,
'guzzle' => [
'config' => null,
],
];
The current component still retains the previously provided service registration functionality.
Just install the hyperf/service-governance-nacos component, then configure the following listeners and custom processes.
Hyperf\ServiceGovernanceNacos\Listener\MainWorkerStartListener
Hyperf\ServiceGovernanceNacos\Listener\OnShutdownListener
Hyperf\ServiceGovernanceNacos\Process\InstanceBeatProcess
Then add the following configuration to listen to the Shutdown event
<?php
use Hyperf\Server\Event;
return [
// ...other
'callbacks' => [
// ...other
Event::ON_SHUTDOWN => [Hyperf\Framework\Bootstrap\ShutdownCallback::class, 'onShutdown']
]
];
When using Aliyun's Nacos service, you may need to use AK and SK authentication. The Nacos component supports it natively. We can easily add the corresponding configuration, as follows:
<?php
declare(strict_types=1);
return [
// nacos server url like https://nacos.hyperf.io, Priority is higher than host:port
// 'uri' => 'http://127.0.0.1:8848/',
// The nacos host info
'host' => '127.0.0.1',
'port' => 8848,
// The nacos account info
'username' => null,
'password' => null,
'access_key' => 'xxxx',
'access_secret' => 'yyyy',
'guzzle' => [
'config' => null,
],
];