apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.5k stars 26.43k forks source link

triple不支持应用级地址发现 #8599

Closed feng996 closed 3 years ago

feng996 commented 3 years ago

Environment

Steps to reproduce this issue

  1. provider配置
    dubbo:
    application:
    metadata-type: remote
    register-mode: instance
    registry:
    address: nacos://${nacos.host}:${nacos.port}
    protocol:
    name: tri
    serialization: protobuf
  2. consumer配置
    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

Pls. provide [GitHub address] to reproduce this issue.

Expected Result

image

Actual Result

image

If there is an exception, please attach the exception trace:

java.lang.IllegalStateException: Failed to check the status of the service service.HelloService. No provider available for the service service.HelloService from the url dubbo://

AlbumenJ commented 3 years ago

Nacos version should upgrade to 2.0.0 or above to support service discovery model. (This is limited by Nacos)

feng996 commented 3 years ago

Nacos version should upgrade to 2.0.0 or above to support service discovery model. (This is limited by Nacos)

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

plusmancn commented 3 years ago

@feng996 Can you provide a demo to help us confirming this question exists?

plusmancn commented 3 years ago

I have reproduced this problem, and the problem can be more specific: The Triple protocol is not working on Spring integrated with Dubbo.

There is something wrong with dubbo-spring-boot-starter, I will try to fix it.

plusmancn commented 3 years ago

@feng996 I have found the cause of the problem which is not related to dubbo-spring-boot-starter as I first thought.

The source is in org.apache.dubbo.config.metadata.ServiceInstanceHostPortCustomizer, let's have a look:

@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);
        }
    }
}

For the moment, if you want both consumer and provider to force using Application Discovery in tri protocol, just change one line config of provider as follows:

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

But, Dubbo official also needs to do two things for further promotion:

  1. Complete the docs: Triple协议迁移指南 as soon as possible
  2. The logic of preferredProtocol was not user-friendly, we maybe should optimize it.

Relate to #8666

feng996 commented 2 years ago

添加 dubbo.application.protocol=tri 3.0.4 consumer reference 还是会报no provider .... demo放在 #8987 回复里了

feng996 commented 2 years ago

添加 dubbo.application.protocol=tri 3.0.4 consumer reference 还是会报no provider .... demo放在 #8987 回复里了

使用注解引用时,再次指定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里再次指定