mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Fixed bug that custom processes cannot fetch config from nacos. (#2149)
* 增加支持配置同步更新至用户自定义进程 * 修复心跳namespaceId参数缺少导致nacos心跳至public * 调整服务、实例创建注册顺序 Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
911b73f3fe
commit
ee843711b7
@ -12,6 +12,7 @@
|
||||
|
||||
## Fixed
|
||||
|
||||
- [#2149](https://github.com/hyperf/hyperf/pull/2149) Fixed bug that custom processes cannot fetch config from nacos.
|
||||
- [#2159](https://github.com/hyperf/hyperf/pull/2159) Fixed fatal exception caused by exist file when using `gen:migration`.
|
||||
|
||||
## Optimized
|
||||
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
return [
|
||||
// The nacos host info
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 8848,
|
||||
// The service info.
|
||||
@ -36,6 +37,7 @@ return [
|
||||
'listener_config' => [
|
||||
// dataId, group, tenant, type, content
|
||||
//[
|
||||
// 'tenant' => 'tenant', // corresponding with service.namespaceId
|
||||
// 'data_id' => 'hyperf-service-config',
|
||||
// 'group' => 'DEFAULT_GROUP',
|
||||
//],
|
||||
|
@ -99,7 +99,8 @@ class NacosInstance extends AbstractNacos
|
||||
$serviceName = $serviceModel->serviceName;
|
||||
$groupName = $serviceModel->groupName;
|
||||
$ephemeral = $instanceModel->ephemeral;
|
||||
$params = array_filter(compact('serviceName', 'groupName', 'ephemeral'), function ($item) {
|
||||
$namespaceId = $instanceModel->namespaceId;
|
||||
$params = array_filter(compact('serviceName', 'groupName', 'ephemeral', 'namespaceId'), function ($item) {
|
||||
return $item !== null;
|
||||
});
|
||||
$params['beat'] = $instanceModel->toJson();
|
||||
|
@ -14,6 +14,7 @@ namespace Hyperf\Nacos\Config;
|
||||
use Hyperf\Contract\ConfigInterface;
|
||||
use Hyperf\Nacos\Client;
|
||||
use Hyperf\Process\AbstractProcess;
|
||||
use Hyperf\Process\ProcessCollector;
|
||||
use Swoole\Coroutine\Server as CoServer;
|
||||
use Swoole\Server;
|
||||
|
||||
@ -48,6 +49,16 @@ class FetchConfigProcess extends AbstractProcess
|
||||
for ($workerId = 0; $workerId <= $workerCount; ++$workerId) {
|
||||
$this->server->sendMessage($pipeMessage, $workerId);
|
||||
}
|
||||
|
||||
$processes = ProcessCollector::all();
|
||||
if ($processes) {
|
||||
$string = serialize($pipeMessage);
|
||||
/** @var \Swoole\Process $process */
|
||||
foreach ($processes as $process) {
|
||||
$process->exportSocket()->send($string);
|
||||
}
|
||||
}
|
||||
|
||||
$cache = $remoteConfig;
|
||||
}
|
||||
sleep((int) $config->get('nacos.config_reload_interval', 3));
|
||||
|
@ -14,6 +14,7 @@ namespace Hyperf\Nacos\Config;
|
||||
use Hyperf\Contract\ConfigInterface;
|
||||
use Hyperf\Event\Contract\ListenerInterface;
|
||||
use Hyperf\Framework\Event\OnPipeMessage;
|
||||
use Hyperf\Process\Event\PipeMessage as UserProcessPipMessage;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class OnPipeMessageListener implements ListenerInterface
|
||||
@ -35,6 +36,7 @@ class OnPipeMessageListener implements ListenerInterface
|
||||
{
|
||||
return [
|
||||
OnPipeMessage::class,
|
||||
UserProcessPipMessage::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -56,13 +56,6 @@ class MainWorkerStartListener implements ListenerInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$instance = $this->container->get(Instance::class);
|
||||
$nacosInstance = $this->container->get(NacosInstance::class);
|
||||
if (! $nacosInstance->register($instance)) {
|
||||
throw new RuntimeException(sprintf('nacos register instance fail: %s', $instance));
|
||||
}
|
||||
$this->logger->info('nacos register instance success.', compact('instance'));
|
||||
|
||||
$nacosService = $this->container->get(NacosService::class);
|
||||
$service = $this->container->get(Service::class);
|
||||
$exist = $nacosService->detail($service);
|
||||
@ -71,6 +64,13 @@ class MainWorkerStartListener implements ListenerInterface
|
||||
}
|
||||
$this->logger->info('nacos register service success.', compact('service'));
|
||||
|
||||
$instance = $this->container->get(Instance::class);
|
||||
$nacosInstance = $this->container->get(NacosInstance::class);
|
||||
if (! $nacosInstance->register($instance)) {
|
||||
throw new RuntimeException(sprintf('nacos register instance fail: %s', $instance));
|
||||
}
|
||||
$this->logger->info('nacos register instance success.', compact('instance'));
|
||||
|
||||
$client = $this->container->get(Client::class);
|
||||
$config = $this->container->get(ConfigInterface::class);
|
||||
$appendNode = $config->get('nacos.config_append_node');
|
||||
|
@ -41,7 +41,7 @@ abstract class AbstractModel implements Arrayable
|
||||
$params = array_filter(get_object_vars($this), function ($item) {
|
||||
return $item !== null;
|
||||
});
|
||||
unset($params['required_field']);
|
||||
unset($params['requiredFields']);
|
||||
$intersect = array_intersect(array_keys($params), $this->requiredFields);
|
||||
sort($this->requiredFields);
|
||||
sort($intersect);
|
||||
|
Loading…
Reference in New Issue
Block a user