You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/08/13 12:31:20 UTC

[dubbo] branch cloud-native updated (733473f -> 36e1a1c)

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

liujun pushed a change to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git.


    from 733473f  Merge branch 'cloud-native' of github.com:apache/incubator-dubbo into cloud-native
     new a12a539  add rest demo
     new e9a9e47  exclude injvm and registry protocol
     new 2eaa132  consul complement
     new 0c33f39  Merge branch 'cloud-native' of https://github.com/apache/dubbo into cloud-native
     new 705ee97  consul service discovery complement
     new eb62f48  Merge remote-tracking branch 'origin/cloud-native' into cloud-native
     new 591e45a  support old registry model and new registry model
     new a80f6fc  change demo
     new 9fdbad3  Merge branch 'cloud-native' of https://github.com/apache/dubbo into cloud-native
     new fd89c83  enhance supporting of multiple registries
     new 96786d8  demos
     new c8ca5b6  demos
     new 36e1a1c  Merge remote-tracking branch 'origin/cloud-native' into cloud-native

The 13 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 dubbo-bootstrap/pom.xml                            |  13 +-
 .../org/apache/dubbo/bootstrap/DubboBootstrap.java |   9 +-
 .../bootstrap/DubboServiceConsumerBootstrap.java   |  12 +-
 .../bootstrap/DubboServiceProvider2Bootstrap.java  |   6 +-
 .../bootstrap/DubboServiceProviderBootstrap.java   |  62 ++++++++--
 .../DubboInterfaceConsumerBootstrap.java}          |  27 +++--
 .../java/org/apache/dubbo/bootstrap/rest/User.java |  77 ++++++++++++
 .../apache/dubbo/bootstrap/rest/UserService.java   |  45 +++++++
 .../dubbo/bootstrap/rest/UserServiceImpl.java      |  32 +++++
 .../rpc/cluster/directory/AbstractDirectory.java   |   6 +-
 .../dubbo/common/constants/RegistryConstants.java  |   6 +-
 .../org/apache/dubbo/common/utils/UrlUtils.java    |   5 +
 .../dubbo/config/AbstractInterfaceConfig.java      |  17 ++-
 .../org/apache/dubbo/config/ReferenceConfig.java   |   6 +-
 .../dubbo/config/DubboConsumerBootstrap.java       |   2 +-
 .../dubbo/config/DubboProviderBootstrap.java       |   2 +-
 dubbo-demo/dubbo-call-sc&dubbo/README.md           |   7 ++
 .../consumer}/pom.xml                              |  27 ++---
 .../samples/microservices/sc/Application.java      |  56 +++++++++
 .../dubbo/samples/microservices/sc/rest/User.java  |  77 ++++++++++++
 .../samples/microservices/sc/rest/UserService.java |  45 +++++++
 .../microservices/sc/rest/UserServiceImpl.java     |  32 +++++
 .../consumer/src/main}/resources/log4j.properties  |   0
 .../pom.xml                                        |   6 +-
 dubbo-demo/dubbo-call-sc&dubbo/provider/pom.xml    |  83 +++++++++++++
 .../samples/microservices/sc/Application.java      |  15 +++
 .../configuration/RestTemplateConfiguration.java   |  16 +++
 .../microservices/sc/controller/MeController.java  |  23 ++++
 .../sc/controller/PropertyController.java          |  45 +++++++
 .../sc/controller/TestController.java              |  46 +++++++
 .../samples/microservices/sc/feign/TestFeign.java  |  13 ++
 .../provider/src/main/resources/application.yml    |   6 +
 .../provider/src/main/resources/bootstrap.yml      |  24 ++++
 dubbo-demo/dubbo-call-sc/README.md                 |   7 ++
 .../consumer}/pom.xml                              |  27 ++---
 .../samples/microservices/sc/Application.java      |  55 +++++++++
 .../dubbo/samples/microservices/sc/rest/User.java  |  77 ++++++++++++
 .../samples/microservices/sc/rest/UserService.java |  45 +++++++
 .../microservices/sc/rest/UserServiceImpl.java     |  32 +++++
 .../consumer/src/main}/resources/log4j.properties  |   0
 .../{dubbo-demo-api => dubbo-call-sc}/pom.xml      |   6 +-
 dubbo-demo/dubbo-call-sc/provider/pom.xml          |  83 +++++++++++++
 .../samples/microservices/sc/Application.java      |  15 +++
 .../configuration/RestTemplateConfiguration.java   |  16 +++
 .../microservices/sc/controller/MeController.java  |  23 ++++
 .../sc/controller/PropertyController.java          |  45 +++++++
 .../sc/controller/TestController.java              |  54 +++++++++
 .../samples/microservices/sc/controller/User.java  |  60 +++++++++
 .../samples/microservices/sc/feign/TestFeign.java  |  13 ++
 .../provider/src/main/resources/application.yml    |   6 +
 .../provider/src/main/resources/bootstrap.yml      |  24 ++++
 dubbo-demo/pom.xml                                 |   1 +
 dubbo-demo/sc-call-dubbo/consumer/pom.xml          |  84 +++++++++++++
 .../com/bettercloud/spring/cloud/Application.java  |  15 +++
 .../configuration/RestTemplateConfiguration.java   |  17 +++
 .../spring/cloud/controller/ClientController.java  |  29 +++++
 .../bettercloud/spring/cloud/feign/TestFeign.java  |  12 ++
 .../src/main/resources/application-holding.yml     |   3 +
 .../consumer/src/main/resources/application.yml    |   7 ++
 .../consumer/src/main/resources/bootstrap.yml      |  26 ++++
 .../{dubbo-demo-api => sc-call-dubbo}/pom.xml      |   6 +-
 .../provider}/pom.xml                              |  32 +----
 .../apache/dubbo/demo/provider/Application.java    |   0
 .../dubbo/demo/provider/DemoServiceImpl.java       |   0
 .../provider/src/main}/resources/log4j.properties  |   0
 .../dubbo/qos/protocol/QosProtocolWrapper.java     |   6 +-
 .../registry/integration/RegistryProtocol.java     |  32 ++---
 .../ServiceOrientedRegistry.java                   |   9 +-
 .../service/ServiceOrientedRegistryFactory.java}   |  18 +--
 .../service/ServiceOrientedRegistryProtocol.java   |  39 +++---
 .../registry/support/AbstractRegistryFactory.java  |   9 +-
 .../org.apache.dubbo.registry.RegistryFactory      |   1 +
 .../dubbo/internal/org.apache.dubbo.rpc.Protocol   |   3 +-
 .../support/ServiceOrientedRegistryTest.java       |   1 +
 .../registry/consul/ConsulServiceDiscovery.java    | 134 +++++++++++++++++++--
 ...e.dubbo.registry.client.ServiceDiscoveryFactory |   1 +
 .../dubbo/registry/dubbo/RegistryProtocolTest.java |  19 +--
 .../dubbo/rpc/protocol/ProtocolFilterWrapper.java  |   6 +-
 .../rpc/protocol/ProtocolListenerWrapper.java      |   6 +-
 79 files changed, 1753 insertions(+), 199 deletions(-)
 copy dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/{DubboServiceConsumerBootstrap.java => compatible/DubboInterfaceConsumerBootstrap.java} (58%)
 create mode 100644 dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/User.java
 create mode 100644 dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserService.java
 create mode 100644 dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserServiceImpl.java
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/README.md
 copy dubbo-demo/{dubbo-demo-api/dubbo-demo-api-provider => dubbo-call-sc&dubbo/consumer}/pom.xml (81%)
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/User.java
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserService.java
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserServiceImpl.java
 copy {dubbo-registry/dubbo-registry-sofa/src/test => dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main}/resources/log4j.properties (100%)
 copy dubbo-demo/{dubbo-demo-api => dubbo-call-sc&dubbo}/pom.xml (93%)
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/provider/pom.xml
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/configuration/RestTemplateConfiguration.java
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/MeController.java
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/PropertyController.java
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/TestController.java
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/feign/TestFeign.java
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/resources/application.yml
 create mode 100644 dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/resources/bootstrap.yml
 create mode 100644 dubbo-demo/dubbo-call-sc/README.md
 copy dubbo-demo/{dubbo-demo-api/dubbo-demo-api-provider => dubbo-call-sc/consumer}/pom.xml (81%)
 create mode 100644 dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
 create mode 100644 dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/User.java
 create mode 100644 dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserService.java
 create mode 100644 dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserServiceImpl.java
 copy {dubbo-registry/dubbo-registry-sofa/src/test => dubbo-demo/dubbo-call-sc/consumer/src/main}/resources/log4j.properties (100%)
 copy dubbo-demo/{dubbo-demo-api => dubbo-call-sc}/pom.xml (93%)
 create mode 100644 dubbo-demo/dubbo-call-sc/provider/pom.xml
 create mode 100644 dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
 create mode 100644 dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/configuration/RestTemplateConfiguration.java
 create mode 100644 dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/MeController.java
 create mode 100644 dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/PropertyController.java
 create mode 100644 dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/TestController.java
 create mode 100644 dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/User.java
 create mode 100644 dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/feign/TestFeign.java
 create mode 100644 dubbo-demo/dubbo-call-sc/provider/src/main/resources/application.yml
 create mode 100644 dubbo-demo/dubbo-call-sc/provider/src/main/resources/bootstrap.yml
 create mode 100644 dubbo-demo/sc-call-dubbo/consumer/pom.xml
 create mode 100644 dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/Application.java
 create mode 100644 dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/configuration/RestTemplateConfiguration.java
 create mode 100644 dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/controller/ClientController.java
 create mode 100644 dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/feign/TestFeign.java
 create mode 100644 dubbo-demo/sc-call-dubbo/consumer/src/main/resources/application-holding.yml
 create mode 100644 dubbo-demo/sc-call-dubbo/consumer/src/main/resources/application.yml
 create mode 100644 dubbo-demo/sc-call-dubbo/consumer/src/main/resources/bootstrap.yml
 copy dubbo-demo/{dubbo-demo-api => sc-call-dubbo}/pom.xml (93%)
 copy dubbo-demo/{dubbo-demo-api => sc-call-dubbo/provider}/pom.xml (57%)
 copy dubbo-demo/{dubbo-demo-api/dubbo-demo-api-provider => sc-call-dubbo/provider}/src/main/java/org/apache/dubbo/demo/provider/Application.java (100%)
 copy dubbo-demo/{dubbo-demo-api/dubbo-demo-api-provider => sc-call-dubbo/provider}/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java (100%)
 copy {dubbo-registry/dubbo-registry-sofa/src/test => dubbo-demo/sc-call-dubbo/provider/src/main}/resources/log4j.properties (100%)
 rename dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/{support => service}/ServiceOrientedRegistry.java (98%)
 copy dubbo-registry/{dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdRegistryFactory.java => dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistryFactory.java} (61%)
 copy dubbo-compatible/src/test/java/org/apache/dubbo/rpc/cluster/NewRouter.java => dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistryProtocol.java (53%)
 create mode 100644 dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
 create mode 100644 dubbo-registry/dubbo-registry-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory


[dubbo] 03/13: consul complement

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 2eaa132b20eae50f18e391a7418ec24f4cff439e
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Aug 12 16:52:46 2019 +0800

    consul complement
---
 .../registry/consul/ConsulServiceDiscovery.java    | 112 ++++++++++++++++++---
 ...e.dubbo.registry.client.ServiceDiscoveryFactory |   1 +
 2 files changed, 99 insertions(+), 14 deletions(-)

diff --git a/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java b/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java
index 3f8f6bd..ce7efc6 100644
--- a/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java
+++ b/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java
@@ -17,18 +17,20 @@
 package org.apache.dubbo.registry.consul;
 
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.NamedThreadFactory;
-import org.apache.dubbo.event.EventDispatcher;
 import org.apache.dubbo.event.EventListener;
-import org.apache.dubbo.registry.NotifyListener;
 import org.apache.dubbo.registry.client.ServiceDiscovery;
 import org.apache.dubbo.registry.client.ServiceInstance;
 import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent;
 import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener;
 
 import com.ecwid.consul.v1.ConsulClient;
+import com.ecwid.consul.v1.QueryParams;
 import com.ecwid.consul.v1.Response;
 import com.ecwid.consul.v1.agent.model.NewService;
+import com.ecwid.consul.v1.health.HealthServicesRequest;
 import com.ecwid.consul.v1.health.model.HealthService;
 
 import java.util.Collections;
@@ -36,15 +38,14 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 import static java.util.concurrent.Executors.newCachedThreadPool;
-import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
 import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.CHECK_PASS_INTERVAL;
 import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.DEFAULT_CHECK_PASS_INTERVAL;
 import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.DEFAULT_DEREGISTER_TIME;
@@ -59,22 +60,20 @@ import static org.apache.dubbo.registry.consul.AbstractConsulRegistry.WATCH_TIME
  * 2019-07-31
  */
 public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<ServiceInstancesChangedEvent> {
+    private static final Logger logger = LoggerFactory.getLogger(ConsulServiceDiscovery.class);
 
     private ConsulClient client;
-    private long checkPassInterval;
     private ExecutorService notifierExecutor = newCachedThreadPool(
             new NamedThreadFactory("dubbo-consul-notifier", true));
-    private ScheduledExecutorService ttlConsulCheckExecutor;
-
+    private TtlScheduler ttlScheduler;
+    private long checkPassInterval;
 
     public ConsulServiceDiscovery(URL url) {
         String host = url.getHost();
         int port = url.getPort() != 0 ? url.getPort() : DEFAULT_PORT;
-        client = new ConsulClient(host, port);
         checkPassInterval = url.getParameter(CHECK_PASS_INTERVAL, DEFAULT_CHECK_PASS_INTERVAL);
-        ttlConsulCheckExecutor = Executors.newSingleThreadScheduledExecutor();
-//        ttlConsulCheckExecutor.scheduleAtFixedRate(this::checkPass, checkPassInterval / 8,
-//                checkPassInterval / 8, TimeUnit.MILLISECONDS);
+        client = new ConsulClient(host, port);
+        ttlScheduler = new TtlScheduler(checkPassInterval, client);
     }
 
     @Override
@@ -94,7 +93,9 @@ public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<S
 
     @Override
     public void register(ServiceInstance serviceInstance) throws RuntimeException {
-        client.agentServiceRegister(buildService(serviceInstance));
+        NewService consulService = buildService(serviceInstance);
+        ttlScheduler.add(consulService.getId());
+        client.agentServiceRegister(consulService);
     }
 
     @Override
@@ -104,7 +105,9 @@ public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<S
 
     @Override
     public void unregister(ServiceInstance serviceInstance) throws RuntimeException {
-        client.agentServiceDeregister(buildId(serviceInstance));
+        String id = buildId(serviceInstance);
+        ttlScheduler.remove(id);
+        client.agentServiceDeregister(id);
     }
 
     @Override
@@ -117,6 +120,22 @@ public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<S
 
     }
 
