This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git

commit f4eed67640f15d9908fe914b9bf3fc37e43a5714
Author: liubao <bi...@qq.com>
AuthorDate: Thu May 28 14:49:59 2020 +0800

    [SCB-1650]discovery schema from instancies directly
---
 .../servicecomb/demo/registry/IServerEndpoint.java |  22 +++
 .../demo/registry/SchemaDiscoveryTestCase.java     |  50 +++++++
 .../src/main/resources/registry.yaml               |   9 ++
 demo/demo-multi-registries/pom.xml                 |   4 +
 .../demo/CategorizedTestCaseRunner.java            |  27 ++--
 dependencies/bom/pom.xml                           |   5 +
 .../registry/consumer/MicroserviceManager.java     |  26 +++-
 service-registry/pom.xml                           |   1 +
 service-registry/registry-local/pom.xml            |   2 +-
 .../localregistry/LocalRegistryStore.java          |  81 ++++++++---
 .../pom.xml                                        |  33 +----
 .../schemadiscovery/SchemaDiscovery.java           | 154 +++++++++++++++++++++
 .../schemadiscovery/SchemaDiscoveryEndpoint.java   |  37 +++++
 .../schemadiscovery/SchemaDiscoveryService.java    |  26 ++++
 .../org.apache.servicecomb.registry.api.Discovery  |  18 +++
 .../src/main/resources/microservice.yaml           |  14 +-
 service-registry/registry-service-center/pom.xml   |   2 +-
 .../registry/AbstractServiceRegistry.java          |   1 +
 service-registry/registry-zero-config/pom.xml      |   2 +-
 19 files changed, 441 insertions(+), 73 deletions(-)

diff --git 
a/demo/demo-multi-registries/demo-multi-registries-client/src/main/java/org/apache/servicecomb/demo/registry/IServerEndpoint.java
 
b/demo/demo-multi-registries/demo-multi-registries-client/src/main/java/org/apache/servicecomb/demo/registry/IServerEndpoint.java
new file mode 100644
index 0000000..4d38e9e
--- /dev/null
+++ 
b/demo/demo-multi-registries/demo-multi-registries-client/src/main/java/org/apache/servicecomb/demo/registry/IServerEndpoint.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.demo.registry;
+
+public interface IServerEndpoint {
+  public String getName(String name);
+}
diff --git 
a/demo/demo-multi-registries/demo-multi-registries-client/src/main/java/org/apache/servicecomb/demo/registry/SchemaDiscoveryTestCase.java
 
b/demo/demo-multi-registries/demo-multi-registries-client/src/main/java/org/apache/servicecomb/demo/registry/SchemaDiscoveryTestCase.java
new file mode 100644
index 0000000..3ed4c1a
--- /dev/null
+++ 
b/demo/demo-multi-registries/demo-multi-registries-client/src/main/java/org/apache/servicecomb/demo/registry/SchemaDiscoveryTestCase.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.demo.registry;
+
+import org.apache.servicecomb.demo.CategorizedTestCase;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.provider.pojo.RpcReference;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SchemaDiscoveryTestCase implements CategorizedTestCase {
+  @RpcReference(microserviceName = "thirdParty-no-schema-server", schemaId = 
"ServerEndpoint")
+  IServerEndpoint serverEndpoint;
+
+  @Override
+  public void testRestTransport() throws Exception {
+    // invoke thirdParty-no-schema-server(mocked by 
demo-multi-registries-server)
+    TestMgr.check("hello", serverEndpoint.getName("hello"));
+  }
+
+  @Override
+  public void testHighwayTransport() throws Exception {
+
+  }
+
+  @Override
+  public void testAllTransport() throws Exception {
+
+  }
+
+  @Override
+  public String getMicroserviceName() {
+    return "thirdParty-service-center";
+  }
+}
diff --git 
a/demo/demo-multi-registries/demo-multi-registries-client/src/main/resources/registry.yaml
 
b/demo/demo-multi-registries/demo-multi-registries-client/src/main/resources/registry.yaml
index 00d4588..3bc2c1e 100644
--- 
a/demo/demo-multi-registries/demo-multi-registries-client/src/main/resources/registry.yaml
+++ 
b/demo/demo-multi-registries/demo-multi-registries-client/src/main/resources/registry.yaml
@@ -24,3 +24,12 @@ thirdParty-service-center:
     instances:
       - endpoints:
           - rest://localhost:30100
