[apache/dubbo]三重反对应用程序地址

2024-07-02 930 views
0
环境
  • Dubbo 版本:3.x
  • 操作系统版本:Ubuntu 18.04.5
  • Java 版本:11
  • nacos版本:1.4.2
重现此问题的步骤
  1. 提供者配置
    dubbo:
    application:
    metadata-type: remote
    register-mode: instance
    registry:
    address: nacos://${nacos.host}:${nacos.port}
    protocol:
    name: tri
    serialization: protobuf
  2. 消费者配置
    dubbo:
    application:
    metadata-type: remote
    service-discovery:
      migration: APPLICATION_FIRST
    registry:
    address: nacos://${nacos.host}:${nacos.port}
    #    ?registry-type=${nacos.registry-type}
    protocol:
    name: tri
    serialization: protobuf

请提供[GitHub 地址]以重现此问题。

预期结果

图像

实际结果

图像

如果有异常,请附上异常跟踪:

java.lang.IllegalStateException: 无法检查服务 service.HelloService 的状态。url dubbo:// 中没有可用于服务 service.HelloService 的提供程序

回答

7

Nacos 版本需要升级到 2.0.0 或以上才能支持服务发现模型。(受 Nacos 限制)

3

使用2.0.2nacos也不行,dubbo协议可以,tri无法找到provider

5

@feng996 您能否提供一个 demo 来帮助我们确认这个问题的存在?

8

我已经重现了这个问题,并且问题可以更具体一些:Triple 协议在与 Dubbo 集成的 Spring 上不起作用。

出了点问题dubbo-spring-boot-starter,我会尽力修复它。

3

@feng996 我找到了问题的原因,它与dubbo-spring-boot-starter我最初想的并不相关。

来源在org.apache.dubbo.config.metadata.ServiceInstanceHostPortCustomizer,我们来看一下:

@Override
public void customize(ServiceInstance serviceInstance) {
    String host = null;
    int port = -1;
    // ......
    Set<URL> urls = writableMetadataService.getExportedServiceURLs();
    if (CollectionUtils.isNotEmpty(urls)) {
        ApplicationModel applicationModel = serviceInstance.getApplicationModel();
        String preferredProtocol = applicationModel.getCurrentConfig().getProtocol();
        //  The default value of preferredProtocol is dubbo.
        if (preferredProtocol != null) {
            for (URL exportedURL : urls) {
                // The protocol of exportedURL is tri
                // because of tri != dubbo, the host and port will not be assigned values.
                if (preferredProtocol.equals(exportedURL.getProtocol())) {
                    host = exportedURL.getHost();
                    port = exportedURL.getPort();
                    break;
                }
            }
        } else {
            URL url = urls.iterator().next();
            host = url.getHost();
            port = url.getPort();
        }
        // If not the port of instace > 0, the application instance will not be registered to RegistryCenter(like Nacos, Zookeeper).
        // As a result, the consumer can't find the avaliabe providers when our settging is registry-mode=instance
        if (serviceInstance instanceof DefaultServiceInstance) {
            DefaultServiceInstance instance = (DefaultServiceInstance) serviceInstance;
            instance.setHost(host);
            instance.setPort(port);
        }
    }
}

目前,如果希望消费者和提供者都强制使用Application Discovery三重协议,只需更改提供者的一行配置,如下所示:

dubbo:
  application:
    metadata-type: remote
    register-mode: instance
    protocol: tri  <==== HERE, set preferredProtocol as tri

但是,Dubbo 官方为了进一步推广还需要做两件事:

  1. 尽快完成文档:三方协议迁移指南
  2. preferredProtocol 的逻辑不够人性化,可能需要优化一下。

与 #8666 相关

7

添加 dubbo.application.protocol=tri 3.0.4 消费者参考 仍然会报没有提供商 .... demo放在 #8987 回复里了

8

使用注解引用时,再次指定protocol=tri,解决 @DubboReference(providedBy = "feedback-provider", check = false, protocol = "tri") private HelloService helloService;

看起来是provider配置里services key 为interface:protocol的原因(“com.example.feedback.api.service.HelloService:tri”)。但是不知道为什么在注解引用时,并没有把dubbo.protocol.name=tri这个信息加到后面,反向reference里再次指定