Code Monkey home page Code Monkey logo

nacos's Introduction

Nacos SDK

安装

composer require hyperf/nacos

使用

<?php

use Hyperf\Nacos\Application;
use Hyperf\Nacos\Config;
use Hyperf\Codec\Json;

$application = new Application(new Config([
    'username' => 'nacos',
    'password' => 'nacos',
    'guzzle_config' => [
        'headers' => [
            'charset' => 'UTF-8',
        ],
    ],
]));

$response = $application->auth->login('nacos', 'nacos');
$result = Json::decode((string) $response->getBody());

$response = $application->config->get('hyperf-service-config', 'DEFAULT_GROUP');
$result = Json::decode((string) $response->getBody());

nacos's People

Contributors

limingxinleo avatar huangzhhui avatar huangdijia avatar tw2066 avatar zxyfaxcn avatar daodao97 avatar elrond-g avatar ganymedenil avatar ulyssesyi avatar pmw1014 avatar crayxn avatar gaichao168 avatar luxin88 avatar sunsgneayo avatar sy-records avatar

Stargazers

Yili He avatar  avatar Roog avatar Cloudflying avatar wosiwo avatar Hong avatar  avatar 张志诚 avatar yboker avatar  avatar CHurricane avatar Aoseala avatar Mr Torn avatar  avatar peng avatar  avatar  avatar herder wu avatar  avatar kong avatar mogu avatar Adam Ou-Yang avatar

Watchers

James Cloos avatar  avatar  avatar  avatar  avatar  avatar

nacos's Issues

获取当时实例文档缺失ConfigInterface $config

https://hyperf.wiki/2.0/#/zh-cn/nacos
文档说明获取当时实例:
$instance = new \Hyperf\Nacos\Instance();

看了Instance代码的实现,需要传ConfigInterface $config
`class Instance extends InstanceModel
{
public function __construct(ConfigInterface $config)
{
$client = $config->get('nacos.client', []);
if (! isset($client['service_name'])) {
throw new InvalidArgumentException('nacos.client.service_name is required');
}

    foreach ($client as $key => $val) {
        $key = Str::camel($key);
        if (property_exists($this, $key)) {
            $this->{$key} = $val;
        }
    }

    $this->ip = current(swoole_get_local_ip());
    $this->port = $config->get('server.servers.0.port');
}

}`

获取当前服务也是:
$service = new \Hyperf\Nacos\Service();

ConfigInterface $config好像传进去;可以更新一下文档吗?

not support to nacos version 2.0.x

n version 1.4.x,GET /nacos/v1/ns/service querying a not exist service , return status code 500. return message body caused: service api@@hyperf is not found!

But in version 2.0.x ,return status code 200 , return message body {"namespaceId":"67f9ce9b-c3d5-4dbb-acf8-308b6b0b928e","groupName":"api","name":"hyperf","protectThreshold":0.0,"metadata":{},"selector":{"type":"none"},"clusters":[]}

请支持能自定义nacos的服务消费者的IP

代码运行在k8s,两个不同的集群,nacos运行在其中一个。
现在代码往上注册的是局域网地址,导致nacos向一个集群不通。想把消费者改成一个特定的代理IP。

hyperf/service-governance-nacos/src/Listener/MainWorkerStartListener.php
image
现在是读swoole的IP地址集的第一个。例如上面的代码能从 配置文件中取,取不到再原样读。

php如何使服务负载均衡权重控制生效?

java服务是这样的:
实现在Nacos控制台上配置服务权重
Nacos默认是轮询。此时在控制台上修改服务的权重是无效的,仍然是轮询。

可以在消费者Consumer的代码上面加上:

ConsumerApplication.java

@bean
@scope(value = "prototype")
public IRule loadBalanceRule()
{
return new NacosRule();
}
这样就可以支持在控制台上手动配置权重了。
————————————————
版权声明:本文为CSDN博主「mxb1234567」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/mxb1234567/article/details/109532872

Nacos2 配置中心 grpc请求方式 无法更新配置

Hyperf\Nacos\GrpcClient

public function listen(): void
    {
        $request = new ConfigBatchListenRequest(true, array_values($this->configListenContexts));
        $response = $this->request($request);
        if ($response instanceof ConfigChangeBatchListenResponse) {
            $changedConfigs = $response->changedConfigs;
            foreach ($changedConfigs as $changedConfig) {
                $this->handleConfig($changedConfig->tenant, $changedConfig->group, $changedConfig->dataId);
            }
        }
    }

config_center.drivers.nacos.client.grpc.enable=true的情况下
上面代码,当Nacos配置修改后,$response->changedConfigs没有任何配置数据

服务如何调用?

注册中心为nacos,服务协议为dubbo,如何调用服务呢?php的相关怎么搜都没有,只有zookeeper的,求教。

Nacos2 配置中心 grpc请求方式 无法更新配置

Hyperf\Nacos\GrpcClient

public function listen(): void
    {
        $request = new ConfigBatchListenRequest(true, array_values($this->configListenContexts));
        $response = $this->request($request);
        if ($response instanceof ConfigChangeBatchListenResponse) {
            $changedConfigs = $response->changedConfigs;
            foreach ($changedConfigs as $changedConfig) {
                $this->handleConfig($changedConfig->tenant, $changedConfig->group, $changedConfig->dataId);
            }
        }
    }

config_center.drivers.nacos.client.grpc.enable=true的情况下
上面代码,当Nacos配置修改后,$response->changedConfigs没有任何配置数据

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.