+thirdParty-no-schema-server:
+  - id: "002"
+    version: "4.0.0"
+    appid: demo-multi-registries
+    schemaIds:
+      - ServerEndpoint # not in local , discovery from 
demo-multi-registries-server
+    instances:
+      - endpoints:
+          - rest://localhost:8080 # actually will invoke to 
demo-multi-registries-server
\ No newline at end of file
diff --git a/demo/demo-multi-registries/pom.xml 
b/demo/demo-multi-registries/pom.xml
index d238442..e8886db 100644
--- a/demo/demo-multi-registries/pom.xml
+++ b/demo/demo-multi-registries/pom.xml
@@ -43,6 +43,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.servicecomb</groupId>
+      <artifactId>registry-schema-discovery</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
       <artifactId>registry-service-center</artifactId>
     </dependency>
     <dependency>
diff --git 
a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCaseRunner.java
 
b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCaseRunner.java
index 20424df..8f92c1d 100644
--- 
a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCaseRunner.java
+++ 
b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/CategorizedTestCaseRunner.java
@@ -28,17 +28,24 @@ public class CategorizedTestCaseRunner {
     for (String transport : DemoConst.transports) {
       for (CategorizedTestCase testCase : tests.values()) {
 
-        if (testCase.getMicroserviceName() != null) {
-          changeTransport(testCase.getMicroserviceName(), transport);
-        } else {
-          changeTransport(microserviceName, transport);
-        }
+        try {
+          if (testCase.getMicroserviceName() != null) {
+            changeTransport(testCase.getMicroserviceName(), transport);
+          } else {
+            changeTransport(microserviceName, transport);
+          }
 
-        testCase.testAllTransport();
-        if ("rest".equals(transport)) {
-          testCase.testRestTransport();
-        } else if ("highway".equals(transport)) {
-          testCase.testHighwayTransport();
+          testCase.testAllTransport();
+          if ("rest".equals(transport)) {
+            testCase.testRestTransport();
+          } else if ("highway".equals(transport)) {
+            testCase.testHighwayTransport();
+          }
+        } catch (Exception e) {
+          TestMgr.failed("run categorized test case " +
+                  testCase.getClass().getName() +
+                  " failed, reason " + e.getMessage(),
+              e);
         }
       }
     }
diff --git a/dependencies/bom/pom.xml b/dependencies/bom/pom.xml
index 9780df5..7b39a5b 100644
--- a/dependencies/bom/pom.xml
+++ b/dependencies/bom/pom.xml
@@ -252,6 +252,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.servicecomb</groupId>
+        <artifactId>registry-schema-discovery</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.servicecomb</groupId>
         <artifactId>registry-service-center</artifactId>
         <version>${project.version}</version>
       </dependency>
diff --git 
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java
 
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java
index 5523c9f..c4636d9 100644
--- 
a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java
+++ 
b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java
@@ -17,9 +17,9 @@
 
 package org.apache.servicecomb.registry.consumer;
 
+import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
 import 
org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent;
 import org.apache.servicecomb.registry.api.event.task.SafeModeChangeEvent;
 import org.slf4j.Logger;
@@ -33,7 +33,9 @@ public class MicroserviceManager {
   private String appId;
 
   // key: microserviceName
-  private Map<String, MicroserviceVersions> versionsByName = new 
ConcurrentHashMapEx<>();
+  private Map<String, MicroserviceVersions> versionsByName = new HashMap<>();
+
+  private Object lock = new Object();
 
   public MicroserviceManager(AppManager appManager, String appId) {
     this.appManager = appManager;
@@ -45,11 +47,21 @@ public class MicroserviceManager {
   }
 
   public MicroserviceVersions getOrCreateMicroserviceVersions(String 
microserviceName) {
-    MicroserviceVersions microserviceVersions = 
versionsByName.computeIfAbsent(microserviceName, name -> {
-      MicroserviceVersions instance = new MicroserviceVersions(appManager, 
appId, microserviceName);
-      instance.pullInstances();
-      return instance;
-    });
+    // do not use ConcurrentHashMap computeIfAbsent for versionsByName
+    // because: when create MicroserviceVersions, one creation may depend on 
another
+    // MicroserviceVersions. And pullInstances will create a new 
MicroserviceVersions.
+    // Calling ConcurrentHashMap computeIfAbsent inside will get deadlock.
+    MicroserviceVersions microserviceVersions = 
versionsByName.get(microserviceName);
+    if (microserviceVersions == null) {
+      synchronized (lock) {
+        microserviceVersions = versionsByName.get(microserviceName);
+        if (microserviceVersions == null) {
+          microserviceVersions = new MicroserviceVersions(appManager, appId, 
microserviceName);
+          versionsByName.put(microserviceName, microserviceVersions);
+          microserviceVersions.pullInstances();
+        }
+      }
+    }
 
     tryRemoveInvalidMicroservice(microserviceVersions);
 
diff --git a/service-registry/pom.xml b/service-registry/pom.xml
index 488f81a..9013cf0 100644
--- a/service-registry/pom.xml
+++ b/service-registry/pom.xml
@@ -34,5 +34,6 @@
     <module>registry-service-center</module>
     <module>registry-local</module>
     <module>registry-zero-config</module>
+    <module>registry-schema-discovery</module>
   </modules>
 </project>
diff --git a/service-registry/registry-local/pom.xml 
b/service-registry/registry-local/pom.xml
index e5a7a3b..318a9b7 100644
--- a/service-registry/registry-local/pom.xml
+++ b/service-registry/registry-local/pom.xml
@@ -26,7 +26,7 @@
   <modelVersion>4.0.0</modelVersion>
 
   <artifactId>registry-local</artifactId>
-  <name>Java Chassis::Registry Service Center</name>
+  <name>Java Chassis::Java Chassis::Service Registry::Local</name>
 
   <dependencies>
     <dependency>
diff --git 
a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistryStore.java
 
b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistryStore.java
index 8cf53eb..9d60e31 100644
--- 
a/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistryStore.java
+++ 
b/service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistryStore.java
@@ -19,8 +19,11 @@ package org.apache.servicecomb.localregistry;
 
 import static 
org.apache.servicecomb.registry.definition.DefinitionConst.DEFAULT_APPLICATION_ID;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -29,17 +32,21 @@ import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.servicecomb.config.ConfigUtil;
 import org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader;
+import org.apache.servicecomb.foundation.common.base.ServiceCombConstants;
+import org.apache.servicecomb.foundation.common.utils.JvmUtils;
+import org.apache.servicecomb.registry.api.registry.FindInstancesResponse;
 import org.apache.servicecomb.registry.api.registry.Microservice;
 import org.apache.servicecomb.registry.api.registry.MicroserviceFactory;
 import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
-import org.apache.servicecomb.registry.api.registry.FindInstancesResponse;
 import org.apache.servicecomb.registry.api.registry.MicroserviceInstances;
 import org.apache.servicecomb.registry.definition.MicroserviceDefinition;
 import org.yaml.snakeyaml.Yaml;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.netflix.config.DynamicPropertyFactory;
 
 public class LocalRegistryStore {
   private static final String REGISTRY_FILE_NAME = "registry.yaml";
@@ -83,9 +90,28 @@ public class LocalRegistryStore {
     selfMicroserviceInstance.setInstanceId(selfMicroservice.getServiceId());
     selfMicroserviceInstance.setServiceId(selfMicroservice.getServiceId());
 
-    InputStream is = 
this.getClass().getClassLoader().getResourceAsStream(REGISTRY_FILE_NAME);
-    if (is != null) {
-      initFromData(is);
+    InputStream is = null;
+
+    try {
+      ClassLoader loader = JvmUtils.findClassLoader();
+      Enumeration<URL> urls = loader.getResources(REGISTRY_FILE_NAME);
+      while (urls.hasMoreElements()) {
+        URL url = urls.nextElement();
+        is = url.openStream();
+        if (is != null) {
+          initFromData(is);
+        }
+      }
+    } catch (IOException e) {
+      throw new IllegalStateException(e);
+    } finally {
+      if (is != null) {
+        try {
+          is.close();
+        } catch (IOException e) {
+          // nothing to do
+        }
+      }
     }
 
     addSelf();
@@ -130,7 +156,7 @@ public class LocalRegistryStore {
         List<String> schemas = (List<String>) serviceConfig.get("schemaIds");
 
         Microservice microservice = new Microservice();
-        microservice.setAppId(appId == null ? DEFAULT_APPLICATION_ID : appId);
+        microservice.setAppId(validAppId(appId));
         microservice.setServiceName(name);
         microservice.setVersion(version);
         microservice.setServiceId(serviceId == null ? 
UUID.randomUUID().toString() : serviceId);
@@ -139,20 +165,41 @@ public class LocalRegistryStore {
           microservice.setSchemas(schemas);
         }
 
-        Map<String, MicroserviceInstance> instanceMap = new 
ConcurrentHashMap<>();
-        for (Map<String, Object> instanceConfig : instancesConfig) {
-          @SuppressWarnings("unchecked")
-          List<String> endpoints = (List<String>) 
instanceConfig.get("endpoints");
+        addInstances(instancesConfig, microservice);
+      }
+    }
+  }
 
-          MicroserviceInstance instance = new MicroserviceInstance();
-          instance.setInstanceId(UUID.randomUUID().toString());
-          instance.setEndpoints(endpoints);
-          instance.setServiceId(microservice.getServiceId());
+  private String validAppId(String configAppId) {
+    if (!StringUtils.isEmpty(configAppId)) {
+      return configAppId;
+    }
+    if (DynamicPropertyFactory.getInstance()
+        .getStringProperty(ServiceCombConstants.CONFIG_APPLICATION_ID_KEY, 
null).get() != null) {
+      return DynamicPropertyFactory.getInstance()
+          .getStringProperty(ServiceCombConstants.CONFIG_APPLICATION_ID_KEY, 
null).get();
+    }
+    return DEFAULT_APPLICATION_ID;
+  }
 
-          instanceMap.put(instance.getInstanceId(), instance);
-        }
-        microserviceInstanceMap.put(microservice.getServiceId(), instanceMap);
-      }
+  private void addInstances(List<Map<String, Object>> instancesConfig, 
Microservice microservice) {
+    Map<String, MicroserviceInstance> instanceMap = new ConcurrentHashMap<>();
+    microserviceInstanceMap.put(microservice.getServiceId(), instanceMap);
+
+    if (instancesConfig == null) {
+      return;
+    }
+
+    for (Map<String, Object> instanceConfig : instancesConfig) {
+      @SuppressWarnings("unchecked")
+      List<String> endpoints = (List<String>) instanceConfig.get("endpoints");
+
+      MicroserviceInstance instance = new MicroserviceInstance();
+      instance.setInstanceId(UUID.randomUUID().toString());
+      instance.setEndpoints(endpoints);
+      instance.setServiceId(microservice.getServiceId());
+
+      instanceMap.put(instance.getInstanceId(), instance);
     }
   }
 
diff --git a/service-registry/registry-local/pom.xml 
b/service-registry/registry-schema-discovery/pom.xml
similarity index 71%
copy from service-registry/registry-local/pom.xml
copy to service-registry/registry-schema-discovery/pom.xml
index e5a7a3b..9a85981 100644
--- a/service-registry/registry-local/pom.xml
+++ b/service-registry/registry-schema-discovery/pom.xml
@@ -25,48 +25,27 @@
   </parent>
   <modelVersion>4.0.0</modelVersion>
 
-  <artifactId>registry-local</artifactId>
-  <name>Java Chassis::Registry Service Center</name>
+  <artifactId>registry-schema-discovery</artifactId>
+  <name>Java Chassis::Service Registry::Schema Discovery</name>
 
   <dependencies>
     <dependency>
       <groupId>org.apache.servicecomb</groupId>
-      <artifactId>deployment</artifactId>
+      <artifactId>provider-jaxrs</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.servicecomb</groupId>
-      <artifactId>foundation-vertx</artifactId>
+      <artifactId>provider-pojo</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.servicecomb</groupId>
-      <artifactId>foundation-config</artifactId>
+      <artifactId>handler-loadbalance</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.servicecomb</groupId>
-      <artifactId>foundation-common</artifactId>
+      <artifactId>registry-local</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.servicecomb</groupId>
-      <artifactId>swagger-generator-core</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.apache.servicecomb</groupId>
-      <artifactId>foundation-registry</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>io.vertx</groupId>
-      <artifactId>vertx-codegen</artifactId>
-      <scope>provided</scope>
-    </dependency>
-
-    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
       <scope>test</scope>
diff --git 
a/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscovery.java
 
b/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscovery.java
new file mode 100644
index 0000000..e6f9bad
--- /dev/null
+++ 
b/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscovery.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.schemadiscovery;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.servicecomb.foundation.common.base.ServiceCombConstants;
+import org.apache.servicecomb.loadbalance.LoadbalanceHandler;
+import org.apache.servicecomb.provider.pojo.Invoker;
+import org.apache.servicecomb.registry.api.Discovery;
+import org.apache.servicecomb.registry.api.registry.Microservice;
+import org.apache.servicecomb.registry.api.registry.MicroserviceInstance;
+import org.apache.servicecomb.registry.api.registry.MicroserviceInstances;
+import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.netflix.config.DynamicPropertyFactory;
+
+public class SchemaDiscovery implements Discovery {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(SchemaDiscovery.class);
+
+  public static final String NAME = "schema discovery";
+
+  public static final String ENABLED = 
"servicecomb.schema.registry.discovery.enabled";
+
+  private SchemaDiscoveryService schemaDiscoveryService = null;
+
+  @Override
+  public Microservice getMicroservice(String microserviceId) {
+    return null;
+  }
+
+  @Override
+  public String getSchema(String microserviceId, 
Collection<MicroserviceInstance> instances, String schemaId) {
+    if (instances == null || instances.isEmpty()) {
+      return null;
+    }
+
+    for (MicroserviceInstance instance : instances) {
+      if (!microserviceId.equals(instance.getServiceId())) {
+        // ensure the same version
+        continue;
+      }
+
+      List<String> endpoints = instance.getEndpoints();
+      if (endpoints == null || endpoints.isEmpty()) {
+        continue;
+      }
+
+      for (String endpoint : endpoints) {
+        InvocationContext invocationContext = new InvocationContext();
+        
invocationContext.addLocalContext(LoadbalanceHandler.SERVICECOMB_SERVER_ENDPOINT,
 endpoint);
+        SchemaDiscoveryService schemaDiscoveryService = 
getOrCreateSchemaDiscoveryService();
+        try {
+          String schema = schemaDiscoveryService.getSchema(invocationContext, 
schemaId);
+          if (!StringUtils.isEmpty(schema)) {
+            return schema;
+          }
+        } catch (Exception e) {
+          LOGGER.warn("failed query schema from endpoint {}, msg {}", 
endpoint, e.getMessage());
+          continue;
+        }
+      }
+    }
+
+    return null;
+  }
+
+  private SchemaDiscoveryService getOrCreateSchemaDiscoveryService() {
+    if (this.schemaDiscoveryService == null) {
+      // For schema discovery, assume all instances of different microservices
+      // are instances of this microservice.
+      String serviceName = DynamicPropertyFactory.getInstance()
+          
.getStringProperty(ServiceCombConstants.CONFIG_QUALIFIED_MICROSERVICE_NAME_KEY,
+              ServiceCombConstants.DEFAULT_MICROSERVICE_NAME).get();
+
+      schemaDiscoveryService = Invoker
+          .createProxy(serviceName, SchemaDiscoveryService.SCHEMA_ID,
+              SchemaDiscoveryService.class);
+    }
+    return schemaDiscoveryService;
+  }
+
+  @Override
+  public MicroserviceInstance getMicroserviceInstance(String serviceId, String 
instanceId) {
+    return null;
+  }
+
+  @Override
+  public MicroserviceInstances findServiceInstances(String appId, String 
serviceName, String versionRule) {
+    MicroserviceInstances microserviceInstances = new MicroserviceInstances();
+    microserviceInstances.setMicroserviceNotExist(true);
+    return microserviceInstances;
+  }
+
+  @Override
+  public String getRevision() {
+    return null;
+  }
+
+  @Override
+  public void setRevision(String revision) {
+
+  }
+
+  @Override
+  public String name() {
+    return NAME;
+  }
+
+  @Override
+  public boolean enabled() {
+    return DynamicPropertyFactory.getInstance()
+        .getBooleanProperty(ENABLED, true).get();
+  }
+
+  @Override
+  public void init() {
+
+  }
+
+  @Override
+  public void run() {
+
+  }
+
+  @Override
+  public void destroy() {
+
+  }
+
+  @Override
+  public int getOrder() {
+    return 1000;
+  }
+}
diff --git 
a/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscoveryEndpoint.java
 
b/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscoveryEndpoint.java
new file mode 100644
index 0000000..c74f637
--- /dev/null
+++ 
b/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscoveryEndpoint.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.schemadiscovery;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.apache.servicecomb.registry.RegistrationManager;
+
+@RestSchema(schemaId = SchemaDiscoveryService.SCHEMA_ID)
+@Path("/v1/schema/discovery")
+@Produces(MediaType.APPLICATION_JSON)
+public class SchemaDiscoveryEndpoint {
+  @Path("/getSchema")
+  @GET
+  public String getSchema(String schemaId) {
+    return 
RegistrationManager.INSTANCE.getMicroservice().getSchemaMap().get(schemaId);
+  }
+}
diff --git 
a/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscoveryService.java
 
b/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscoveryService.java
new file mode 100644
index 0000000..a5d7c57
--- /dev/null
+++ 
b/service-registry/registry-schema-discovery/src/main/java/org/apache/servicecomb/schemadiscovery/SchemaDiscoveryService.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.schemadiscovery;
+
+import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+
+public interface SchemaDiscoveryService {
+  String SCHEMA_ID = "SchemaDiscoveryEndpoint";
+
+  String getSchema(InvocationContext context, String schemaId);
+}
diff --git 
a/service-registry/registry-schema-discovery/src/main/resources/META-INF/services/org.apache.servicecomb.registry.api.Discovery
 
b/service-registry/registry-schema-discovery/src/main/resources/META-INF/services/org.apache.servicecomb.registry.api.Discovery
new file mode 100644
index 0000000..949cd3c
--- /dev/null
+++ 
b/service-registry/registry-schema-discovery/src/main/resources/META-INF/services/org.apache.servicecomb.registry.api.Discovery
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.servicecomb.schemadiscovery.SchemaDiscovery
\ No newline at end of file
diff --git 
a/demo/demo-multi-registries/demo-multi-registries-client/src/main/resources/registry.yaml
 
b/service-registry/registry-schema-discovery/src/main/resources/microservice.yaml
similarity index 82%
copy from 
demo/demo-multi-registries/demo-multi-registries-client/src/main/resources/registry.yaml
copy to 
service-registry/registry-schema-discovery/src/main/resources/microservice.yaml
index 00d4588..0eefa9b 100644
--- 
a/demo/demo-multi-registries/demo-multi-registries-client/src/main/resources/registry.yaml
+++ 
b/service-registry/registry-schema-discovery/src/main/resources/microservice.yaml
@@ -14,13 +14,9 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
+servicecomb-config-order: -100
 
-thirdParty-service-center:
-  - id: "001"
-    version: "4.0.0"
-    appid: demo-multi-registries
-    schemaIds:
-      - ServiceCenterEndpoint
-    instances:
-      - endpoints:
-          - rest://localhost:30100
+servicecomb:
+  loadbalance:
+    userDefinedEndpoint:
+      enabled: true
\ No newline at end of file
diff --git a/service-registry/registry-service-center/pom.xml 
b/service-registry/registry-service-center/pom.xml
index 90afb8a..ec09190 100644
--- a/service-registry/registry-service-center/pom.xml
+++ b/service-registry/registry-service-center/pom.xml
@@ -26,7 +26,7 @@
   <modelVersion>4.0.0</modelVersion>
 
   <artifactId>registry-service-center</artifactId>
-  <name>Java Chassis::Registry Service Center</name>
+  <name>Java Chassis::Service Registry::Service Center</name>
 
   <dependencies>
     <dependency>
diff --git 
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
 
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
index e7232af..ffc17e7 100644
--- 
a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
+++ 
b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
@@ -263,6 +263,7 @@ public abstract class AbstractServiceRegistry implements 
ServiceRegistry {
 
   @Override
   // TODO: this is for 3rd party invocation, and a better way can be provided
+  // TODO:  microserviceManager.getVersionsByName() can not be used, will 
delete this in SCB-1949
   public void registerMicroserviceMapping(String microserviceName, String 
version,
       List<MicroserviceInstance> instances, Class<?> schemaIntfCls) {
     MicroserviceNameParser parser = new 
MicroserviceNameParser(microservice.getAppId(), microserviceName);
diff --git a/service-registry/registry-zero-config/pom.xml 
b/service-registry/registry-zero-config/pom.xml
index 20c656b..233d414 100644
--- a/service-registry/registry-zero-config/pom.xml
+++ b/service-registry/registry-zero-config/pom.xml
@@ -27,7 +27,7 @@
   <modelVersion>4.0.0</modelVersion>
 
   <artifactId>registry-zero-config</artifactId>
-  <name>Java Chassis::Registry Zero Config</name>
+  <name>Java Chassis::Service Registry::Zero Config</name>
 
   <dependencies>
     <dependency>

Reply via email to