+    @Override
+    public List<ServiceInstance> getInstances(String serviceName) throws NullPointerException {
+        List<ServiceInstance> instances;
+        Response<List<HealthService>> response = getHealthServices(serviceName, -1, buildWatchTimeout(url));
+        urls = convert(response.getValue(), url);
+    }
+
+    private Response<List<HealthService>> getHealthServices(String service, long index, int watchTimeout) {
+        HealthServicesRequest request = HealthServicesRequest.newBuilder()
+                .setTag(SERVICE_TAG)
+                .setQueryParams(new QueryParams(watchTimeout, index))
+                .setPassing(true)
+                .build();
+        return client.getHealthServices(service, request);
+    }
+
     private NewService buildService(ServiceInstance serviceInstance) {
         NewService service = new NewService();
         service.setAddress(serviceInstance.getHost());
@@ -130,7 +149,6 @@ public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<S
     }
 
     private String buildId(ServiceInstance serviceInstance) {
-        // let's simply use url's hashcode to generate unique service id for now
         return Integer.toHexString(serviceInstance.hashCode());
     }
 
@@ -193,4 +211,70 @@ public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<S
             this.running = false;
         }
     }
+
+    private static class TtlScheduler {
+
+        private static final Logger logger = LoggerFactory.getLogger(TtlScheduler.class);
+
+        private final Map<String, ScheduledFuture> serviceHeartbeats = new ConcurrentHashMap<>();
+
+        private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
+        ;
+
+        private long checkInterval;
+
+        private ConsulClient client;
+
+        public TtlScheduler(long checkInterval, ConsulClient client) {
+            this.checkInterval = checkInterval;
+            this.client = client;
+        }
+
+        /**
+         * Add a service to the checks loop.
+         *
+         * @param instanceId instance id
+         */
+        public void add(String instanceId) {
+            ScheduledFuture task = this.scheduler.scheduleAtFixedRate(
+                    new ConsulHeartbeatTask(instanceId),
+                    checkInterval / 8,
+                    checkInterval / 8,
+                    TimeUnit.MILLISECONDS);
+            ScheduledFuture previousTask = this.serviceHeartbeats.put(instanceId, task);
+            if (previousTask != null) {
+                previousTask.cancel(true);
+            }
+        }
+
+        public void remove(String instanceId) {
+            ScheduledFuture task = this.serviceHeartbeats.get(instanceId);
+            if (task != null) {
+                task.cancel(true);
+            }
+            this.serviceHeartbeats.remove(instanceId);
+        }
+
+        private class ConsulHeartbeatTask implements Runnable {
+
+            private String checkId;
+
+            ConsulHeartbeatTask(String serviceId) {
+                this.checkId = serviceId;
+                if (!this.checkId.startsWith("service:")) {
+                    this.checkId = "service:" + this.checkId;
+                }
+            }
+
+            @Override
+            public void run() {
+                TtlScheduler.this.client.agentCheckPass(this.checkId);
+                if (logger.isInfoEnabled()) {
+                    logger.info("Sending consul heartbeat for: " + this.checkId);
+                }
+            }
+
+        }
+
+    }
 }
diff --git a/dubbo-registry/dubbo-registry-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory b/dubbo-registry/dubbo-registry-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory
new file mode 100644
index 0000000..a0f1252
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-consul/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory
@@ -0,0 +1 @@
+consul=org.apache.dubbo.registry.consul.ConsulServiceDiscoveryFactory
\ No newline at end of file


[dubbo] 12/13: demos

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit c8ca5b6d839f7759d09543a5a95e5082278d9860
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Aug 13 20:20:43 2019 +0800

    demos
---
 dubbo-demo/dubbo-call-sc&dubbo/README.md           |  7 ++
 dubbo-demo/dubbo-call-sc&dubbo/consumer/pom.xml    | 81 +++++++++++++++++++++
 .../samples/microservices/sc/Application.java      | 56 +++++++++++++++
 .../dubbo/samples/microservices/sc/rest/User.java  | 77 ++++++++++++++++++++
 .../samples/microservices/sc/rest/UserService.java | 45 ++++++++++++
 .../microservices/sc/rest/UserServiceImpl.java     | 32 +++++++++
 .../consumer/src/main/resources/log4j.properties   |  7 ++
 dubbo-demo/dubbo-call-sc&dubbo/pom.xml             | 61 ++++++++++++++++
 dubbo-demo/dubbo-call-sc&dubbo/provider/pom.xml    | 83 +++++++++++++++++++++
 .../samples/microservices/sc/Application.java      | 15 ++++
 .../configuration/RestTemplateConfiguration.java   | 16 +++++
 .../microservices/sc/controller/MeController.java  | 23 ++++++
 .../sc/controller/PropertyController.java          | 45 ++++++++++++
 .../sc/controller/TestController.java              | 46 ++++++++++++
 .../samples/microservices/sc/feign/TestFeign.java  | 13 ++++
 .../provider/src/main/resources/application.yml    |  6 ++
 .../provider/src/main/resources/bootstrap.yml      | 24 +++++++
 dubbo-demo/dubbo-call-sc/README.md                 |  7 ++
 dubbo-demo/dubbo-call-sc/consumer/pom.xml          | 81 +++++++++++++++++++++
 .../samples/microservices/sc/Application.java      | 55 ++++++++++++++
 .../dubbo/samples/microservices/sc/rest/User.java  | 77 ++++++++++++++++++++
 .../samples/microservices/sc/rest/UserService.java | 45 ++++++++++++
 .../microservices/sc/rest/UserServiceImpl.java     | 32 +++++++++
 .../consumer/src/main/resources/log4j.properties   |  7 ++
 dubbo-demo/dubbo-call-sc/pom.xml                   | 61 ++++++++++++++++
 dubbo-demo/dubbo-call-sc/provider/pom.xml          | 83 +++++++++++++++++++++
 .../samples/microservices/sc/Application.java      | 15 ++++
 .../configuration/RestTemplateConfiguration.java   | 16 +++++
 .../microservices/sc/controller/MeController.java  | 23 ++++++
 .../sc/controller/PropertyController.java          | 45 ++++++++++++
 .../sc/controller/TestController.java              | 54 ++++++++++++++
 .../samples/microservices/sc/controller/User.java  | 60 ++++++++++++++++
 .../samples/microservices/sc/feign/TestFeign.java  | 13 ++++
 .../provider/src/main/resources/application.yml    |  6 ++
 .../provider/src/main/resources/bootstrap.yml      | 24 +++++++
 dubbo-demo/pom.xml                                 |  1 +
 dubbo-demo/sc-call-dubbo/consumer/pom.xml          | 84 ++++++++++++++++++++++
 .../com/bettercloud/spring/cloud/Application.java  | 15 ++++
 .../configuration/RestTemplateConfiguration.java   | 17 +++++
 .../spring/cloud/controller/ClientController.java  | 29 ++++++++
 .../bettercloud/spring/cloud/feign/TestFeign.java  | 12 ++++
 .../src/main/resources/application-holding.yml     |  3 +
 .../consumer/src/main/resources/application.yml    |  7 ++
 .../consumer/src/main/resources/bootstrap.yml      | 26 +++++++
 dubbo-demo/sc-call-dubbo/pom.xml                   | 61 ++++++++++++++++
 dubbo-demo/sc-call-dubbo/provider/pom.xml          | 33 +++++++++
 .../apache/dubbo/demo/provider/Application.java    | 36 ++++++++++
 .../dubbo/demo/provider/DemoServiceImpl.java       | 34 +++++++++
 .../provider/src/main/resources/log4j.properties   |  7 ++
 .../dubbo/registry/dubbo/RegistryProtocolTest.java | 19 +++--
 50 files changed, 1718 insertions(+), 7 deletions(-)

