Skip to content

Conversation

@limit81995
Copy link
Contributor

@limit81995 limit81995 commented Jul 25, 2025

Fixes #7461

适配高版本,修复在使用高版本时,请求api后,会提示接口弃用,导致请求处理成功了,但是在终端提示了error内容。
如果使用了nacos2.0及以上的版本时,可以在config/autoload/services.php 文件下,drivers.nacos.version 填写字符串"2","3"
例如:

<?php
return [
    // 此处省略了其它同层级的配置
    'consumers' => value(function () {
        $consumers = [];
        $services = [];
        foreach ($services as $name => $interface) {
            $consumers[] = [
                "name" => $name,
                "service" => $interface,
                "id" => $interface,
                "protocol" => "jsonrpc",
                'registry' => [
                    'protocol' => 'nacos',
                    'address' =>  "http://" . env("NACOS_HOST", "127.0.0.1") . ":" . env("NACOS_PORT", "8848"),
                ],
                //registry和nodes 二选一即可
//                'nodes' => [
//                    ["host" => "127.0.0.1", "port" => 9602]
//                ]
            ];
        }
        return $consumers;
    }),
    'drivers' => [
        'nacos' => [
            'host' => env("NACOS_HOST", "127.0.0.1"),
            'port' => env("NACOS_PORT", "8848"),
            'username' => env("NACOS_USERNAME", "nacos"),
            'password' => env("NACOS_PASSWORD", "nacos"),
            'guzzle' => [
                'config' => null,
            ],
            'group_name' => env("NACOS_GROUP_NAME", "DEFAULT_GROUP"),
            'namespace_id' => env("NACOS_NAMESPACE", "public"),
            'heartbeat' => 5,
            'version' => "3"
        ],
    ],
];

可以参考例子上的drivers.nacos.version填写。如果不填写默认使用nacos v1的openapi

这个分支只是增加了v2和v3版本的内容,可以根据具体情况抽离interface增加ide提示。(nacos官方说到过,以后会更加规范openapi和grpc 这两个方式来使用。)

@limingxinleo limingxinleo changed the title fix:适配高版本,修复在使用高版本时,请求api后,会提示接口弃用,导致请求处理成功了,但是在终端提示了error内容。 Support versions v2 and v3 for nacos sdk. Sep 3, 2025
@limingxinleo limingxinleo merged commit 5465fed into hyperf:master Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] 期望支持nacos 3.0版本及以上。目前差的版本时间太久。

2 participants