java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Dubbo Nacos服务启动报错,返回unknown user

Dubbo+Nacos服务启动报错,返回unknown user的问题

作者:普通网友

这篇文章主要介绍了Dubbo+Nacos服务启动报错,返回unknown user的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

1、由于开启了nacos的安全认证

修改了nacos的application.properties

nacos.core.auth.enabled=true

2、错误信息

如下:

Caused by: com.alibaba.nacos.api.exception.NacosException: Request nacos server failed: 
    at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:279) ~[nacos-client-2.0.3.jar:na]
    at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.doRegisterService(NamingGrpcClientProxy.java:129) ~[nacos-client-2.0.3.jar:na]
    at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.registerService(NamingGrpcClientProxy.java:115) ~[nacos-client-2.0.3.jar:na]
    at com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate.registerService(NamingClientProxyDelegate.java:95) ~[nacos-client-2.0.3.jar:na]
    at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:145) ~[nacos-client-2.0.3.jar:na]
    at org.apache.dubbo.registry.nacos.NacosNamingServiceWrapper.registerInstance(NacosNamingServiceWrapper.java:57) ~[dubbo-3.0.2.1.jar:3.0.2.1]
    at org.apache.dubbo.registry.nacos.NacosRegistry.doRegister(NacosRegistry.java:170) ~[dubbo-3.0.2.1.jar:3.0.2.1]
    ... 42 common frames omitted
Caused by: com.alibaba.nacos.api.exception.NacosException: unknown user!
    at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:271) ~[nacos-client-2.0.3.jar:na]
    ... 48 common frames omitted

3、pom.xml 依赖配置

如下:

<properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.3.6.RELEASE</spring-boot.version>
        <dubbo.version>3.0.2.1</dubbo.version>
        <nacos.version>2.0.3</nacos.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <!-- spring boot 2.3.2.RELEASE -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
	<dependencies>
        <!-- spring boot 集成 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- dubbo spring boot 集成 -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>${dubbo.version}</version>
        </dependency>
        <!-- dubbo nacos 集成 -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-registry-nacos</artifactId>
            <version>${dubbo.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.nacos</groupId>
            <artifactId>nacos-client</artifactId>
            <version>${nacos.version}</version>
        </dependency>
    </dependencies>

4、application.yml 配置内容

如下:

spring:
  application:
    name: dubbo-demo-provider
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss
dubbo:
  application:
    name: dubbo-demo-provider
    # 禁用QOS同一台机器可能会有端口冲突现象
    qos-enable: false
    qos-accept-foreign-ip: false
  scan:
    # 配置接口扫描包
    base-packages: tm.ucp.service
  protocol:
    # 协议类型
    name: dubbo
    port: 8888
  registry:
    protocol: dubbo
    address: nacos://localhost:8848?username=${username}&password=${password}
    timeout: 3000
    # 默认【public】 配置 namespace
    parameters:
      namespace: eec62008-6264-4e6e-aee8-bebb1c26a8ab

解决方法

由于dubbo的源码中发现 username、paasword并没有实际用到,

而在 RegistryConfig 类中发现 address属性值中,对username、password值进行了处理

故采用如下方法进行配置

dubbo:
  registry:
     address: nacos://localhost:8848?username=${username}&password=${password}

配置文件参考:

https://github.com/apache/dubbo-spring-boot-project/tree/master/dubbo-spring-boot-samples/registry-samples

https://github.com/apache/dubbo/issues/5956

至此已成功解决~

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文