diff --git a/dubbo-demo/dubbo-call-sc&dubbo/README.md b/dubbo-demo/dubbo-call-sc&dubbo/README.md
new file mode 100644
index 0000000..e42c3e7
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/README.md
@@ -0,0 +1,7 @@
+Dubbo自动发现并消费原生Spring Cloud服务,以Consul为注册中心。
+
+* Spring MVC方式开发服务端
+* 以标准Dubbo方式开发客户端
+    * 首先,定义标准JAX-RS注解的接口(与Provider端相对应)
+    * Registry指定
+    * 同时消费,要使用Multiple Registry策略
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/consumer/pom.xml b/dubbo-demo/dubbo-call-sc&dubbo/consumer/pom.xml
new file mode 100644
index 0000000..f1d9dfd
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/consumer/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-call-sc</artifactId>
+        <version>${revision}</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>consumer</artifactId>
+
+    <properties>
+        <skip_maven_deploy>true</skip_maven_deploy>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-config-api</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-demo-interface</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-multicast</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-rpc-dubbo</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-remoting-netty4</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-serialization-hessian2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-bootstrap</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-consul</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-rpc-rest</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+    </dependencies>
+
+</project>
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java b/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
new file mode 100644
index 0000000..4164f60
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
@@ -0,0 +1,56 @@
+/*
+ * 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.dubbo.samples.microservices.sc;
+
+import org.apache.dubbo.bootstrap.DubboBootstrap;
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.context.ConfigManager;
+import org.apache.dubbo.samples.microservices.sc.rest.UserService;
+
+public class Application {
+    public static void main(String[] args) {
+        RegistryConfig interfaceRegistry = new RegistryConfig();
+        interfaceRegistry.setId("interfaceRegistry");
+        interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181");
+
+        new DubboBootstrap()
+                .application("dubbo-consumer-demo")
+                // Zookeeper
+                .registry(interfaceRegistry)
+                // Nacos
+//                .registry("consul", builder -> builder.address("consul://127.0.0.1:8500?registry.type=service&subscribed.services=dubbo-provider-demo"))
+                .reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest"))
+                .onlyRegisterProvider(true)
+                .start()
+                .await();
+
+        ConfigManager configManager = ConfigManager.getInstance();
+
+        ReferenceConfig<UserService> referenceConfig1 = configManager.getReferenceConfig("user");
+        UserService userService = referenceConfig1.get();
+
+        for (int i = 0; i < 500; i++) {
+            Thread.sleep(2000L);
+            System.out.println(echoService.echo("Hello,World"));
+            System.out.println(userService.getUser(1L));
+        }
+    }
+}
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/User.java b/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/User.java
new file mode 100644
index 0000000..c365f8f
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/User.java
@@ -0,0 +1,77 @@
+/*
+ *
+ *   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.dubbo.samples.microservices.sc.rest;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class User implements Serializable {
+
+    @NotNull
+    @Min(1L)
+    private Long id;
+
+    @JsonProperty("username")
+    @XmlElement(name = "username")
+    @NotNull
+    @Size(min = 6, max = 50)
+    private String name;
+
+    public User() {
+    }
+
+    public User(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "User (" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ')';
+    }
+}
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserService.java b/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserService.java
new file mode 100644
index 0000000..06dcb2c
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserService.java
@@ -0,0 +1,45 @@
+/*
+ *
+ *   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.dubbo.samples.microservices.sc.rest;
+
+
+import org.apache.dubbo.rpc.protocol.rest.support.ContentType;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("users")
+@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
+@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
+@Api(value = "UserService")
+public interface UserService {
+
+    @GET
+    @Path("{id : \\d+}")
+    @ApiOperation(value = "getUser")
+    User getUser(@ApiParam(value = "id") @PathParam("id") Long id);
+}
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserServiceImpl.java b/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserServiceImpl.java
new file mode 100644
index 0000000..fcf8875
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserServiceImpl.java
@@ -0,0 +1,32 @@
+/*
+ *
+ *   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.dubbo.samples.microservices.sc.rest;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class UserServiceImpl implements UserService {
+
+    private final AtomicLong idGen = new AtomicLong();
+
+    @Override
+    public User getUser(Long id) {
+        return new User(id, "username" + id);
+    }
+
+}
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/resources/log4j.properties b/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/resources/log4j.properties
new file mode 100644
index 0000000..15a0900
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/consumer/src/main/resources/log4j.properties
@@ -0,0 +1,7 @@
+###set log levels###
+log4j.rootLogger=info, stdout
+###output to the console###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/pom.xml b/dubbo-demo/dubbo-call-sc&dubbo/pom.xml
new file mode 100644
index 0000000..46625c4
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-demo</artifactId>
+        <version>${revision}</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>provider</module>
+        <module>consumer</module>
+    </modules>
+
+    <properties>
+        <skip_maven_deploy>true</skip_maven_deploy>
+        <spring-boot-maven-plugin.version>2.1.4.RELEASE</spring-boot-maven-plugin.version>
+    </properties>
+
+    <artifactId>dubbo-call-sc</artifactId>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot-maven-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/provider/pom.xml b/dubbo-demo/dubbo-call-sc&dubbo/provider/pom.xml
new file mode 100644
index 0000000..f3a3ea0
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/provider/pom.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-call-sc</artifactId>
+        <version>${revision}</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>provider</artifactId>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud-dependencies.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-context</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-feign</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-ribbon</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-consul-all</artifactId>
+            <version>${spring-cloud-starter-consul.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-consul-config</artifactId>
+            <version>${spring-cloud-starter-consul.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <version>${spring-boot-starter-test.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <properties>
+        <spring-cloud-starter-consul.version>1.3.0.RELEASE</spring-cloud-starter-consul.version>
+        <spring-boot-starter-test.version>1.5.10.RELEASE</spring-boot-starter-test.version>
+        <spring-cloud-dependencies.version>Dalston.SR4</spring-cloud-dependencies.version>
+    </properties>
+</project>
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
new file mode 100644
index 0000000..7244b58
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
@@ -0,0 +1,15 @@
+package org.apache.dubbo.samples.microservices.sc;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.feign.EnableFeignClients;
+
+@SpringBootApplication
+@EnableDiscoveryClient
+@EnableFeignClients()
+public class Application {
+    public static void main(String[] args) {
+        SpringApplication.run(Application.class, args);
+    }
+}
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/configuration/RestTemplateConfiguration.java b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/configuration/RestTemplateConfiguration.java
new file mode 100644
index 0000000..85cc275
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/configuration/RestTemplateConfiguration.java
@@ -0,0 +1,16 @@
+package org.apache.dubbo.samples.microservices.sc.configuration;
+
+import org.springframework.cloud.client.loadbalancer.LoadBalanced;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+@Configuration
+public class RestTemplateConfiguration {
+
+    @Bean
+    @LoadBalanced
+    RestTemplate loadBalancedRestTemplate() {
+        return new RestTemplate();
+    }
+}
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/MeController.java b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/MeController.java
new file mode 100644
index 0000000..2fcf3e0
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/MeController.java
@@ -0,0 +1,23 @@
+package org.apache.dubbo.samples.microservices.sc.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class MeController {
+
+    private String instanceId;
+
+    @Autowired
+    public MeController(@Value("${spring.cloud.consul.discovery.instance-id:${random.value}}") String instanceId) {
+        this.instanceId = instanceId;
+    }
+
+    @GetMapping("/me")
+    public String me() {
+        return instanceId;
+    }
+
+}
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/PropertyController.java b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/PropertyController.java
new file mode 100644
index 0000000..cb24179
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/PropertyController.java
@@ -0,0 +1,45 @@
+package org.apache.dubbo.samples.microservices.sc.controller;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RefreshScope
+@RestController
+@RequestMapping("/property")
+public class PropertyController {
+
+    @Value("${applicationProp:default value}")
+    private String applicationProperty;
+
+    @Value("${property:default value}")
+    private String property;
+
+    @Value("${property2:default value}")
+    private String property2;
+
+    @Value("${infrastructureDesc:default value}")
+    private String infrastructureDesc;
+
+    @Value("${infrastructureUserName:default value}")
+    private String infrastructureUserName;
+
+    @Value("${infrastructurePassword:default value}")
+    private String infrastructurePassword;
+
+	@Value("${password:mypassword}")
+	private String secret;
+
+    @RequestMapping
+    public String getProperty() {
+        return "<h3>applicationProperty:</h3> " + applicationProperty + "</br>"
+                + "<h3>property:</h3> " +  property + "</br>"
+                + "<h3>property2:</h3> " + property2 + "</br>"
+                + "<h3>infrastructureDesc:</h3> " + infrastructureDesc + "</br>"
+                + "<h3>infrastructureUserName:</h3> " + infrastructureUserName + "</br>"
+                + "<h3>infrastructurePassword:</h3> " + infrastructurePassword + "</br>"
+				+ "<h3>vault password:</h3>" + secret + "</br>";
+    }
+
+}
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/TestController.java b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/TestController.java
new file mode 100644
index 0000000..615e998
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/TestController.java
@@ -0,0 +1,46 @@
+package org.apache.dubbo.samples.microservices.sc.controller;
+
+import org.apache.dubbo.samples.microservices.sc.feign.TestFeign;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+
+@RestController
+@RequestMapping("/ping")
+public class TestController {
+
+    @Value("${spring.application.name}")
+    private String appName;
+
+    private final RestTemplate restTemplate;
+    private final TestFeign testFeign;
+
+    public TestController(RestTemplate restTemplate,
+                          TestFeign testFeign) {
+        this.restTemplate = restTemplate;
+        this.testFeign = testFeign;
+    }
+
+    @RequestMapping
+    public String doAlive() {
+        return "Alive!";
+    }
+
+    @RequestMapping("/rest")
+    public String doRestAlive() {
+        return new RestTemplate().getForObject("http://localhost:8099/ping", String.class);
+    }
+
+    @RequestMapping("/rest/ribbon")
+    public String doRestAliveUsingEurekaAndRibbon() {
+        String url = "http://dubbo-provider-demo/users/1";
+        System.out.println("url: "+url);
+        return restTemplate.getForObject(url, String.class);
+    }
+
+    @RequestMapping("/rest/feign")
+    public String doRestAliveUsingFeign() {
+        return testFeign.doAlive();
+    }
+}
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/feign/TestFeign.java b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/feign/TestFeign.java
new file mode 100644
index 0000000..6451c89
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/feign/TestFeign.java
@@ -0,0 +1,13 @@
+package org.apache.dubbo.samples.microservices.sc.feign;
+
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+@FeignClient(name = "dubbo-provider-demo")
+public interface TestFeign {
+
+    @RequestMapping(value="/users/1", method = RequestMethod.GET)
+    String doAlive();
+
+}
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/resources/application.yml b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/resources/application.yml
new file mode 100644
index 0000000..869e5ae
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/resources/application.yml
@@ -0,0 +1,6 @@
+management:
+  security:
+    enabled: false
+endpoints:
+  shutdown:
+    enabled: true
diff --git a/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/resources/bootstrap.yml b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..cabb49f
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc&dubbo/provider/src/main/resources/bootstrap.yml
@@ -0,0 +1,24 @@
+server:
+  port: 8099
+
+spring:
+  application:
+    name: spring-cloud-provider-for-dubbo
+  cloud:
+    consul:
+      host: localhost
+      port: 8500
+      enabled: true
+      discovery:
+        instance-id: ${spring.application.name}:${random.value}
+        service-name: ${spring.application.name}
+      config:
+        format: yaml
+        prefix: config
+        defaultContext: application
+        data-key: data
+        profileSeparator: '-'
+
+management:
+  security:
+    enabled: false
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-call-sc/README.md b/dubbo-demo/dubbo-call-sc/README.md
new file mode 100644
index 0000000..e42c3e7
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/README.md
@@ -0,0 +1,7 @@
+Dubbo自动发现并消费原生Spring Cloud服务,以Consul为注册中心。
+
+* Spring MVC方式开发服务端
+* 以标准Dubbo方式开发客户端
+    * 首先,定义标准JAX-RS注解的接口(与Provider端相对应)
+    * Registry指定
+    * 同时消费,要使用Multiple Registry策略
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-call-sc/consumer/pom.xml b/dubbo-demo/dubbo-call-sc/consumer/pom.xml
new file mode 100644
index 0000000..f1d9dfd
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/consumer/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-call-sc</artifactId>
+        <version>${revision}</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>consumer</artifactId>
+
+    <properties>
+        <skip_maven_deploy>true</skip_maven_deploy>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-config-api</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-demo-interface</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-multicast</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-rpc-dubbo</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-remoting-netty4</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-serialization-hessian2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-bootstrap</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-consul</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-rpc-rest</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+    </dependencies>
+
+</project>
diff --git a/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java b/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
new file mode 100644
index 0000000..3a017a2
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
@@ -0,0 +1,55 @@
+/*
+ * 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.dubbo.samples.microservices.sc;
+
+import org.apache.dubbo.bootstrap.DubboBootstrap;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.context.ConfigManager;
+import org.apache.dubbo.samples.microservices.sc.rest.UserService;
+
+public class Application {
+    public static void main(String[] args) throws Exception{
+        RegistryConfig interfaceRegistry = new RegistryConfig();
+        interfaceRegistry.setId("interfaceRegistry");
+        interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181?" +
+                "registry.type=service&subscribed.services=spring-cloud-provider-for-dubbo");
+
+        new DubboBootstrap()
+                .application("dubbo-consumer-demo")
+                // Zookeeper
+                .registry(interfaceRegistry)
+                // Nacos
+//                .registry("consul", builder -> builder.address("consul://127.0.0.1:8500?registry.type=service&subscribed.services=dubbo-provider-demo"))
+                .reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest"))
+                .onlyRegisterProvider(true)
+                .start()
+                .await();
+
+        ConfigManager configManager = ConfigManager.getInstance();
+
+        ReferenceConfig<UserService> referenceConfig1 = configManager.getReferenceConfig("user");
+        UserService userService = referenceConfig1.get();
+
+        for (int i = 0; i < 500; i++) {
+            Thread.sleep(2000L);
+            System.out.println(userService.getUser(1L));
+        }
+    }
+}
diff --git a/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/User.java b/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/User.java
new file mode 100644
index 0000000..c365f8f
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/User.java
@@ -0,0 +1,77 @@
+/*
+ *
+ *   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.dubbo.samples.microservices.sc.rest;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class User implements Serializable {
+
+    @NotNull
+    @Min(1L)
+    private Long id;
+
+    @JsonProperty("username")
+    @XmlElement(name = "username")
+    @NotNull
+    @Size(min = 6, max = 50)
+    private String name;
+
+    public User() {
+    }
+
+    public User(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "User (" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ')';
+    }
+}
diff --git a/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserService.java b/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserService.java
new file mode 100644
index 0000000..06dcb2c
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserService.java
@@ -0,0 +1,45 @@
+/*
+ *
+ *   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.dubbo.samples.microservices.sc.rest;
+
+
+import org.apache.dubbo.rpc.protocol.rest.support.ContentType;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("users")
+@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
+@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
+@Api(value = "UserService")
+public interface UserService {
+
+    @GET
+    @Path("{id : \\d+}")
+    @ApiOperation(value = "getUser")
+    User getUser(@ApiParam(value = "id") @PathParam("id") Long id);
+}
diff --git a/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserServiceImpl.java b/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserServiceImpl.java
new file mode 100644
index 0000000..fcf8875
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/consumer/src/main/java/org/apache/dubbo/samples/microservices/sc/rest/UserServiceImpl.java
@@ -0,0 +1,32 @@
+/*
+ *
+ *   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.dubbo.samples.microservices.sc.rest;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class UserServiceImpl implements UserService {
+
+    private final AtomicLong idGen = new AtomicLong();
+
+    @Override
+    public User getUser(Long id) {
+        return new User(id, "username" + id);
+    }
+
+}
diff --git a/dubbo-demo/dubbo-call-sc/consumer/src/main/resources/log4j.properties b/dubbo-demo/dubbo-call-sc/consumer/src/main/resources/log4j.properties
new file mode 100644
index 0000000..15a0900
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/consumer/src/main/resources/log4j.properties
@@ -0,0 +1,7 @@
+###set log levels###
+log4j.rootLogger=info, stdout
+###output to the console###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-call-sc/pom.xml b/dubbo-demo/dubbo-call-sc/pom.xml
new file mode 100644
index 0000000..46625c4
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-demo</artifactId>
+        <version>${revision}</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>provider</module>
+        <module>consumer</module>
+    </modules>
+
+    <properties>
+        <skip_maven_deploy>true</skip_maven_deploy>
+        <spring-boot-maven-plugin.version>2.1.4.RELEASE</spring-boot-maven-plugin.version>
+    </properties>
+
+    <artifactId>dubbo-call-sc</artifactId>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot-maven-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/dubbo-demo/dubbo-call-sc/provider/pom.xml b/dubbo-demo/dubbo-call-sc/provider/pom.xml
new file mode 100644
index 0000000..f3a3ea0
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/provider/pom.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-call-sc</artifactId>
+        <version>${revision}</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>provider</artifactId>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud-dependencies.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-context</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-feign</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-ribbon</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-consul-all</artifactId>
+            <version>${spring-cloud-starter-consul.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-consul-config</artifactId>
+            <version>${spring-cloud-starter-consul.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <version>${spring-boot-starter-test.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <properties>
+        <spring-cloud-starter-consul.version>1.3.0.RELEASE</spring-cloud-starter-consul.version>
+        <spring-boot-starter-test.version>1.5.10.RELEASE</spring-boot-starter-test.version>
+        <spring-cloud-dependencies.version>Dalston.SR4</spring-cloud-dependencies.version>
+    </properties>
+</project>
diff --git a/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
new file mode 100644
index 0000000..7244b58
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/Application.java
@@ -0,0 +1,15 @@
+package org.apache.dubbo.samples.microservices.sc;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.feign.EnableFeignClients;
+
+@SpringBootApplication
+@EnableDiscoveryClient
+@EnableFeignClients()
+public class Application {
+    public static void main(String[] args) {
+        SpringApplication.run(Application.class, args);
+    }
+}
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/configuration/RestTemplateConfiguration.java b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/configuration/RestTemplateConfiguration.java
new file mode 100644
index 0000000..85cc275
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/configuration/RestTemplateConfiguration.java
@@ -0,0 +1,16 @@
+package org.apache.dubbo.samples.microservices.sc.configuration;
+
+import org.springframework.cloud.client.loadbalancer.LoadBalanced;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+@Configuration
+public class RestTemplateConfiguration {
+
+    @Bean
+    @LoadBalanced
+    RestTemplate loadBalancedRestTemplate() {
+        return new RestTemplate();
+    }
+}
diff --git a/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/MeController.java b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/MeController.java
new file mode 100644
index 0000000..2fcf3e0
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/MeController.java
@@ -0,0 +1,23 @@
+package org.apache.dubbo.samples.microservices.sc.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class MeController {
+
+    private String instanceId;
+
+    @Autowired
+    public MeController(@Value("${spring.cloud.consul.discovery.instance-id:${random.value}}") String instanceId) {
+        this.instanceId = instanceId;
+    }
+
+    @GetMapping("/me")
+    public String me() {
+        return instanceId;
+    }
+
+}
diff --git a/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/PropertyController.java b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/PropertyController.java
new file mode 100644
index 0000000..cb24179
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/PropertyController.java
@@ -0,0 +1,45 @@
+package org.apache.dubbo.samples.microservices.sc.controller;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RefreshScope
+@RestController
+@RequestMapping("/property")
+public class PropertyController {
+
+    @Value("${applicationProp:default value}")
+    private String applicationProperty;
+
+    @Value("${property:default value}")
+    private String property;
+
+    @Value("${property2:default value}")
+    private String property2;
+
+    @Value("${infrastructureDesc:default value}")
+    private String infrastructureDesc;
+
+    @Value("${infrastructureUserName:default value}")
+    private String infrastructureUserName;
+
+    @Value("${infrastructurePassword:default value}")
+    private String infrastructurePassword;
+
+	@Value("${password:mypassword}")
+	private String secret;
+
+    @RequestMapping
+    public String getProperty() {
+        return "<h3>applicationProperty:</h3> " + applicationProperty + "</br>"
+                + "<h3>property:</h3> " +  property + "</br>"
+                + "<h3>property2:</h3> " + property2 + "</br>"
+                + "<h3>infrastructureDesc:</h3> " + infrastructureDesc + "</br>"
+                + "<h3>infrastructureUserName:</h3> " + infrastructureUserName + "</br>"
+                + "<h3>infrastructurePassword:</h3> " + infrastructurePassword + "</br>"
+				+ "<h3>vault password:</h3>" + secret + "</br>";
+    }
+
+}
diff --git a/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/TestController.java b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/TestController.java
new file mode 100644
index 0000000..96801f8
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/TestController.java
@@ -0,0 +1,54 @@
+package org.apache.dubbo.samples.microservices.sc.controller;
+
+import org.apache.dubbo.samples.microservices.sc.feign.TestFeign;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+
+@RestController
+@RequestMapping("/users")
+//@RequestMapping("/ping")
+public class TestController {
+
+    @Value("${spring.application.name}")
+    private String appName;
+
+    private final RestTemplate restTemplate;
+    private final TestFeign testFeign;
+
+    public TestController(RestTemplate restTemplate,
+                          TestFeign testFeign) {
+        this.restTemplate = restTemplate;
+        this.testFeign = testFeign;
+    }
+
+    @RequestMapping("{id}")
+    public User getUser(@PathVariable("id") Long id) {
+        return new User(id, "username-" + id);
+    }
+
+
+    @RequestMapping
+    public String doAlive() {
+        return "Alive!";
+    }
+
+    @RequestMapping("/rest")
+    public String doRestAlive() {
+        return new RestTemplate().getForObject("http://localhost:8099/ping", String.class);
+    }
+
+    @RequestMapping("/rest/ribbon")
+    public String doRestAliveUsingEurekaAndRibbon() {
+        String url = "http://dubbo-provider-demo/users/1";
+        System.out.println("url: "+url);
+        return restTemplate.getForObject(url, String.class);
+    }
+
+    @RequestMapping("/rest/feign")
+    public String doRestAliveUsingFeign() {
+        return testFeign.doAlive();
+    }
+}
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/User.java b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/User.java
new file mode 100644
index 0000000..dd163f1
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/controller/User.java
@@ -0,0 +1,60 @@
+/*
+ *
+ *   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.dubbo.samples.microservices.sc.controller;
+
+import java.io.Serializable;
+
+public class User implements Serializable {
+
+    private Long id;
+
+    private String name;
+
+    public User() {
+    }
+
+    public User(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "User (" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ')';
+    }
+}
diff --git a/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/feign/TestFeign.java b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/feign/TestFeign.java
new file mode 100644
index 0000000..6451c89
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/provider/src/main/java/org/apache/dubbo/samples/microservices/sc/feign/TestFeign.java
@@ -0,0 +1,13 @@
+package org.apache.dubbo.samples.microservices.sc.feign;
+
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+@FeignClient(name = "dubbo-provider-demo")
+public interface TestFeign {
+
+    @RequestMapping(value="/users/1", method = RequestMethod.GET)
+    String doAlive();
+
+}
diff --git a/dubbo-demo/dubbo-call-sc/provider/src/main/resources/application.yml b/dubbo-demo/dubbo-call-sc/provider/src/main/resources/application.yml
new file mode 100644
index 0000000..869e5ae
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/provider/src/main/resources/application.yml
@@ -0,0 +1,6 @@
+management:
+  security:
+    enabled: false
+endpoints:
+  shutdown:
+    enabled: true
diff --git a/dubbo-demo/dubbo-call-sc/provider/src/main/resources/bootstrap.yml b/dubbo-demo/dubbo-call-sc/provider/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..cabb49f
--- /dev/null
+++ b/dubbo-demo/dubbo-call-sc/provider/src/main/resources/bootstrap.yml
@@ -0,0 +1,24 @@
+server:
+  port: 8099
+
+spring:
+  application:
+    name: spring-cloud-provider-for-dubbo
+  cloud:
+    consul:
+      host: localhost
+      port: 8500
+      enabled: true
+      discovery:
+        instance-id: ${spring.application.name}:${random.value}
+        service-name: ${spring.application.name}
+      config:
+        format: yaml
+        prefix: config
+        defaultContext: application
+        data-key: data
+        profileSeparator: '-'
+
+management:
+  security:
+    enabled: false
\ No newline at end of file
diff --git a/dubbo-demo/pom.xml b/dubbo-demo/pom.xml
index e636a23..4c03eda 100644
--- a/dubbo-demo/pom.xml
+++ b/dubbo-demo/pom.xml
@@ -35,6 +35,7 @@
         <module>dubbo-demo-xml</module>
         <module>dubbo-demo-annotation</module>
         <module>dubbo-demo-api</module>
+        <!--        <module>dubbo-call-sc</module>-->
     </modules>
 
     <dependencyManagement>
diff --git a/dubbo-demo/sc-call-dubbo/consumer/pom.xml b/dubbo-demo/sc-call-dubbo/consumer/pom.xml
new file mode 100644
index 0000000..e938869
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/consumer/pom.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-call-sc</artifactId>
+        <version>${revision}</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>consumer</artifactId>
+
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud-dependencies.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-context</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-feign</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-ribbon</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-consul-all</artifactId>
+            <version>${spring-cloud-starter-consul.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-consul-config</artifactId>
+            <version>${spring-cloud-starter-consul.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <version>${spring-boot-starter-test.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <properties>
+        <spring-cloud-starter-consul.version>1.3.0.RELEASE</spring-cloud-starter-consul.version>
+        <spring-boot-starter-test.version>1.5.10.RELEASE</spring-boot-starter-test.version>
+        <spring-cloud-dependencies.version>Dalston.SR4</spring-cloud-dependencies.version>
+    </properties>
+</project>
diff --git a/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/Application.java b/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/Application.java
new file mode 100644
index 0000000..e1f07cb
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/Application.java
@@ -0,0 +1,15 @@
+package com.bettercloud.spring.cloud;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.feign.EnableFeignClients;
+
+@SpringBootApplication
+@EnableDiscoveryClient
+@EnableFeignClients
+public class Application {
+    public static void main(String[] args) {
+        SpringApplication.run(Application.class, args);
+    }
+}
\ No newline at end of file
diff --git a/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/configuration/RestTemplateConfiguration.java b/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/configuration/RestTemplateConfiguration.java
new file mode 100644
index 0000000..cf0a2b1
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/configuration/RestTemplateConfiguration.java
@@ -0,0 +1,17 @@
+package com.bettercloud.spring.cloud.configuration;
+
+import org.springframework.cloud.client.loadbalancer.LoadBalanced;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+@Configuration
+public class RestTemplateConfiguration {
+
+    @Bean
+    @LoadBalanced
+    RestTemplate loadBalancedRestTemplate() {
+        return new RestTemplate();
+    }
+
+}
diff --git a/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/controller/ClientController.java b/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/controller/ClientController.java
new file mode 100644
index 0000000..b38edf3
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/controller/ClientController.java
@@ -0,0 +1,29 @@
+package com.bettercloud.spring.cloud.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+
+
+@RestController
+@RequestMapping("/client")
+public class ClientController {
+
+    private String serviceEndpoint;
+    private RestTemplate restTemplate;
+
+    @Autowired
+    public ClientController(@Value("${service.me}") final String serviceEndpoint, final RestTemplate restTemplate) {
+        this.serviceEndpoint = serviceEndpoint;
+        this.restTemplate = restTemplate;
+    }
+
+    @GetMapping
+    public String getService() {
+        return restTemplate.getForEntity(serviceEndpoint, String.class).getBody();
+    }
+
+}
diff --git a/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/feign/TestFeign.java b/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/feign/TestFeign.java
new file mode 100644
index 0000000..e8663ec
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/consumer/src/main/java/com/bettercloud/spring/cloud/feign/TestFeign.java
@@ -0,0 +1,12 @@
+package com.bettercloud.spring.cloud.feign;
+
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+@FeignClient(name = "springcloudwebtest")
+public interface TestFeign {
+
+    @RequestMapping(value="/ping", method = RequestMethod.GET)
+    String doAlive();
+}
diff --git a/dubbo-demo/sc-call-dubbo/consumer/src/main/resources/application-holding.yml b/dubbo-demo/sc-call-dubbo/consumer/src/main/resources/application-holding.yml
new file mode 100644
index 0000000..7a8a421
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/consumer/src/main/resources/application-holding.yml
@@ -0,0 +1,3 @@
+service:
+  host: http://service-holding
+  me: ${service.host}/me
diff --git a/dubbo-demo/sc-call-dubbo/consumer/src/main/resources/application.yml b/dubbo-demo/sc-call-dubbo/consumer/src/main/resources/application.yml
new file mode 100644
index 0000000..bb7bfea
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/consumer/src/main/resources/application.yml
@@ -0,0 +1,7 @@
+management:
+  security:
+    enabled: false
+endpoints:
+  shutdown:
+    enabled: true
+
diff --git a/dubbo-demo/sc-call-dubbo/consumer/src/main/resources/bootstrap.yml b/dubbo-demo/sc-call-dubbo/consumer/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..73dacfc
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/consumer/src/main/resources/bootstrap.yml
@@ -0,0 +1,26 @@
+server:
+  port: 8080
+
+spring:
+  application:
+    name: client
+  cloud:
+    consul:
+      host: consul
+      port: 8500
+      enabled: true
+      config:
+        format: yaml
+        prefix: config
+        defaultContext: application
+        data-key: data
+        profileSeparator: '-'
+    vault:
+      scheme: http
+      host: vault
+      authentication: TOKEN
+      token: ${VAULT_APP_TOKEN}
+
+management:
+  security:
+    enabled: false
\ No newline at end of file
diff --git a/dubbo-demo/sc-call-dubbo/pom.xml b/dubbo-demo/sc-call-dubbo/pom.xml
new file mode 100644
index 0000000..46625c4
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-demo</artifactId>
+        <version>${revision}</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>provider</module>
+        <module>consumer</module>
+    </modules>
+
+    <properties>
+        <skip_maven_deploy>true</skip_maven_deploy>
+        <spring-boot-maven-plugin.version>2.1.4.RELEASE</spring-boot-maven-plugin.version>
+    </properties>
+
+    <artifactId>dubbo-call-sc</artifactId>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot-maven-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/dubbo-demo/sc-call-dubbo/provider/pom.xml b/dubbo-demo/sc-call-dubbo/provider/pom.xml
new file mode 100644
index 0000000..9f98d0e
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/provider/pom.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-call-sc</artifactId>
+        <version>${revision}</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>provider</artifactId>
+
+</project>
diff --git a/dubbo-demo/sc-call-dubbo/provider/src/main/java/org/apache/dubbo/demo/provider/Application.java b/dubbo-demo/sc-call-dubbo/provider/src/main/java/org/apache/dubbo/demo/provider/Application.java
new file mode 100644
index 0000000..5990d75
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/provider/src/main/java/org/apache/dubbo/demo/provider/Application.java
@@ -0,0 +1,36 @@
+/*
+ * 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.dubbo.demo.provider;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.demo.DemoService;
+
+public class Application {
+    public static void main(String[] args) throws Exception {
+        ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
+        service.setApplication(new ApplicationConfig("dubbo-demo-api-provider"));
+        service.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
+        service.setInterface(DemoService.class);
+        service.setRef(new DemoServiceImpl());
+        service.export();
+        System.in.read();
+    }
+}
diff --git a/dubbo-demo/sc-call-dubbo/provider/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java b/dubbo-demo/sc-call-dubbo/provider/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java
new file mode 100644
index 0000000..5e2ef23
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/provider/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java
@@ -0,0 +1,34 @@
+/*
+ * 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.dubbo.demo.provider;
+
+import org.apache.dubbo.demo.DemoService;
+import org.apache.dubbo.rpc.RpcContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DemoServiceImpl implements DemoService {
+    private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class);
+
+    @Override
+    public String sayHello(String name) {
+        logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+        return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
+    }
+
+}
diff --git a/dubbo-demo/sc-call-dubbo/provider/src/main/resources/log4j.properties b/dubbo-demo/sc-call-dubbo/provider/src/main/resources/log4j.properties
new file mode 100644
index 0000000..15a0900
--- /dev/null
+++ b/dubbo-demo/sc-call-dubbo/provider/src/main/resources/log4j.properties
@@ -0,0 +1,7 @@
+###set log levels###
+log4j.rootLogger=info, stdout
+###output to the console###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n
\ No newline at end of file
diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java
index 192ed58..ff3f130 100644
--- a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java
+++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java
@@ -41,6 +41,7 @@ import org.junit.jupiter.api.Test;
 import java.util.ArrayList;
 import java.util.List;
 
+import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
 import static org.apache.dubbo.registry.integration.RegistryProtocol.DEFAULT_REGISTER_PROVIDER_KEYS;
 import static org.apache.dubbo.rpc.cluster.Constants.EXPORT_KEY;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -62,16 +63,20 @@ public class RegistryProtocolTest {
     final URL registryUrl = URL.valueOf("registry://127.0.0.1:9090/");
     final private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
 
+    public static RegistryProtocol getRegistryProtocol() {
+        return (RegistryProtocol) ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(REGISTRY_PROTOCOL);
+    }
+
     @Test
     public void testDefaultPort() {
-        RegistryProtocol registryProtocol = RegistryProtocol.getRegistryProtocol();
+        RegistryProtocol registryProtocol = getRegistryProtocol();
         assertEquals(9090, registryProtocol.getDefaultPort());
     }
 
     @Test
     public void testExportUrlNull() {
         Assertions.assertThrows(IllegalArgumentException.class, () -> {
-            RegistryProtocol registryProtocol = RegistryProtocol.getRegistryProtocol();
+            RegistryProtocol registryProtocol = getRegistryProtocol();
             registryProtocol.setCluster(new FailfastCluster());
 
             Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
@@ -84,7 +89,7 @@ public class RegistryProtocolTest {
 
     @Test
     public void testExport() {
-        RegistryProtocol registryProtocol = RegistryProtocol.getRegistryProtocol();
+        RegistryProtocol registryProtocol = getRegistryProtocol();
         registryProtocol.setCluster(new FailfastCluster());
         registryProtocol.setRegistryFactory(ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension());
 
@@ -107,7 +112,7 @@ public class RegistryProtocolTest {
         URL newRegistryUrl = registryUrl.addParameter(EXPORT_KEY, serviceUrl);
         Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
         Exporter<?> exporter = protocol.export(invoker);
-        RegistryProtocol rprotocol = RegistryProtocol.getRegistryProtocol();
+        RegistryProtocol rprotocol = getRegistryProtocol();
         NotifyListener listener = getListener(rprotocol);
         List<URL> urls = new ArrayList<URL>();
         urls.add(URL.valueOf("override://0.0.0.0/?timeout=1000"));
@@ -137,7 +142,7 @@ public class RegistryProtocolTest {
         URL newRegistryUrl = registryUrl.addParameter(EXPORT_KEY, serviceUrl);
         Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
         Exporter<?> exporter = protocol.export(invoker);
-        RegistryProtocol rprotocol = RegistryProtocol.getRegistryProtocol();
+        RegistryProtocol rprotocol = getRegistryProtocol();
         NotifyListener listener = getListener(rprotocol);
         List<URL> urls = new ArrayList<URL>();
         urls.add(URL.valueOf("override://0.0.0.0/org.apache.dubbo.registry.protocol.HackService?timeout=100"));
@@ -168,7 +173,7 @@ public class RegistryProtocolTest {
 
     @Test
     public void testGetParamsToRegistry() {
-        RegistryProtocol registryProtocol = RegistryProtocol.getRegistryProtocol();
+        RegistryProtocol registryProtocol = getRegistryProtocol();
         String[] additionalParams = new String[]{"key1", "key2"};
         String[] registryParams = registryProtocol.getParamsToRegistry(DEFAULT_REGISTER_PROVIDER_KEYS, additionalParams);
         String[] expectParams = ArrayUtils.addAll(DEFAULT_REGISTER_PROVIDER_KEYS, additionalParams);
@@ -176,7 +181,7 @@ public class RegistryProtocolTest {
     }
 
     private void destroyRegistryProtocol() {
-        Protocol registry = RegistryProtocol.getRegistryProtocol();
+        Protocol registry = getRegistryProtocol();
         registry.destroy();
     }
 


[dubbo] 08/13: change demo

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit a80f6fc61863abc501b4922306df86569d5e7e71
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Aug 12 19:44:52 2019 +0800

    change demo
---
 .../bootstrap/DubboServiceProviderBootstrap.java   | 37 +++++++++++++++++++---
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
index fc2242e..2639d6b 100644
--- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
@@ -19,7 +19,10 @@ package org.apache.dubbo.bootstrap;
 import org.apache.dubbo.bootstrap.rest.UserService;
 import org.apache.dubbo.bootstrap.rest.UserServiceImpl;
 import org.apache.dubbo.config.ProtocolConfig;
-import org.apache.dubbo.config.builders.RegistryBuilder;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+
+import java.util.Arrays;
 
 /**
  * Dubbo Provider Bootstrap
@@ -29,21 +32,46 @@ import org.apache.dubbo.config.builders.RegistryBuilder;
 public class DubboServiceProviderBootstrap {
 
     public static void main(String[] args) {
+        multipleRegistries();
+    }
+
+    private static void multipleRegistries() {
         ProtocolConfig restProtocol = new ProtocolConfig();
         restProtocol.setName("rest");
         restProtocol.setId("rest");
         restProtocol.setPort(-1);
 
+        RegistryConfig interfaceRegistry = new RegistryConfig();
+        interfaceRegistry.setId("interfaceRegistry");
+        interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181");
+
+        RegistryConfig serviceRegistry = new RegistryConfig();
+        serviceRegistry.setId("serviceRegistry");
+        serviceRegistry.setAddress("zookeeper://127.0.0.1:2181?registry-type=service");
+
+        ServiceConfig<EchoService> echoService = new ServiceConfig<>();
+        echoService.setInterface(EchoService.class.getName());
+        echoService.setRef(new EchoServiceImpl());
+//        echoService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
+
+        ServiceConfig<UserService> userService = new ServiceConfig<>();
+        userService.setInterface(UserService.class.getName());
+        userService.setRef(new UserServiceImpl());
+        userService.setProtocol(restProtocol);
+//        userService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
+
+
         new DubboBootstrap()
                 .application("dubbo-provider-demo")
                 // Zookeeper in service registry type
 //                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service"))
                 // Nacos
 //                .registry("zookeeper", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service"))
-                .registry(RegistryBuilder.newBuilder().address("consul://127.0.0.1:8500?registry-type=service").build())
+                .registries(Arrays.asList(interfaceRegistry, serviceRegistry))
+//                .registry(RegistryBuilder.newBuilder().address("consul://127.0.0.1:8500?registry-type=service").build())
                 .protocol(builder -> builder.port(-1).name("dubbo"))
-                .service(builder -> builder.id("echo").interfaceClass(EchoService.class).ref(new EchoServiceImpl()))
-                .service(builder -> builder.id("user").interfaceClass(UserService.class).ref(new UserServiceImpl()).addProtocol(restProtocol))
+                .service(echoService)
+                .service(userService)
                 .start()
                 .await();
     }
@@ -59,4 +87,5 @@ public class DubboServiceProviderBootstrap {
     private static void testDubboTansormation() {
 
     }
+
 }


[dubbo] 01/13: add rest demo

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit a12a5398850dac857c1021fa751801f993035287
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Aug 12 16:52:04 2019 +0800

    add rest demo
---
 dubbo-bootstrap/pom.xml                            | 13 +++-
 .../bootstrap/DubboServiceConsumerBootstrap.java   |  8 ++-
 .../bootstrap/DubboServiceProviderBootstrap.java   | 30 +++++++--
 .../java/org/apache/dubbo/bootstrap/rest/User.java | 77 ++++++++++++++++++++++
 .../apache/dubbo/bootstrap/rest/UserService.java   | 47 +++++++++++++
 .../dubbo/bootstrap/rest/UserServiceImpl.java      | 38 +++++++++++
 6 files changed, 205 insertions(+), 8 deletions(-)

diff --git a/dubbo-bootstrap/pom.xml b/dubbo-bootstrap/pom.xml
index 0fd354d..2566294 100644
--- a/dubbo-bootstrap/pom.xml
+++ b/dubbo-bootstrap/pom.xml
@@ -33,6 +33,12 @@
             <version>${project.parent.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-consul</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
 
         <dependency>
             <groupId>org.apache.dubbo</groupId>
@@ -75,7 +81,12 @@
             <version>${project.parent.version}</version>
             <scope>test</scope>
         </dependency>
-
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-rpc-rest</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-rpc-hessian</artifactId>
diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java
index 0f7a958..def1d07 100644
--- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java
@@ -16,6 +16,7 @@
  */
 package org.apache.dubbo.bootstrap;
 
