haoxiaolan 2025-01-19 16:07 采纳率: 35.3%
浏览 27

dubbo微服务注册nacos发生错误

dubbo

img

两个微服务注册到nacos 只有一个

img

服务1 (成功注册到nacos)

@DubboService
public class MytesttempServiceImpl implements MytesttempService{
    @Override
    public User getUser() {
        User user = new User();
        user.setName("zs");
        return user;
    }
}
server:
  port: 80
dubbo:
  registry:
    address: nacos://127.0.0.1:8848
    #parameters:
    #  username: nacos
    #  password: nacos
    register: true
    # This will enable application-level service discovery only (the recommended service discovery method for Dubbo3).
    # For users upgrading from Dubbo2.x, please set the value to 'all' for smooth migration.
    register-mode: instance
  protocol:
    name: tri
    port: 50050
  application:
    name: dubbo-provider
    qos-enable: true
    qos-port: 22222
    #qos-accept-foreign-ip: false

服务2 (没有成功注册到nacos)


@RestController
public class controller {

    @DubboReference
    private MytesttempService mytesttempService;

    @GetMapping("/test")
    public User getUser(){
        User user = mytesttempService.getUser();
        System.out.println(user);
        return user;
    }
}
server:
  port: 81
dubbo:
  registry:
    address: nacos://127.0.0.1:8848
    #parameters:
    #  username: nacos
    #  password: nacos
    register: true
    # This will enable application-level service discovery only (the recommended service discovery method for Dubbo3).
    # For users upgrading from Dubbo2.x, please set the value to 'all' for smooth migration.
    register-mode: instance
  protocol:
    name: tri
    port: 50051
  application:
    name: dubbo-consumer
    qos-enable: true
    qos-port: 22221
    #qos-accept-foreign-ip: false

调用controller接口,就报错了?怎么解决呀?这是什么原因

  • 写回答

2条回答 默认 最新

  • 关注

    以下回复参考:皆我百晓生券券喵儿等免费微信小程序作答:

    根据您提供的信息,我看到您在配置Dubbo服务提供者(provider)和消费者(consumer)时使用了Nacos作为注册中心,但在调用controller接口时遇到了错误。为了解决这个问题,我们需要考虑以下几个方面:

    1. 服务注册问题: 确保服务提供者(dubbo-provider)已经成功注册到Nacos注册中心。检查Nacos控制台中的服务列表,确认服务提供者是否已经注册并显示在服务列表中。

    2. 服务消费者配置问题: 检查服务消费者(dubbo-consumer)的配置,确保它能够正确订阅服务提供者的服务。检查消费者的@DubboReference注解是否正确引用了服务提供者的服务接口。

    3. 网络连接问题: 确认服务提供者和消费者之间的网络连接是否正常。确保服务提供者的IP和端口配置正确,并且消费者能够访问到服务提供者。

    4. 服务版本和分组问题: 检查服务提供者和消费者使用的服务版本和分组是否一致。在Dubbo中,服务版本和分组是区分服务的标识之一,如果提供者和消费者使用的版本或分组不一致,可能会导致调用失败。

    5. Nacos配置问题: 确认Nacos注册中心的配置是否正确。检查Nacos的地址、用户名和密码(如果需要的话)是否正确配置在Dubbo的配置文件中。此外,确认Nacos是否开启了鉴权功能,如果有的话,确保Dubbo的配置中也包含了正确的鉴权信息。

    为了更好地帮助您解决问题,我需要更详细的错误信息或日志输出。请提供调用controller接口时出现的错误日志或异常堆栈信息,这样我可以更准确地判断问题的原因并给出解决方案。同时,确保您的Dubbo和Nacos版本是兼容的,避免因为版本不匹配导致的问题。

    评论

报告相同问题?

问题事件

  • 创建了问题 1月19日