plusmancn edited a comment on issue #8599:
URL: https://github.com/apache/dubbo/issues/8599#issuecomment-912218330


   @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:
   ```java
   @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:
   ```yaml
   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协议迁移指南](https://dubbo.apache.org/zh/docs/migration/migration-triple/) as 
soon as possible
   2. The logic of preferredProtocol was not user-friendly, we maybe should 
optimize it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to