+import org.apache.dubbo.bootstrap.rest.UserService;
 import org.apache.dubbo.config.ReferenceConfig;
 import org.apache.dubbo.config.context.ConfigManager;
 
@@ -31,10 +32,11 @@ public class DubboServiceConsumerBootstrap {
         new DubboBootstrap()
                 .application("dubbo-consumer-demo")
                 // Zookeeper
-                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service&subscribed-services=dubbo-provider-demo"))
+//                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service&subscribed-services=dubbo-provider-demo"))
                 // Nacos
-//                .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service&subscribed-services=dubbo-provider-demo"))
-                .reference("ref", builder -> builder.interfaceClass(EchoService.class))
+                .registry("consul", builder -> builder.address("consul://127.0.0.1:8500?registry-type=service&subscribed-services=dubbo-provider-demo"))
+                .reference("echo", builder -> builder.interfaceClass(EchoService.class).protocol("dubbo"))
+                .reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest"))
                 .onlyRegisterProvider(true)
                 .start()
                 .await();
diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
index 15d1628..fc2242e 100644
--- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
@@ -16,6 +16,11 @@
  */
 package org.apache.dubbo.bootstrap;
 
+import org.apache.dubbo.bootstrap.rest.UserService;
+import org.apache.dubbo.bootstrap.rest.UserServiceImpl;
+import org.apache.dubbo.config.ProtocolConfig;
+import org.apache.dubbo.config.builders.RegistryBuilder;
+
 /**
  * Dubbo Provider Bootstrap
  *
@@ -24,17 +29,34 @@ package org.apache.dubbo.bootstrap;
 public class DubboServiceProviderBootstrap {
 
     public static void main(String[] args) {
+        ProtocolConfig restProtocol = new ProtocolConfig();
+        restProtocol.setName("rest");
+        restProtocol.setId("rest");
+        restProtocol.setPort(-1);
+
         new DubboBootstrap()
                 .application("dubbo-provider-demo")
                 // Zookeeper in service registry type
-                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service"))
+//                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service"))
                 // Nacos
 //                .registry("zookeeper", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service"))
-//                .registry(RegistryBuilder.newBuilder().address("etcd3://127.0.0.1:2379?registry-type=service").build())
+                .registry(RegistryBuilder.newBuilder().address("consul://127.0.0.1:8500?registry-type=service").build())
                 .protocol(builder -> builder.port(-1).name("dubbo"))
-                .protocol(builder -> builder.port(-1).name("hessian"))
-                .service(builder -> builder.id("test").interfaceClass(EchoService.class).ref(new EchoServiceImpl()))
+                .service(builder -> builder.id("echo").interfaceClass(EchoService.class).ref(new EchoServiceImpl()))
+                .service(builder -> builder.id("user").interfaceClass(UserService.class).ref(new UserServiceImpl()).addProtocol(restProtocol))
                 .start()
                 .await();
     }
+
+    private static void testSCCallDubbo() {
+
+    }
+
+    private static void testDubboCallSC() {
+
+    }
+
+    private static void testDubboTansormation() {
+
+    }
 }
diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/User.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/User.java
new file mode 100644
index 0000000..993862a
--- /dev/null
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/User.java
@@ -0,0 +1,77 @@
+/*
+ *
+ *   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.dubbo.bootstrap.rest;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class User implements Serializable {
+
+    @NotNull
+    @Min(1L)
+    private Long id;
+
+    @JsonProperty("username")
+    @XmlElement(name = "username")
+    @NotNull
+    @Size(min = 6, max = 50)
+    private String name;
+
+    public User() {
+    }
+
+    public User(Long id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "User (" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ')';
+    }
+}
diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserService.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserService.java
new file mode 100644
index 0000000..514a0bf
--- /dev/null
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserService.java
@@ -0,0 +1,47 @@
+/*
+ *
+ *   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.dubbo.bootstrap.rest;
+
+
+import org.apache.dubbo.rpc.protocol.rest.support.ContentType;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("users")
+@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
+@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
+@Api(value = "UserService")
+public interface UserService {
+
+    @GET
+    @Path("{id : \\d+}")
+    @ApiOperation(value = "getUser")
+    User getUser(@ApiParam(value = "id") @PathParam("id") Long id);
+
+    Long registerUser(User user);
+}
diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserServiceImpl.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserServiceImpl.java
new file mode 100644
index 0000000..01259eb
--- /dev/null
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserServiceImpl.java
@@ -0,0 +1,38 @@
+/*
+ *
+ *   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.dubbo.bootstrap.rest;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class UserServiceImpl implements UserService {
+
+    private final AtomicLong idGen = new AtomicLong();
+
+    @Override
+    public User getUser(Long id) {
+        return new User(id, "username" + id);
+    }
+
+
+    @Override
+    public Long registerUser(User user) {
+//        System.out.println("Username is " + user.getName());
+        return idGen.incrementAndGet();
+    }
+}


[dubbo] 10/13: enhance supporting of multiple registries

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit fd89c839447fdea828b7d0d248674281c45d019c
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Aug 13 20:13:48 2019 +0800

    enhance supporting of multiple registries
---
 .../rpc/cluster/directory/AbstractDirectory.java   |  6 +--
 .../dubbo/common/constants/RegistryConstants.java  |  6 ++-
 .../org/apache/dubbo/common/utils/UrlUtils.java    |  5 +++
 .../dubbo/config/AbstractInterfaceConfig.java      | 17 ++++++--
 .../org/apache/dubbo/config/ReferenceConfig.java   |  6 +--
 .../dubbo/config/DubboConsumerBootstrap.java       |  2 +-
 .../dubbo/config/DubboProviderBootstrap.java       |  2 +-
 .../dubbo/qos/protocol/QosProtocolWrapper.java     |  6 +--
 .../registry/integration/RegistryProtocol.java     | 32 ++++++---------
 .../ServiceOrientedRegistry.java                   |  9 ++++-
 .../service/ServiceOrientedRegistryFactory.java    | 38 +++++++++++++++++
 .../service/ServiceOrientedRegistryProtocol.java   | 47 ++++++++++++++++++++++
 .../registry/support/AbstractRegistryFactory.java  | 42 +++++--------------
 .../org.apache.dubbo.registry.RegistryFactory      |  1 +
 .../dubbo/internal/org.apache.dubbo.rpc.Protocol   |  3 +-
 .../support/ServiceOrientedRegistryTest.java       |  1 +
 .../dubbo/rpc/protocol/ProtocolFilterWrapper.java  |  6 +--
 .../rpc/protocol/ProtocolListenerWrapper.java      |  6 +--
 18 files changed, 158 insertions(+), 77 deletions(-)

diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
index 4e304e9..36110c9 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.common.utils.UrlUtils;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.RpcException;
@@ -31,9 +32,8 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
-import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
-import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
+import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
 
 /**
  * Abstract implementation of Directory: Invoker list returned from this Directory's list method have been filtered by Routers
@@ -65,7 +65,7 @@ public abstract class AbstractDirectory<T> implements Directory<T> {
             throw new IllegalArgumentException("url == null");
         }
 
-        if (url.getProtocol().equals(REGISTRY_PROTOCOL)) {
+        if (UrlUtils.isRegistry(url)) {
             Map<String, String> queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(REFER_KEY));
             this.url = url.addParameters(queryMap).removeParameter(MONITOR_KEY);
         } else {
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/RegistryConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/RegistryConstants.java
index 69aa605..b0d89b9 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/RegistryConstants.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/RegistryConstants.java
@@ -58,7 +58,7 @@ public interface RegistryConstants {
      *
      * @since 2.7.4
      */
-    String REGISTRY_TYPE_KEY = "registry-type";
+    String REGISTRY_TYPE_KEY = "registry.type";
 
     /**
      * The parameter value of Service-Oriented Registry type
@@ -67,12 +67,14 @@ public interface RegistryConstants {
      */
     String SERVICE_REGISTRY_TYPE = "service";
 
+    String SERVICE_REGISTRY_PROTOCOL = "service-oriented-registry";
+
     /**
      * The parameter key of the subscribed service names for Service-Oriented Registry
      *
      * @since 2.7.4
      */
-    String SUBSCRIBED_SERVICE_NAMES_KEY = "subscribed-services";
+    String SUBSCRIBED_SERVICE_NAMES_KEY = "subscribed.services";
 
 
     /**
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java
index 91dc387..7a2f99c 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java
@@ -49,8 +49,10 @@ import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGO
 import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL;
 import static org.apache.dubbo.common.constants.RegistryConstants.OVERRIDE_PROTOCOL;
 import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY;
+import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
 import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY;
 import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL;
+import static org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_PROTOCOL;
 
 public class UrlUtils {
 
@@ -484,6 +486,9 @@ public class UrlUtils {
                 PROVIDERS_CATEGORY.equals(url.getParameter(CATEGORY_KEY, PROVIDERS_CATEGORY));
     }
 
+    public static boolean isRegistry(URL url) {
+        return REGISTRY_PROTOCOL.equals(url.getProtocol()) || SERVICE_REGISTRY_PROTOCOL.equalsIgnoreCase(url.getProtocol());
+    }
 
     /**
      * Check if the given value matches the given pattern. The pattern supports wildcard "*".
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java
index b4f83b9..f1ad3d9 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java
@@ -59,6 +59,9 @@ import static org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_SE
 import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
 import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY;
 import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
+import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_TYPE_KEY;
+import static org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_PROTOCOL;
+import static org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_TYPE;
 import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;
 import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY;
 import static org.apache.dubbo.config.Constants.LAYER_KEY;
@@ -281,9 +284,10 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
                     List<URL> urls = UrlUtils.parseURLs(address, map);
 
                     for (URL url : urls) {
+
                         url = URLBuilder.from(url)
                                 .addParameter(REGISTRY_KEY, url.getProtocol())
-                                .setProtocol(REGISTRY_PROTOCOL)
+                                .setProtocol(extractRegistryType(url))
                                 .build();
                         if ((provider && url.getParameter(REGISTER_KEY, true))
                                 || (!provider && url.getParameter(SUBSCRIBE_KEY, true))) {
@@ -296,6 +300,12 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
         return registryList;
     }
 
+    private String extractRegistryType(URL url) {
+        boolean isServiceRegistry = url.getParameter(REGISTRY_TYPE_KEY) != null
+                && SERVICE_REGISTRY_TYPE.equals(url.getParameter(REGISTRY_TYPE_KEY));
+        return isServiceRegistry ? SERVICE_REGISTRY_PROTOCOL : REGISTRY_PROTOCOL;
+    }
+
     /**
      * Load the monitor config from the system properties and conversation it to {@link URL}
      *
@@ -332,10 +342,11 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
                 }
             }
             return UrlUtils.parseURL(address, map);
-        } else if (REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) {
+        } else if ((REGISTRY_PROTOCOL.equals(monitor.getProtocol()) || SERVICE_REGISTRY_PROTOCOL.equals(monitor.getProtocol()))
+                && registryURL != null) {
             return URLBuilder.from(registryURL)
                     .setProtocol(DUBBO_PROTOCOL)
-                    .addParameter(PROTOCOL_KEY, REGISTRY_PROTOCOL)
+                    .addParameter(PROTOCOL_KEY, monitor.getProtocol())
                     .addParameterAndEncoded(REFER_KEY, StringUtils.toQueryString(map))
                     .build();
         }
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
index 3620761..9d01682 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
@@ -25,6 +25,7 @@ import org.apache.dubbo.common.utils.CollectionUtils;
 import org.apache.dubbo.common.utils.ConfigUtils;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.common.utils.UrlUtils;
 import org.apache.dubbo.config.annotation.Reference;
 import org.apache.dubbo.config.context.ConfigManager;
 import org.apache.dubbo.config.event.ReferenceConfigDestroyedEvent;
@@ -73,7 +74,6 @@ import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_PATTERN;
 import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
-import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
 import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost;
 import static org.apache.dubbo.config.Constants.DUBBO_IP_TO_REGISTRY;
 import static org.apache.dubbo.registry.Constants.CONSUMER_PROTOCOL;
@@ -384,7 +384,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
                         if (StringUtils.isEmpty(url.getPath())) {
                             url = url.setPath(interfaceName);
                         }
-                        if (REGISTRY_PROTOCOL.equals(url.getProtocol())) {
+                        if (UrlUtils.isRegistry(url)) {
                             urls.add(url.addParameterAndEncoded(REFER_KEY, StringUtils.toQueryString(map)));
                         } else {
                             urls.add(ClusterUtils.mergeUrl(url, map));
@@ -418,7 +418,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
                 URL registryURL = null;
                 for (URL url : urls) {
                     invokers.add(REF_PROTOCOL.refer(interfaceClass, url));
-                    if (REGISTRY_PROTOCOL.equals(url.getProtocol())) {
+                    if (UrlUtils.isRegistry(url)) {
                         registryURL = url; // use last registry url
                     }
                 }
diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/DubboConsumerBootstrap.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/DubboConsumerBootstrap.java
index 0a67c7b..f10e4e8 100644
--- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/DubboConsumerBootstrap.java
+++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/DubboConsumerBootstrap.java
@@ -34,7 +34,7 @@ public class DubboConsumerBootstrap {
 
         // 连接注册中心配置
         RegistryConfig registry = new RegistryConfig();
-        registry.setAddress("zookeeper://127.0.0.1:2181?registry-type=service");
+        registry.setAddress("zookeeper://127.0.0.1:2181?registry.type=service");
 
         // 服务提供者协议配置
         ProtocolConfig protocol = new ProtocolConfig();
diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/DubboProviderBootstrap.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/DubboProviderBootstrap.java
index 9b68c68..ef8cca8 100644
--- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/DubboProviderBootstrap.java
+++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/DubboProviderBootstrap.java
@@ -39,7 +39,7 @@ public class DubboProviderBootstrap {
         ApplicationConfig application = new ApplicationConfig();
         application.setName("dubbo-provider-demo");
 
-        URL connectionURL = URL.valueOf("zookeeper://127.0.0.1:2181?registry-type=service");
+        URL connectionURL = URL.valueOf("zookeeper://127.0.0.1:2181?registry.type=service");
 
         // 连接注册中心配置
         RegistryConfig registry = new RegistryConfig();
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
index 6c5b72f..05f0382 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java
@@ -19,6 +19,7 @@ package org.apache.dubbo.qos.protocol;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.UrlUtils;
 import org.apache.dubbo.qos.common.QosConstants;
 import org.apache.dubbo.qos.server.Server;
 import org.apache.dubbo.rpc.Exporter;
@@ -33,7 +34,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP;
 import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
 import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT;
-import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
 
 
 public class QosProtocolWrapper implements Protocol {
@@ -58,7 +58,7 @@ public class QosProtocolWrapper implements Protocol {
 
     @Override
     public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
-        if (REGISTRY_PROTOCOL.equals(invoker.getUrl().getProtocol())) {
+        if (UrlUtils.isRegistry(invoker.getUrl())) {
             startQosServer(invoker.getUrl());
             return protocol.export(invoker);
         }
@@ -67,7 +67,7 @@ public class QosProtocolWrapper implements Protocol {
 
     @Override
     public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
-        if (REGISTRY_PROTOCOL.equals(url.getProtocol())) {
+        if (UrlUtils.isRegistry(url)) {
             startQosServer(url);
             return protocol.refer(type, url);
         }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
index 089383c..1c4bd28 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
@@ -121,7 +121,6 @@ public class RegistryProtocol implements Protocol {
     };
 
     private final static Logger logger = LoggerFactory.getLogger(RegistryProtocol.class);
-    private static RegistryProtocol INSTANCE;
     private final Map<URL, NotifyListener> overrideListeners = new ConcurrentHashMap<>();
     private final Map<String, ServiceConfigurationListener> serviceConfigurationListeners = new ConcurrentHashMap<>();
     private final ProviderConfigurationListener providerConfigurationListener = new ProviderConfigurationListener();
@@ -133,17 +132,6 @@ public class RegistryProtocol implements Protocol {
     private RegistryFactory registryFactory;
     private ProxyFactory proxyFactory;
 
-    public RegistryProtocol() {
-        INSTANCE = this;
-    }
-
-    public static RegistryProtocol getRegistryProtocol() {
-        if (INSTANCE == null) {
-            ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(REGISTRY_PROTOCOL); // load
-        }
-        return INSTANCE;
-    }
-
     //Filter the parameters that do not need to be output in url(Starting with .)
     private static String[] getFilteredKeys(URL url) {
         Map<String, String> params = url.getParameters();
@@ -294,12 +282,12 @@ public class RegistryProtocol implements Protocol {
      * @param originInvoker
      * @return
      */
-    private Registry getRegistry(final Invoker<?> originInvoker) {
+    protected Registry getRegistry(final Invoker<?> originInvoker) {
         URL registryUrl = getRegistryUrl(originInvoker);
         return registryFactory.getRegistry(registryUrl);
     }
 
-    private URL getRegistryUrl(Invoker<?> originInvoker) {
+    protected URL getRegistryUrl(Invoker<?> originInvoker) {
         URL registryUrl = originInvoker.getUrl();
         if (REGISTRY_PROTOCOL.equals(registryUrl.getProtocol())) {
             String protocol = registryUrl.getParameter(REGISTRY_KEY, DEFAULT_REGISTRY);
@@ -308,6 +296,13 @@ public class RegistryProtocol implements Protocol {
         return registryUrl;
     }
 
+    protected URL getRegistryUrl(URL url) {
+        return URLBuilder.from(url)
+                .setProtocol(url.getParameter(REGISTRY_KEY, DEFAULT_REGISTRY))
+                .removeParameter(REGISTRY_KEY)
+                .build();
+    }
+
 
     /**
      * Return the url that is registered to the registry and filter the url parameter once
@@ -373,10 +368,7 @@ public class RegistryProtocol implements Protocol {
     @Override
     @SuppressWarnings("unchecked")
     public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
-        url = URLBuilder.from(url)
-                .setProtocol(url.getParameter(REGISTRY_KEY, DEFAULT_REGISTRY))
-                .removeParameter(REGISTRY_KEY)
-                .build();
+        url = getRegistryUrl(url);
         Registry registry = registryFactory.getRegistry(url);
         if (RegistryService.class.equals(type)) {
             return proxyFactory.getInvoker((T) registry, type, url);
@@ -672,14 +664,14 @@ public class RegistryProtocol implements Protocol {
             String key = getCacheKey(this.originInvoker);
             bounds.remove(key);
 
-            Registry registry = RegistryProtocol.INSTANCE.getRegistry(originInvoker);
+            Registry registry = RegistryProtocol.this.getRegistry(originInvoker);
             try {
                 registry.unregister(registerUrl);
             } catch (Throwable t) {
                 logger.warn(t.getMessage(), t);
             }
             try {
-                NotifyListener listener = RegistryProtocol.INSTANCE.overrideListeners.remove(subscribeUrl);
+                NotifyListener listener = RegistryProtocol.this.overrideListeners.remove(subscribeUrl);
                 registry.unsubscribe(subscribeUrl, listener);
                 ExtensionLoader.getExtensionLoader(GovernanceRuleRepository.class).getDefaultExtension()
                         .removeListener(subscribeUrl.getServiceKey() + CONFIGURATORS_SUFFIX,
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistry.java
similarity index 98%
rename from dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java
rename to dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistry.java
index 32d03cd..52348b3 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistry.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.dubbo.registry.support;
+package org.apache.dubbo.registry.service;
 
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.extension.ExtensionLoader;
@@ -31,6 +31,7 @@ import org.apache.dubbo.registry.client.ServiceDiscoveryFactory;
 import org.apache.dubbo.registry.client.ServiceInstance;
 import org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxyFactory;
 import org.apache.dubbo.registry.client.selector.ServiceInstanceSelector;
+import org.apache.dubbo.registry.support.FailbackRegistry;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -52,6 +53,7 @@ import static java.util.stream.Collectors.toSet;
 import static java.util.stream.Stream.of;
 import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL;
 import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.METADATA_DEFAULT;
 import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
@@ -117,7 +119,10 @@ public class ServiceOrientedRegistry extends FailbackRegistry {
 
     private ServiceDiscovery buildServiceDiscovery(URL url) {
         ServiceDiscoveryFactory factory = ExtensionLoader.getExtensionLoader(ServiceDiscoveryFactory.class).getAdaptiveExtension();
-        ServiceDiscovery serviceDiscovery = factory.getDiscovery(url);
+        ServiceDiscovery serviceDiscovery = factory.getDiscovery(url
+                .addParameter(INTERFACE_KEY, ServiceDiscovery.class.getName())
+                .removeParameter(REGISTRY_TYPE_KEY)
+        );
         serviceDiscovery.start();
         return serviceDiscovery;
     }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistryFactory.java
new file mode 100644
index 0000000..ea7027c
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistryFactory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.dubbo.registry.service;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.registry.Registry;
+import org.apache.dubbo.registry.support.AbstractRegistryFactory;
+
+import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY;
+import static org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_PROTOCOL;
+import static org.apache.dubbo.registry.Constants.DEFAULT_REGISTRY;
+
+public class ServiceOrientedRegistryFactory extends AbstractRegistryFactory {
+
+    @Override
+    protected Registry createRegistry(URL url) {
+        if (SERVICE_REGISTRY_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
+            String protocol = url.getParameter(REGISTRY_KEY, DEFAULT_REGISTRY);
+            url = url.setProtocol(protocol).removeParameter(REGISTRY_KEY);
+        }
+        return new ServiceOrientedRegistry(url);
+    }
+
+}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistryProtocol.java
new file mode 100644
index 0000000..733e8b8
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/service/ServiceOrientedRegistryProtocol.java
@@ -0,0 +1,47 @@
+/*
+ * 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.dubbo.registry.service;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.registry.integration.RegistryProtocol;
+import org.apache.dubbo.rpc.Invoker;
+
+import static org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_PROTOCOL;
+
+/**
+ * TODO, replace RegistryProtocol completely in the future.
+ */
+public class ServiceOrientedRegistryProtocol extends RegistryProtocol {
+
+    @Override
+    protected URL getRegistryUrl(Invoker<?> originInvoker) {
+        URL registryUrl = originInvoker.getUrl();
+        if (SERVICE_REGISTRY_PROTOCOL.equals(registryUrl.getProtocol())) {
+            return registryUrl;
+        }
+        return super.getRegistryUrl(originInvoker);
+    }
+
+    @Override
+    protected URL getRegistryUrl(URL url) {
+        if (SERVICE_REGISTRY_PROTOCOL.equals(url.getProtocol())) {
+            return url;
+        }
+        return super.getRegistryUrl(url);
+    }
+
+}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
index 70e7597..c686e38 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
@@ -47,11 +47,8 @@ public abstract class AbstractRegistryFactory implements RegistryFactory {
     // The lock for the acquisition process of the registry
     private static final ReentrantLock LOCK = new ReentrantLock();
 
-    // Registry Collection Map<RegistryAddress, ServiceOrientedRegistry>
-    private static final Map<String, Registry> REGISTRIES = new HashMap<>();
-
     // Registry Collection Map<RegistryAddress, Registry>
-    private static final Map<String, Registry> COMPATIBLE_REGISTRIES = new HashMap<>();
+    private static final Map<String, Registry> REGISTRIES = new HashMap<>();
 
     /**
      * Get all registries
@@ -97,42 +94,23 @@ public abstract class AbstractRegistryFactory implements RegistryFactory {
         // Lock the registry access process to ensure a single instance of the registry
         LOCK.lock();
         try {
-            boolean isServiceOriented = ServiceOrientedRegistry.supports(url);
-            if (isServiceOriented) {
-                Registry registry = REGISTRIES.get(key);
-                if (registry != null) {
-                    return registry;
-                }
-                //create registry by spi/ioc
-                registry = ServiceOrientedRegistry.create(url);
-                if (registry == null) {
-                    throw new IllegalStateException("Can not service-oriented registry " + url);
-                }
-                REGISTRIES.put(key, registry);
+            Registry registry = REGISTRIES.get(key);
+            if (registry != null) {
                 return registry;
-            } else {
-                return getCompatibleRegistry(key, url);
             }
+            //create registry by spi/ioc
+            registry = createRegistry(url);
+            if (registry == null) {
+                throw new IllegalStateException("Can not create registry " + url);
+            }
+            REGISTRIES.put(key, registry);
+            return registry;
         } finally {
             // Release the lock
             LOCK.unlock();
         }
     }
 
-    private Registry getCompatibleRegistry(String key, URL url) {
-        Registry registry = COMPATIBLE_REGISTRIES.get(key);
-        if (registry != null) {
-            return registry;
-        }
-        //create registry by spi/ioc
-        registry = createRegistry(url);
-        if (registry == null) {
-            throw new IllegalStateException("Can not create registry " + url);
-        }
-        COMPATIBLE_REGISTRIES.put(key, registry);
-        return registry;
-    }
-
     protected abstract Registry createRegistry(URL url);
 
 }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
new file mode 100644
index 0000000..d533e06
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
@@ -0,0 +1 @@
+service-oriented-registry=org.apache.dubbo.registry.service.ServiceOrientedRegistryFactory
\ No newline at end of file
diff --git a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
index c2da911..ed2df31 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
+++ b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol
@@ -1 +1,2 @@
-registry=org.apache.dubbo.registry.integration.RegistryProtocol
\ No newline at end of file
+registry=org.apache.dubbo.registry.integration.RegistryProtocol
+service-oriented-registry=org.apache.dubbo.registry.service.ServiceOrientedRegistryProtocol
\ No newline at end of file
diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java
index ec40682..5d9157d 100644
--- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java
+++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java
@@ -19,6 +19,7 @@ package org.apache.dubbo.registry.support;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.metadata.WritableMetadataService;
 import org.apache.dubbo.registry.NotifyListener;
+import org.apache.dubbo.registry.service.ServiceOrientedRegistry;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java
index 5a454a6..84a9033 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java
@@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.protocol;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.constants.CommonConstants;
 import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.utils.UrlUtils;
 import org.apache.dubbo.rpc.Exporter;
 import org.apache.dubbo.rpc.Filter;
 import org.apache.dubbo.rpc.Invocation;
@@ -31,7 +32,6 @@ import org.apache.dubbo.rpc.RpcException;
 
 import java.util.List;
 
-import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
 import static org.apache.dubbo.rpc.Constants.REFERENCE_FILTER_KEY;
 import static org.apache.dubbo.rpc.Constants.SERVICE_FILTER_KEY;
 
@@ -117,7 +117,7 @@ public class ProtocolFilterWrapper implements Protocol {
 
     @Override
     public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
-        if (REGISTRY_PROTOCOL.equals(invoker.getUrl().getProtocol())) {
+        if (UrlUtils.isRegistry(invoker.getUrl())) {
             return protocol.export(invoker);
         }
         return protocol.export(buildInvokerChain(invoker, SERVICE_FILTER_KEY, CommonConstants.PROVIDER));
@@ -125,7 +125,7 @@ public class ProtocolFilterWrapper implements Protocol {
 
     @Override
     public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
-        if (REGISTRY_PROTOCOL.equals(url.getProtocol())) {
+        if (UrlUtils.isRegistry(url)) {
             return protocol.refer(type, url);
         }
         return buildInvokerChain(protocol.refer(type, url), REFERENCE_FILTER_KEY, CommonConstants.CONSUMER);
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolListenerWrapper.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolListenerWrapper.java
index 5e8deb8..63c53e5 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolListenerWrapper.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolListenerWrapper.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.protocol;
 
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.utils.UrlUtils;
 import org.apache.dubbo.rpc.Exporter;
 import org.apache.dubbo.rpc.ExporterListener;
 import org.apache.dubbo.rpc.Invoker;
@@ -31,7 +32,6 @@ import org.apache.dubbo.rpc.listener.ListenerInvokerWrapper;
 import java.util.Collections;
 import java.util.List;
 
-import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
 import static org.apache.dubbo.rpc.Constants.EXPORTER_LISTENER_KEY;
 import static org.apache.dubbo.rpc.Constants.INVOKER_LISTENER_KEY;
 
@@ -56,7 +56,7 @@ public class ProtocolListenerWrapper implements Protocol {
 
     @Override
     public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
-        if (REGISTRY_PROTOCOL.equals(invoker.getUrl().getProtocol())) {
+        if (UrlUtils.isRegistry(invoker.getUrl())) {
             return protocol.export(invoker);
         }
         return new ListenerExporterWrapper<T>(protocol.export(invoker),
@@ -66,7 +66,7 @@ public class ProtocolListenerWrapper implements Protocol {
 
     @Override
     public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
-        if (REGISTRY_PROTOCOL.equals(url.getProtocol())) {
+        if (UrlUtils.isRegistry(url)) {
             return protocol.refer(type, url);
         }
         return new ListenerInvokerWrapper<T>(protocol.refer(type, url),


[dubbo] 04/13: Merge branch 'cloud-native' of https://github.com/apache/dubbo into cloud-native

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 0c33f3908bf63c12c9394aa85a3edf09998abb32
Merge: 2eaa132 4549e02
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Aug 12 17:00:22 2019 +0800

    Merge branch 'cloud-native' of https://github.com/apache/dubbo into cloud-native

 .../org/apache/dubbo/bootstrap/DubboBootstrap.java |  5 +-
 .../DynamicConfigurationServiceNameMapping.java    |  6 +-
 .../apache/dubbo/metadata/MetadataConstants.java   | 12 ++++
 .../org/apache/dubbo/metadata/MetadataService.java |  4 +-
 .../org/apache/dubbo/metadata/MetadataUtil.java    |  8 +--
 .../dubbo/metadata/WritableMetadataService.java    |  2 +-
 .../dubbo/metadata/report/MetadataReport.java      | 13 ++--
 .../metadata/report/MetadataReportInstance.java    | 53 ++++++++++++++
 .../BaseApplicationMetadataIdentifier.java         | 50 ++++++++++++++
 .../identifier/BaseServiceMetadataIdentifier.java  | 69 +++++++++++++++++++
 .../report/identifier/MetadataIdentifier.java      | 49 ++-----------
 .../identifier/ServiceMetadataIdentifier.java      | 51 ++++++++++++++
 .../identifier/SubscriberMetadataIdentifier.java   | 55 +++++++++++++++
 .../report/support/AbstractMetadataReport.java     | 38 ++++++----
 .../store/InMemoryWritableMetadataService.java     |  4 +-
 .../store/RemoteWritableMetadataService.java       | 80 ++++------------------
 .../report/identifier/MetadataIdentifierTest.java  | 12 ++--
 .../support/AbstractMetadataReportFactoryTest.java | 15 ++--
 .../report/support/AbstractMetadataReportTest.java | 34 ++++++---
 .../store/RemoteWritableMeatadataServiceTest.java  |  3 +-
 .../metadata/test/JTestMetadataReport4Test.java    | 13 +++-
 .../store/consul/ConsulMetadataReport.java         | 13 +++-
 .../metadata/store/etcd/EtcdMetadataReport.java    | 13 +++-
 .../metadata/store/nacos/NacosMetadataReport.java  | 13 +++-
 .../metadata/store/redis/RedisMetadataReport.java  | 17 +++--
 .../store/zookeeper/ZookeeperMetadataReport.java   | 13 +++-
 dubbo-registry/dubbo-registry-api/pom.xml          |  5 --
 .../CompositeMetadataServiceURLBuilder.java        |  1 +
 .../metadata/RefreshServiceMetadataCustomizer.java |  2 +-
 .../proxy/BaseMetadataServiceProxyFactory.java     | 23 +++++++
 .../proxy/DefaultMetadataServiceProxyFactory.java  |  7 +-
 .../metadata/{ => proxy}/MetadataServiceProxy.java | 15 ++--
 .../metadata/proxy/RemoteMetadataServiceProxy.java | 71 +++++++++++++++++++
 .../proxy/RemoteMetadataServiceProxyFactory.java   |  6 +-
 34 files changed, 570 insertions(+), 205 deletions(-)



[dubbo] 05/13: consul service discovery complement

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 705ee975717e5e5dacfc9f8db8c02abb74e66e14
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Aug 12 17:25:31 2019 +0800

    consul service discovery complement
---
 .../registry/consul/ConsulServiceDiscovery.java    | 28 ++++++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java b/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java
index ce7efc6..503823a 100644
--- a/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java
+++ b/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java
@@ -21,10 +21,12 @@ import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.NamedThreadFactory;
 import org.apache.dubbo.event.EventListener;
+import org.apache.dubbo.registry.client.DefaultServiceInstance;
 import org.apache.dubbo.registry.client.ServiceDiscovery;
 import org.apache.dubbo.registry.client.ServiceInstance;
 import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent;
 import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener;
+import org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils;
 
 import com.ecwid.consul.v1.ConsulClient;
 import com.ecwid.consul.v1.QueryParams;
@@ -36,6 +38,7 @@ import com.ecwid.consul.v1.health.model.HealthService;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
@@ -67,6 +70,7 @@ public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<S
             new NamedThreadFactory("dubbo-consul-notifier", true));
     private TtlScheduler ttlScheduler;
     private long checkPassInterval;
+    private URL url;
 
     public ConsulServiceDiscovery(URL url) {
         String host = url.getHost();
@@ -74,6 +78,7 @@ public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<S
         checkPassInterval = url.getParameter(CHECK_PASS_INTERVAL, DEFAULT_CHECK_PASS_INTERVAL);
         client = new ConsulClient(host, port);
         ttlScheduler = new TtlScheduler(checkPassInterval, client);
+        this.url = url;
     }
 
     @Override
@@ -122,9 +127,23 @@ public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<S
 
     @Override
     public List<ServiceInstance> getInstances(String serviceName) throws NullPointerException {
-        List<ServiceInstance> instances;
-        Response<List<HealthService>> response = getHealthServices(serviceName, -1, buildWatchTimeout(url));
-        urls = convert(response.getValue(), url);
+        Response<List<HealthService>> response = getHealthServices(serviceName, -1, buildWatchTimeout());
+        return convert(response.getValue());
+    }
+
+    private List<ServiceInstance> convert(List<HealthService> services) {
+        return services.stream()
+                .map(HealthService::getService)
+                .filter(service -> Objects.nonNull(service) && service.getMeta().containsKey(ServiceInstanceMetadataUtils.METADATA_SERVICE_URL_PARAMS_KEY))
+                .map(service -> {
+                    ServiceInstance instance = new DefaultServiceInstance(
+                            service.getService(),
+                            service.getAddress(),
+                            service.getPort());
+                    instance.getMetadata().putAll(service.getMeta());
+                    return instance;
+                })
+                .collect(Collectors.toList());
     }
 
     private Response<List<HealthService>> getHealthServices(String service, long index, int watchTimeout) {
@@ -170,11 +189,10 @@ public class ConsulServiceDiscovery implements ServiceDiscovery, EventListener<S
         return check;
     }
 
-    private int buildWatchTimeout(URL url) {
+    private int buildWatchTimeout() {
         return url.getParameter(WATCH_TIMEOUT, DEFAULT_WATCH_TIMEOUT) / 1000;
     }
 
-
     private class ConsulNotifier implements Runnable {
         private ServiceInstance serviceInstance;
         private long consulIndex;


[dubbo] 07/13: support old registry model and new registry model

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 591e45a36e597d12a7fa09ca5687f00af035c058
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Aug 12 19:44:38 2019 +0800

    support old registry model and new registry model
---
 .../registry/support/AbstractRegistryFactory.java  | 47 +++++++++++++++-------
 1 file changed, 32 insertions(+), 15 deletions(-)

diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
index 0458ada..70e7597 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
@@ -47,9 +47,12 @@ public abstract class AbstractRegistryFactory implements RegistryFactory {
     // The lock for the acquisition process of the registry
     private static final ReentrantLock LOCK = new ReentrantLock();
 
-    // Registry Collection Map<RegistryAddress, Registry>
+    // Registry Collection Map<RegistryAddress, ServiceOrientedRegistry>
     private static final Map<String, Registry> REGISTRIES = new HashMap<>();
 
+    // Registry Collection Map<RegistryAddress, Registry>
+    private static final Map<String, Registry> COMPATIBLE_REGISTRIES = new HashMap<>();
+
     /**
      * Get all registries
      *
@@ -94,28 +97,42 @@ public abstract class AbstractRegistryFactory implements RegistryFactory {
         // Lock the registry access process to ensure a single instance of the registry
         LOCK.lock();
         try {
-            Registry registry = REGISTRIES.get(key);
-            if (registry != null) {
-                return registry;
-            }
-            // creates an instance of ServiceOrientedRegistry if supported
-            // since 2.7.4
-            registry = ServiceOrientedRegistry.create(url);
-            if (registry == null) { // If not supported, create the default Registry
+            boolean isServiceOriented = ServiceOrientedRegistry.supports(url);
+            if (isServiceOriented) {
+                Registry registry = REGISTRIES.get(key);
+                if (registry != null) {
+                    return registry;
+                }
                 //create registry by spi/ioc
-                registry = createRegistry(url);
-            }
-            if (registry == null) {
-                throw new IllegalStateException("Can not create registry " + url);
+                registry = ServiceOrientedRegistry.create(url);
+                if (registry == null) {
+                    throw new IllegalStateException("Can not service-oriented registry " + url);
+                }
+                REGISTRIES.put(key, registry);
+                return registry;
+            } else {
+                return getCompatibleRegistry(key, url);
             }
-            REGISTRIES.put(key, registry);
-            return registry;
         } finally {
             // Release the lock
             LOCK.unlock();
         }
     }
 
+    private Registry getCompatibleRegistry(String key, URL url) {
+        Registry registry = COMPATIBLE_REGISTRIES.get(key);
+        if (registry != null) {
+            return registry;
+        }
+        //create registry by spi/ioc
+        registry = createRegistry(url);
+        if (registry == null) {
+            throw new IllegalStateException("Can not create registry " + url);
+        }
+        COMPATIBLE_REGISTRIES.put(key, registry);
+        return registry;
+    }
+
     protected abstract Registry createRegistry(URL url);
 
 }


[dubbo] 11/13: demos

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 96786d8a9a61970a8793fa3990e14e6f31cc526b
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Aug 13 20:14:09 2019 +0800

    demos
---
 .../bootstrap/DubboServiceConsumerBootstrap.java    |  6 +++---
 .../bootstrap/DubboServiceProvider2Bootstrap.java   |  6 +++---
 .../bootstrap/DubboServiceProviderBootstrap.java    |  8 ++++----
 .../DubboInterfaceConsumerBootstrap.java}           | 21 +++++++++++++++------
 .../apache/dubbo/bootstrap/rest/UserService.java    |  2 --
 .../dubbo/bootstrap/rest/UserServiceImpl.java       |  6 ------
 6 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java
index def1d07..f082192 100644
--- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java
@@ -32,9 +32,9 @@ public class DubboServiceConsumerBootstrap {
         new DubboBootstrap()
                 .application("dubbo-consumer-demo")
                 // Zookeeper
-//                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service&subscribed-services=dubbo-provider-demo"))
+                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry.type=service&subscribed.services=dubbo-provider-demo"))
                 // Nacos
-                .registry("consul", builder -> builder.address("consul://127.0.0.1:8500?registry-type=service&subscribed-services=dubbo-provider-demo"))
+//                .registry("consul", builder -> builder.address("consul://127.0.0.1:8500?registry.type=service&subscribed.services=dubbo-provider-demo").group("namespace1"))
                 .reference("echo", builder -> builder.interfaceClass(EchoService.class).protocol("dubbo"))
                 .reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest"))
                 .onlyRegisterProvider(true)
@@ -43,7 +43,7 @@ public class DubboServiceConsumerBootstrap {
 
         ConfigManager configManager = ConfigManager.getInstance();
 
-        ReferenceConfig<EchoService> referenceConfig = configManager.getReferenceConfig("ref");
+        ReferenceConfig<EchoService> referenceConfig = configManager.getReferenceConfig("echo");
 
         EchoService echoService = referenceConfig.get();
 
diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProvider2Bootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProvider2Bootstrap.java
index cc2948e..ad87adb 100644
--- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProvider2Bootstrap.java
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProvider2Bootstrap.java
@@ -27,10 +27,10 @@ public class DubboServiceProvider2Bootstrap {
         new DubboBootstrap()
                 .application("dubbo-provider-demo")
                 // Zookeeper in service registry type
-                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service"))
+                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry.type=service"))
                 // Nacos
-//                .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service"))
-//                .registry(RegistryBuilder.newBuilder().address("etcd3://127.0.0.1:2379?registry-type=service").build())
+//                .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry.type=service"))
+//                .registry(RegistryBuilder.newBuilder().address("etcd3://127.0.0.1:2379?registry.type=service").build())
                 .protocol(builder -> builder.port(20885).name("dubbo"))
                 .service(builder -> builder.id("test").interfaceClass(EchoService.class).ref(new EchoServiceImpl()))
                 .start()
diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
index 2639d6b..dd2060c 100644
--- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
@@ -47,7 +47,7 @@ public class DubboServiceProviderBootstrap {
 
         RegistryConfig serviceRegistry = new RegistryConfig();
         serviceRegistry.setId("serviceRegistry");
-        serviceRegistry.setAddress("zookeeper://127.0.0.1:2181?registry-type=service");
+        serviceRegistry.setAddress("zookeeper://127.0.0.1:2181?registry.type=service");
 
         ServiceConfig<EchoService> echoService = new ServiceConfig<>();
         echoService.setInterface(EchoService.class.getName());
@@ -64,11 +64,11 @@ public class DubboServiceProviderBootstrap {
         new DubboBootstrap()
                 .application("dubbo-provider-demo")
                 // Zookeeper in service registry type
-//                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service"))
+//                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry.type=service"))
                 // Nacos
-//                .registry("zookeeper", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service"))
+//                .registry("zookeeper", builder -> builder.address("nacos://127.0.0.1:8848?registry.type=service"))
                 .registries(Arrays.asList(interfaceRegistry, serviceRegistry))
-//                .registry(RegistryBuilder.newBuilder().address("consul://127.0.0.1:8500?registry-type=service").build())
+//                .registry(RegistryBuilder.newBuilder().address("consul://127.0.0.1:8500?registry.type=service").build())
                 .protocol(builder -> builder.port(-1).name("dubbo"))
                 .service(echoService)
                 .service(userService)
diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/compatible/DubboInterfaceConsumerBootstrap.java
similarity index 68%
copy from dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java
copy to dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/compatible/DubboInterfaceConsumerBootstrap.java
index def1d07..59a8fb1 100644
--- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/compatible/DubboInterfaceConsumerBootstrap.java
@@ -14,10 +14,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.dubbo.bootstrap;
+package org.apache.dubbo.bootstrap.compatible;
 
+import org.apache.dubbo.bootstrap.DubboBootstrap;
+import org.apache.dubbo.bootstrap.EchoService;
 import org.apache.dubbo.bootstrap.rest.UserService;
 import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
 import org.apache.dubbo.config.context.ConfigManager;
 
 /**
@@ -25,16 +28,19 @@ import org.apache.dubbo.config.context.ConfigManager;
  *
  * @since 2.7.4
  */
-public class DubboServiceConsumerBootstrap {
+public class DubboInterfaceConsumerBootstrap {
 
     public static void main(String[] args) throws Exception {
+        RegistryConfig interfaceRegistry = new RegistryConfig();
+        interfaceRegistry.setId("interfaceRegistry");
+        interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181");
 
         new DubboBootstrap()
                 .application("dubbo-consumer-demo")
                 // Zookeeper
-//                .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service&subscribed-services=dubbo-provider-demo"))
+                .registry(interfaceRegistry)
                 // Nacos
-                .registry("consul", builder -> builder.address("consul://127.0.0.1:8500?registry-type=service&subscribed-services=dubbo-provider-demo"))
+//                .registry("consul", builder -> builder.address("consul://127.0.0.1:8500?registry.type=service&subscribed.services=dubbo-provider-demo"))
                 .reference("echo", builder -> builder.interfaceClass(EchoService.class).protocol("dubbo"))
                 .reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest"))
                 .onlyRegisterProvider(true)
@@ -43,13 +49,16 @@ public class DubboServiceConsumerBootstrap {
 
         ConfigManager configManager = ConfigManager.getInstance();
 
-        ReferenceConfig<EchoService> referenceConfig = configManager.getReferenceConfig("ref");
-
+        ReferenceConfig<EchoService> referenceConfig = configManager.getReferenceConfig("echo");
         EchoService echoService = referenceConfig.get();
 
+        ReferenceConfig<UserService> referenceConfig1 = configManager.getReferenceConfig("user");
+        UserService userService = referenceConfig1.get();
+
         for (int i = 0; i < 500; i++) {
             Thread.sleep(2000L);
             System.out.println(echoService.echo("Hello,World"));
+            System.out.println(userService.getUser(1L));
         }
 
     }
diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserService.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserService.java
index 514a0bf..3d18f86 100644
--- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserService.java
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserService.java
@@ -42,6 +42,4 @@ public interface UserService {
     @Path("{id : \\d+}")
     @ApiOperation(value = "getUser")
     User getUser(@ApiParam(value = "id") @PathParam("id") Long id);
-
-    Long registerUser(User user);
 }
diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserServiceImpl.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserServiceImpl.java
index 01259eb..7439c53 100644
--- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserServiceImpl.java
+++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/rest/UserServiceImpl.java
@@ -29,10 +29,4 @@ public class UserServiceImpl implements UserService {
         return new User(id, "username" + id);
     }
 
-
-    @Override
-    public Long registerUser(User user) {
-//        System.out.println("Username is " + user.getName());
-        return idGen.incrementAndGet();
-    }
 }


[dubbo] 09/13: Merge branch 'cloud-native' of https://github.com/apache/dubbo into cloud-native

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 9fdbad3537060dae8d221af3d4ffdae4c77ed7f2
Merge: a80f6fc 932cace
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Aug 12 19:45:45 2019 +0800

    Merge branch 'cloud-native' of https://github.com/apache/dubbo into cloud-native

 .../apache/dubbo/config/context/ConfigManager.java | 30 ++++++++++------------
 1 file changed, 14 insertions(+), 16 deletions(-)


[dubbo] 13/13: Merge remote-tracking branch 'origin/cloud-native' into cloud-native

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 36e1a1c0acf1625fa16204f1b4eeb8f45abfbd81
Merge: c8ca5b6 733473f
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Aug 13 20:30:53 2019 +0800

    Merge remote-tracking branch 'origin/cloud-native' into cloud-native
    
    # Conflicts:
    #	dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java
    #	dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java

 .../org/apache/dubbo/bootstrap/DubboBootstrap.java |  10 +-
 .../org/apache/dubbo/config/AbstractConfig.java    |   3 +-
 .../apache/dubbo/config/context/ConfigManager.java | 135 ++++++++-------
 .../dubbo/config/context/ConfigManagerTest.java    | 186 ++++++++++++++++++++-
 .../apache/dubbo/metadata/MetadataConstants.java   |   1 +
 .../identifier/BaseServiceMetadataIdentifier.java  |   3 +
 .../identifier/ServiceMetadataIdentifier.java      |  10 +-
 .../report/support/AbstractMetadataReport.java     |   4 +-
 .../report/support/AbstractMetadataReportTest.java |   4 +-
 .../metadata/test/JTestMetadataReport4Test.java    |   2 +-
 .../store/consul/ConsulMetadataReport.java         |   2 +-
 .../metadata/store/etcd/EtcdMetadataReport.java    |   2 +-
 .../metadata/store/nacos/NacosMetadataReport.java  |   2 +-
 .../metadata/store/redis/RedisMetadataReport.java  |   2 +-
 .../store/zookeeper/ZookeeperMetadataReport.java   |  14 +-
 .../metadata/RefreshServiceMetadataCustomizer.java |   6 +-
 .../proxy/BaseMetadataServiceProxyFactory.java     |   3 +-
 .../metadata/proxy/RemoteMetadataServiceProxy.java |   4 +-
 .../registry/service/ServiceOrientedRegistry.java  |   2 +
 19 files changed, 301 insertions(+), 94 deletions(-)



[dubbo] 02/13: exclude injvm and registry protocol

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit e9a9e4711ea7b82f4c3a164c37059570ab391aaf
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Aug 12 16:52:28 2019 +0800

    exclude injvm and registry protocol
---
 .../src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java b/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java
index 4189238..457116c 100644
--- a/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java
+++ b/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java
@@ -773,14 +773,19 @@ public class DubboBootstrap {
     private String findOneProtocolForServiceInstance(Set<String> protocols) {
         String result = null;
         for (String protocol : protocols) {
-            if ("rest".equals(protocol)) {
+            if ("rest".equalsIgnoreCase(protocol)) {
                 result = protocol;
                 break;
             }
         }
 
         if (result == null) {
-            result = protocols.iterator().next();
+            for (String protocol : protocols) {
+                if (!"injvm".equalsIgnoreCase(protocol) && "registry".equalsIgnoreCase(protocol)) {
+                    result = protocol;
+                    break;
+                }
+            }
         }
         return result;
     }


[dubbo] 06/13: Merge remote-tracking branch 'origin/cloud-native' into cloud-native

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit eb62f48a3f5e25c8b686ec2a9a8fe80a7f2d0f94
Merge: 705ee97 b2f3307
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Aug 12 17:26:12 2019 +0800

    Merge remote-tracking branch 'origin/cloud-native' into cloud-native
    
    # Conflicts:
    #	dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscovery.java

 .../configcenter/AbstractDynamicConfiguration.java |  52 ++++--
 .../config/configcenter/DynamicConfiguration.java  |   3 +
 .../file/FileSystemDynamicConfiguration.java       | 101 +++---------
 .../org/apache/dubbo/config/AbstractConfig.java    |  15 ++
 .../apache/dubbo/config/context/ConfigManager.java | 182 ++++++++++++---------
 .../ConfigurableMetadataServiceExporter.java       |   1 -
 .../dubbo/metadata/MetadataServiceExporter.java    |   1 -
 .../dubbo-metadata-definition-protobuf/pom.xml     |   3 +-
 .../metadata/RefreshServiceMetadataCustomizer.java |   1 -
 .../registry/consul/AbstractConsulRegistry.java    |   4 -
 .../dubbo/registry/etcd/EtcdServiceDiscovery.java  |   1 -
 11 files changed, 192 insertions(+), 172 deletions(-)