You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/09/06 13:55:49 UTC

[GitHub] [dubbo] plusmancn removed a comment on issue #8666: [3.0] The problem collection of Triple with ApplicationDiscovery

plusmancn removed a comment on issue #8666:
URL: https://github.com/apache/dubbo/issues/8666#issuecomment-913655259


   ## The logic of preferredProtocol was not user-friendly, we maybe should optimize it.
   
   ### What's the problem?
   When we only use the `triple` protocol in dubbo with setting provider's register-mode as `instance`, the consumer can't find the service.
   
   
   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
   ```
   
   
   
   
   ### The possible solution
   change the default `application-protocol` as `TRIPLE` in the future
   > Why not now? Because most users are still trying to migrate from 2.0 to 3.0
   
   ```java
   // => org.apache.dubbo.config.ApplicationConfig#checkDefault
   protected void checkDefault() {
       super.checkDefault();
       if (protocol == null) {
           protocol = DUBBO;   // <======= HERE
       }
       // ......
   }
   ```
   In `ServiceInstanceHostPortCustomizer`, If the default protocol not exists, just try to get the first protocol and log an error log.
   


-- 
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-unsubscribe@dubbo.apache.org

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



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