You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/09/17 02:57:18 UTC

[GitHub] chickenlj closed pull request #2160: [Dubbo-2030] A basically running demo implementation for introducing dynamic configuration to Dubbo.

chickenlj closed pull request #2160: [Dubbo-2030] A basically running demo implementation for introducing dynamic configuration to Dubbo.
URL: https://github.com/apache/incubator-dubbo/pull/2160
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bom/pom.xml b/bom/pom.xml
index 96efb4a098..06ec3f7d0f 100644
--- a/bom/pom.xml
+++ b/bom/pom.xml
@@ -93,6 +93,11 @@
                 <artifactId>dubbo-config-spring</artifactId>
                 <version>${project.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-config-dynamic</artifactId>
+                <version>${project.version}</version>
+            </dependency>
             <dependency>
                 <groupId>org.apache.dubbo</groupId>
                 <artifactId>dubbo-filter-cache</artifactId>
diff --git a/dubbo-cluster/pom.xml b/dubbo-cluster/pom.xml
index 42941d4db6..d987afb2bf 100644
--- a/dubbo-cluster/pom.xml
+++ b/dubbo-cluster/pom.xml
@@ -34,5 +34,10 @@
             <artifactId>dubbo-rpc-api</artifactId>
             <version>${project.parent.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-config-dynamic</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Router.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Router.java
index 47aa2515a3..43410b79ae 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Router.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Router.java
@@ -22,6 +22,7 @@
 import org.apache.dubbo.rpc.RpcException;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * Router. (SPI, Prototype, ThreadSafe)
@@ -32,7 +33,6 @@
  * @see org.apache.dubbo.rpc.cluster.Directory#list(Invocation)
  */
 public interface Router extends Comparable<Router> {
-
     /**
      * get the router url.
      *
@@ -51,4 +51,20 @@
      */
     <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException;
 
+    default <T> Map<String, List<Invoker<T>>> preRoute(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
+        return null;
+    }
+
+    default boolean isRuntime() {
+        return true;
+    }
+
+    default String getKey() {
+        return "";
+    }
+
+    default boolean isForce() {
+        return false;
+    }
+
 }
\ No newline at end of file
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
new file mode 100644
index 0000000000..dda01954e8
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
@@ -0,0 +1,107 @@
+/*
+ * 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.rpc.cluster;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.utils.CollectionUtils;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcInvocation;
+import org.apache.dubbo.rpc.cluster.router.InvokerTreeCache;
+import org.apache.dubbo.rpc.cluster.router.TreeNode;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ *
+ */
+public class RouterChain<T> {
+
+    List<Invoker<T>> fullInvokers;
+
+    private InvokerTreeCache<T> treeCache;
+
+    List<Router> routers;
+
+    public static <T> RouterChain<T> buildChain(DynamicConfiguration dynamicConfiguration) {
+        List<RouterFactory> extensionFactories = ExtensionLoader.getExtensionLoader(RouterFactory.class).getActivateExtension(dynamicConfiguration.getUrl(), (String[]) null);
+        List<Router> routers = extensionFactories.stream().map(factory -> factory.getRouter(dynamicConfiguration)).collect(Collectors.toList());
+        return new RouterChain<>(routers);
+    }
+
+    public RouterChain(List<Router> routers) {
+        this.routers = routers;
+    }
+
+
+    public void addRouter(Router router) {
+        this.routers.add(router);
+    }
+
+    public void sort() {
+
+    }
+
+    /**
+     * @param methodInvokers
+     * @param url
+     * @param invocation     TODO has no been used yet
+     */
+    public void preRoute(Map<String, List<Invoker<T>>> methodInvokers, URL url, Invocation invocation) {
+        if (CollectionUtils.isEmpty(routers)) {
+            return;
+        }
+        TreeNode root = treeCache.buildTree();
+        Router router = routers.get(0);
+        methodInvokers.forEach((method, invokers) -> {
+            TreeNode<T> node = new TreeNode<>("method", method, invokers, true);
+            root.addChild(node);
+            Invocation invocation1 = new RpcInvocation(method, new Class<?>[0], new Object[0]);
+            routeeee(router, 1, root, router.preRoute(invokers, url, invocation1), url, invocation1);
+        });
+    }
+
+    private void routeeee(Router router, int i, TreeNode parentNode, Map<String, List<Invoker<T>>> invokers, URL url, Invocation invocation) {
+        invokers.forEach((routerValue, list) -> {
+            TreeNode<T> node = new TreeNode<>(router.getKey(), routerValue, list, router.isForce());
+            parentNode.addChild(node);
+            Router nextRouter = routers.get(i);
+            if (CollectionUtils.isNotEmpty(list)) {
+                routeeee(nextRouter, i + 1, node, nextRouter.preRoute(list, url, invocation), url, invocation);
+            }
+        });
+    }
+
+    public List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) {
+        // TODO will calculate every time
+        List<Invoker<T>> finalInvokers = treeCache.getInvokers(treeCache.getTree(), url, invocation);
+        for (Router router : routers) {
+            if (router.isRuntime()) {
+                finalInvokers = router.route(finalInvokers, url, invocation);
+            }
+        }
+        return finalInvokers;
+    }
+
+    public void notifyFullInvokers(Map<String, List<Invoker<T>>> invokers, URL url) {
+        preRoute(invokers, url, null);
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterFactory.java
index 679b9fe589..287ec7153a 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterFactory.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterFactory.java
@@ -19,6 +19,7 @@
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.extension.Adaptive;
 import org.apache.dubbo.common.extension.SPI;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
 import org.apache.dubbo.rpc.Invocation;
 
 /**
@@ -41,4 +42,7 @@
     @Adaptive("protocol")
     Router getRouter(URL url);
 
+    default Router getRouter(DynamicConfiguration dynamicConfiguration) {
+        return null;
+    }
 }
\ No newline at end of file
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 085094df22..9bbdcf24cd 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
@@ -16,9 +16,7 @@
  */
 package org.apache.dubbo.rpc.cluster.directory;
 
-import org.apache.dubbo.common.Constants;
 import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.ExtensionLoader;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.rpc.Invocation;
@@ -26,11 +24,9 @@
 import org.apache.dubbo.rpc.RpcException;
 import org.apache.dubbo.rpc.cluster.Directory;
 import org.apache.dubbo.rpc.cluster.Router;
-import org.apache.dubbo.rpc.cluster.RouterFactory;
-import org.apache.dubbo.rpc.cluster.router.MockInvokersSelector;
+import org.apache.dubbo.rpc.cluster.RouterChain;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 /**
@@ -48,22 +44,22 @@
 
     private volatile URL consumerUrl;
 
-    private volatile List<Router> routers;
+    protected RouterChain<T> routerChain;
 
     public AbstractDirectory(URL url) {
         this(url, null);
     }
 
-    public AbstractDirectory(URL url, List<Router> routers) {
-        this(url, url, routers);
+    public AbstractDirectory(URL url, RouterChain<T> routerChain) {
+        this(url, url, routerChain);
     }
 
-    public AbstractDirectory(URL url, URL consumerUrl, List<Router> routers) {
+    public AbstractDirectory(URL url, URL consumerUrl, RouterChain<T> routerChain) {
         if (url == null)
             throw new IllegalArgumentException("url == null");
         this.url = url;
         this.consumerUrl = consumerUrl;
-        setRouters(routers);
+        setRouterChain(routerChain);
     }
 
     @Override
@@ -71,19 +67,16 @@ public AbstractDirectory(URL url, URL consumerUrl, List<Router> routers) {
         if (destroyed) {
             throw new RpcException("Directory already destroyed .url: " + getUrl());
         }
+
         List<Invoker<T>> invokers = doList(invocation);
-        List<Router> localRouters = this.routers; // local reference
-        if (localRouters != null && !localRouters.isEmpty()) {
-            for (Router router : localRouters) {
-                try {
-                    if (router.getUrl() == null || router.getUrl().getParameter(Constants.RUNTIME_KEY, false)) {
-                        invokers = router.route(invokers, getConsumerUrl(), invocation);
-                    }
-                } catch (Throwable t) {
-                    logger.error("Failed to execute router: " + getUrl() + ", cause: " + t.getMessage(), t);
-                }
-            }
+
+        try {
+            // runtime routers will be executed.
+            routerChain.route(invokers, getConsumerUrl(), invocation);
+        } catch (Throwable t) {
+            logger.error("Failed to execute router: " + getUrl() + ", cause: " + t.getMessage(), t);
         }
+
         return invokers;
     }
 
@@ -92,23 +85,24 @@ public URL getUrl() {
         return url;
     }
 
-    public List<Router> getRouters() {
-        return routers;
+    public RouterChain<T> getRouterChain() {
+        return routerChain;
+    }
+
+    public void setRouterChain(RouterChain<T> routerChain) {
+        this.routerChain = routerChain;
     }
 
-    protected void setRouters(List<Router> routers) {
+    protected void addRouters(List<Router> routers) {
         // copy list
-        routers = routers == null ? new ArrayList<Router>() : new ArrayList<Router>(routers);
-        // append url router
-        String routerkey = url.getParameter(Constants.ROUTER_KEY);
-        if (routerkey != null && routerkey.length() > 0) {
-            RouterFactory routerFactory = ExtensionLoader.getExtensionLoader(RouterFactory.class).getExtension(routerkey);
-            routers.add(routerFactory.getRouter(url));
-        }
-        // append mock invoker selector
-        routers.add(new MockInvokersSelector());
-        Collections.sort(routers);
-        this.routers = routers;
+        routers = routers == null ? new ArrayList<>() : new ArrayList<>(routers);
+        routers.forEach(this::addRouter);
+    }
+
+    protected void addRouter(Router router) {
+        routerChain.addRouter(router);
+        // FIXME append mock invoker selector
+//        routerChain.add(new MockInvokersSelector());
     }
 
     public URL getConsumerUrl() {
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java
index 47a0d12bc7..9367bdf75f 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java
@@ -20,13 +20,15 @@
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.cluster.Router;
+import org.apache.dubbo.rpc.cluster.RouterChain;
 
 import java.util.List;
 
 /**
  * StaticDirectory
  *
+ * FIXME We should add separate router rules for StaticDirectory, not use RouterChain in AbstractDirectory. For example, machineRoom rule only. Ask LVS team for help.
+ *
  */
 public class StaticDirectory<T> extends AbstractDirectory<T> {
 
@@ -36,16 +38,16 @@ public StaticDirectory(List<Invoker<T>> invokers) {
         this(null, invokers, null);
     }
 
-    public StaticDirectory(List<Invoker<T>> invokers, List<Router> routers) {
-        this(null, invokers, routers);
+    public StaticDirectory(List<Invoker<T>> invokers, RouterChain<T> routerChain) {
+        this(null, invokers, routerChain);
     }
 
     public StaticDirectory(URL url, List<Invoker<T>> invokers) {
         this(url, invokers, null);
     }
 
-    public StaticDirectory(URL url, List<Invoker<T>> invokers, List<Router> routers) {
-        super(url == null && invokers != null && !invokers.isEmpty() ? invokers.get(0).getUrl() : url, routers);
+    public StaticDirectory(URL url, List<Invoker<T>> invokers, RouterChain<T> routerChain) {
+        super(url == null && invokers != null && !invokers.isEmpty() ? invokers.get(0).getUrl() : url, routerChain);
         if (invokers == null || invokers.isEmpty())
             throw new IllegalArgumentException("invokers == null");
         this.invokers = invokers;
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/InvokerTreeCache.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/InvokerTreeCache.java
new file mode 100644
index 0000000000..784dca94b0
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/InvokerTreeCache.java
@@ -0,0 +1,71 @@
+/*
+ * 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.rpc.cluster.router;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ *
+ */
+public class InvokerTreeCache<T> {
+
+    TreeNode<T> tree;
+
+    public TreeNode buildTree() {
+        tree = new TreeNode<>();
+        return tree;
+    }
+
+    public List<Invoker<T>> getInvokers(TreeNode<T> node, URL url, Invocation invocation) {
+        if (node.getChildren() == null) {
+            return node.getInvokers();
+        }
+
+        if (tree.getChildren().size() == 1) {
+            return getInvokers(tree.getChildren().get(0), url, invocation);
+        }
+
+        TreeNode<T> failoverNode = null;
+        for (TreeNode<T> n : tree.getChildren()) {
+            String key = n.getConditionKey();
+            if (TreeNode.FAILOVER_KEY.equals(key)) {
+                failoverNode = n;
+                continue;
+            }
+            if (n.getConditionValue().equals(invocation.getAttachment(key, url.getParameter(key)))) {
+                if (n.getInvokers() != null || (n.getInvokers() == null && n.isForce()))
+                    return getInvokers(n, url, invocation);
+            }
+        }
+
+        if (failoverNode != null) {
+            return getInvokers(failoverNode, url, invocation);
+        }
+        return Collections.emptyList();
+    }
+
+
+    public TreeNode getTree() {
+        return tree;
+    }
+
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/MockInvokersSelector.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/MockInvokersSelector.java
index 0ca2a4997d..f775f899b2 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/MockInvokersSelector.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/MockInvokersSelector.java
@@ -18,13 +18,16 @@
 
 import org.apache.dubbo.common.Constants;
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.CollectionUtils;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.RpcException;
 import org.apache.dubbo.rpc.cluster.Router;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * A specific Router designed to realize mock feature.
@@ -49,6 +52,36 @@ else if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
         return invokers;
     }
 
+    @Override
+    public <T> Map<String, List<Invoker<T>>> preRoute(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
+        Map<String, List<Invoker<T>>> map = new HashMap<>();
+
+        if (CollectionUtils.isEmpty(invokers)) {
+            return map;
+        }
+
+        if (isRuntime()) {
+            map.put(TreeNode.FAILOVER_KEY, invokers);
+            return map;
+        }
+        return map;
+    }
+
+    @Override
+    public boolean isRuntime() {
+        return true;
+    }
+
+    @Override
+    public String getKey() {
+        return TreeNode.FAILOVER_KEY;
+    }
+
+    @Override
+    public boolean isForce() {
+        return false;
+    }
+
     private <T> List<Invoker<T>> getMockedInvokers(final List<Invoker<T>> invokers) {
         if (!hasMockProviders(invokers)) {
             return null;
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/TreeNode.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/TreeNode.java
new file mode 100644
index 0000000000..813a0c29f9
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/TreeNode.java
@@ -0,0 +1,103 @@
+/*
+ * 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.rpc.cluster.router;
+
+import org.apache.dubbo.common.utils.CollectionUtils;
+import org.apache.dubbo.rpc.Invoker;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ */
+public class TreeNode<T> {
+    public static final String FAILOVER_KEY = "failover";
+
+    private String conditionKey;
+    private String conditionValue;
+    private boolean force;
+    private List<Invoker<T>> invokers;
+    private List<TreeNode<T>> children;
+
+    public TreeNode() {
+        this.children = new ArrayList<>();
+    }
+
+    public TreeNode(String conditionKey, String conditionValue, List<Invoker<T>> invokers, boolean force) {
+        this.conditionKey = conditionKey;
+        this.conditionValue = conditionValue;
+        this.invokers = invokers;
+        this.force = force;
+        this.children = new ArrayList<>();
+    }
+
+    public void traverse() {
+
+    }
+
+    public void addChild(TreeNode child) {
+        children.add(child);
+    }
+
+    public boolean isLeaf() {
+        if (CollectionUtils.isEmpty(children)) {
+            return true;
+        }
+        return false;
+    }
+
+    public String getConditionKey() {
+        return conditionKey;
+    }
+
+    public void setConditionKey(String conditionKey) {
+        this.conditionKey = conditionKey;
+    }
+
+    public String getConditionValue() {
+        return conditionValue;
+    }
+
+    public void setConditionValue(String conditionValue) {
+        this.conditionValue = conditionValue;
+    }
+
+    public List<Invoker<T>> getInvokers() {
+        return invokers;
+    }
+
+    public void setInvokers(List<Invoker<T>> invokers) {
+        this.invokers = invokers;
+    }
+
+    public List<TreeNode<T>> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<TreeNode<T>> children) {
+        this.children = children;
+    }
+
+    public boolean isForce() {
+        return force;
+    }
+
+    public void setForce(boolean force) {
+        this.force = force;
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java
index af36757028..a2de676a1f 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.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.CollectionUtils;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.common.utils.UrlUtils;
@@ -27,6 +28,7 @@
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.RpcException;
 import org.apache.dubbo.rpc.cluster.Router;
+import org.apache.dubbo.rpc.cluster.router.TreeNode;
 
 import java.text.ParseException;
 import java.util.ArrayList;
@@ -45,19 +47,26 @@
 public class ConditionRouter implements Router, Comparable<Router> {
 
     private static final Logger logger = LoggerFactory.getLogger(ConditionRouter.class);
-    private static Pattern ROUTE_PATTERN = Pattern.compile("([&!=,]*)\\s*([^&!=,\\s]+)");
-    private final URL url;
-    private final int priority;
-    private final boolean force;
-    private final Map<String, MatchPair> whenCondition;
-    private final Map<String, MatchPair> thenCondition;
+    protected static Pattern ROUTE_PATTERN = Pattern.compile("([&!=,]*)\\s*([^&!=,\\s]+)");
+    protected URL url;
+    protected int priority;
+    protected boolean force;
+    protected Map<String, MatchPair> whenCondition;
+    protected Map<String, MatchPair> thenCondition;
+
+    protected ConditionRouter() {
+
+    }
 
     public ConditionRouter(URL url) {
         this.url = url;
         this.priority = url.getParameter(Constants.PRIORITY_KEY, 0);
         this.force = url.getParameter(Constants.FORCE_KEY, false);
+        init(url.getParameterAndDecoded(Constants.RULE_KEY));
+    }
+
+    protected void init(String rule) {
         try {
-            String rule = url.getParameterAndDecoded(Constants.RULE_KEY);
             if (rule == null || rule.trim().length() == 0) {
                 throw new IllegalArgumentException("Illegal route rule!");
             }
@@ -174,6 +183,37 @@ else if (",".equals(separator)) { // Should be seperateed by ','
         return invokers;
     }
 
+    @Override
+    public <T> Map<String, List<Invoker<T>>> preRoute(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
+        Map<String, List<Invoker<T>>> map = new HashMap<>();
+
+        if (CollectionUtils.isEmpty(invokers)) {
+            return map;
+        }
+
+        if (isRuntime()) {
+            map.put(TreeNode.FAILOVER_KEY, invokers);
+            return map;
+        }
+        return map;
+    }
+
+    @Override
+    public boolean isRuntime() {
+        // We always return true for previously defined Router, don't support cache.
+        return this.url.getParameter(Constants.RUNTIME_KEY, false);
+    }
+
+    @Override
+    public String getKey() {
+        return TreeNode.FAILOVER_KEY;
+    }
+
+    @Override
+    public boolean isForce() {
+        return force;
+    }
+
     @Override
     public URL getUrl() {
         return url;
@@ -229,7 +269,7 @@ private boolean matchCondition(Map<String, MatchPair> condition, URL url, URL pa
         return result;
     }
 
-    private static final class MatchPair {
+    protected static final class MatchPair {
         final Set<String> matches = new HashSet<String>();
         final Set<String> mismatches = new HashSet<String>();
 
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConditionRouterRule.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConditionRouterRule.java
new file mode 100644
index 0000000000..886468f92e
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConditionRouterRule.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.router.condition.config;
+
+/**
+ *
+ */
+public class ConditionRouterRule {
+    private String ruleBody;
+    private boolean runtime;
+    private boolean force;
+
+    public String getRuleBody() {
+        return ruleBody;
+    }
+
+    public void setRuleBody(String ruleBody) {
+        this.ruleBody = ruleBody;
+    }
+
+    public boolean isRuntime() {
+        return runtime;
+    }
+
+    public void setRuntime(boolean runtime) {
+        this.runtime = runtime;
+    }
+
+    public boolean isForce() {
+        return force;
+    }
+
+    public void setForce(boolean force) {
+        this.force = force;
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConditionRuleParser.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConditionRuleParser.java
new file mode 100644
index 0000000000..db90cc7152
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConditionRuleParser.java
@@ -0,0 +1,30 @@
+/*
+ * 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.rpc.cluster.router.condition.config;
+
+/**
+ *
+ */
+public class ConditionRuleParser {
+
+    public static ConditionRouterRule parse(String rawRule) {
+        ConditionRouterRule conditionRouterRule = new ConditionRouterRule();
+        conditionRouterRule.setRuleBody("host!=10.20.153.10,10.20.153.11=>");
+        return conditionRouterRule;
+    }
+
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConfigConditionRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConfigConditionRouter.java
new file mode 100644
index 0000000000..846e560698
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConfigConditionRouter.java
@@ -0,0 +1,102 @@
+/*
+ * 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.rpc.cluster.router.condition.config;
+
+import org.apache.dubbo.common.Constants;
+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.CollectionUtils;
+import org.apache.dubbo.config.dynamic.ConfigChangeEvent;
+import org.apache.dubbo.config.dynamic.ConfigurationListener;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.router.TreeNode;
+import org.apache.dubbo.rpc.cluster.router.condition.ConditionRouter;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ */
+public class ConfigConditionRouter extends ConditionRouter implements ConfigurationListener {
+    private static final Logger logger = LoggerFactory.getLogger(ConfigConditionRouter.class);
+    private DynamicConfiguration configuration;
+    private ConditionRouterRule routerRule;
+
+    public ConfigConditionRouter(URL url) {
+        super(url);
+    }
+
+    public ConfigConditionRouter(DynamicConfiguration configuration) {
+        this.configuration = configuration;
+        this.priority = -2;
+        this.force = false;
+        try {
+            String app = configuration.getUrl().getParameter(Constants.APPLICATION_KEY);
+            String rawRule = configuration.getConfig(app + Constants.ROUTERS_SUFFIX, "dubbo", this);
+            ConditionRouterRule routerRule = ConditionRuleParser.parse(rawRule);
+            init(routerRule.getRuleBody());
+        } catch (Exception e) {
+            throw new IllegalStateException(e.getMessage(), e);
+        }
+    }
+
+    @Override
+    public void process(ConfigChangeEvent event) {
+        String rawRule = event.getNewValue();
+        ConditionRouterRule routerRule = ConditionRuleParser.parse(rawRule);
+        init(routerRule.getRuleBody());
+    }
+
+    @Override
+    public <T> Map<String, List<Invoker<T>>> preRoute(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
+        Map<String, List<Invoker<T>>> map = new HashMap<>();
+
+        if (CollectionUtils.isEmpty(invokers)) {
+            return map;
+        }
+
+        if (isRuntime()) {
+            map.put(TreeNode.FAILOVER_KEY, invokers);
+            return map;
+        }
+
+        map.put(TreeNode.FAILOVER_KEY, route(invokers, url, invocation));
+
+        return map;
+    }
+
+    @Override
+    public boolean isRuntime() {
+        return routerRule.isRuntime();
+    }
+
+    @Override
+    public String getKey() {
+        return "";
+    }
+
+    @Override
+    public boolean isForce() {
+        return routerRule.isForce();
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConfigConditionRouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConfigConditionRouterFactory.java
new file mode 100644
index 0000000000..396b10b242
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ConfigConditionRouterFactory.java
@@ -0,0 +1,39 @@
+/*
+ * 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.rpc.cluster.router.condition.config;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
+import org.apache.dubbo.rpc.cluster.Router;
+import org.apache.dubbo.rpc.cluster.RouterFactory;
+
+/**
+ *
+ */
+@Activate
+public class ConfigConditionRouterFactory implements RouterFactory {
+    @Override
+    public Router getRouter(URL url) {
+        return null;
+    }
+
+    @Override
+    public Router getRouter(DynamicConfiguration dynamicConfiguration) {
+        return new ConfigConditionRouter(dynamicConfiguration);
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/GroupRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/GroupRouter.java
new file mode 100644
index 0000000000..8508f176dc
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/GroupRouter.java
@@ -0,0 +1,153 @@
+/*
+ * 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.rpc.cluster.router.group;
+
+import org.apache.dubbo.common.Constants;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.CollectionUtils;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.config.dynamic.ConfigChangeEvent;
+import org.apache.dubbo.config.dynamic.ConfigurationListener;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
+import org.apache.dubbo.config.dynamic.DynamicConfigurationFactory;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.Router;
+import org.apache.dubbo.rpc.cluster.router.TreeNode;
+import org.apache.dubbo.rpc.cluster.router.group.model.GroupRouterRule;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+/**
+ *
+ */
+public class GroupRouter implements Router, Comparable<Router>, ConfigurationListener {
+    private static final Logger logger = LoggerFactory.getLogger(GroupRouter.class);
+    private static final String GROUPRULE_DATAID = "global.routers";
+    private static final String ROUTE_GROUP = "route.group";
+    private static final String ROUTE_FAILOVER = "route.failover";
+    private int priority;
+    private URL url;
+    private DynamicConfiguration configuration;
+    private GroupRouterRule groupRouterRule;
+
+    public GroupRouter(URL url) {
+        this(ExtensionLoader.getExtensionLoader(DynamicConfigurationFactory.class).getAdaptiveExtension().getDynamicConfiguration(url));
+        this.url = url;
+    }
+
+    public GroupRouter(DynamicConfiguration configuration) {
+        this.priority = -1;
+        this.configuration = configuration;
+        init();
+    }
+
+    public void init() {
+        String rawRule = configuration.getConfig(GROUPRULE_DATAID, "dubbo", this);
+        this.groupRouterRule = GroupRuleParser.parse(rawRule);
+    }
+
+    @Override
+    public void process(ConfigChangeEvent event) {
+        String rawRule = event.getNewValue();
+        // remove, set groupRouterRule to null
+        // change, update groupRouterRule
+    }
+
+    @Override
+    public URL getUrl() {
+        return url;
+    }
+
+    @Override
+    public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
+        if (CollectionUtils.isEmpty(invokers)) {
+            return invokers;
+        }
+        List<Invoker<T>> result = invokers;
+        String routeGroup = StringUtils.isEmpty(invocation.getAttachment(ROUTE_GROUP)) ? url.getParameter(ROUTE_GROUP) : invocation.getAttachment(ROUTE_GROUP);
+        if (StringUtils.isNotEmpty(routeGroup)) {
+            String providerApp = invokers.get(0).getUrl().getParameter(Constants.APPLICATION_KEY);
+            List<String> ips = groupRouterRule.filter(routeGroup, providerApp);
+            if (CollectionUtils.isNotEmpty(ips)) {
+                result = filterInvoker(invokers, invoker -> ipMatches(invoker.getUrl(), ips));
+            } else {
+                result = filterInvoker(invokers, invoker -> invoker.getUrl().getParameter(ROUTE_GROUP).equals(routeGroup));
+            }
+        }
+        if (StringUtils.isEmpty(routeGroup) || (CollectionUtils.isEmpty(result) && url.getParameter(ROUTE_FAILOVER, true))) {
+            result = filterInvoker(invokers, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(ROUTE_GROUP)));
+        }
+        return result;
+    }
+
+    @Override
+    public <T> Map<String, List<Invoker<T>>> preRoute(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
+        Map<String, List<Invoker<T>>> map = new HashMap<>();
+
+        if (CollectionUtils.isEmpty(invokers)) {
+            return map;
+        }
+
+        if (isRuntime()) {
+            map.put(TreeNode.FAILOVER_KEY, invokers);
+            return map;
+        }
+
+        // FIXME Consider groupRouterRule
+        invokers.forEach(invoker -> {
+            String routeGroup = invoker.getUrl().getParameter(ROUTE_GROUP);
+            List<Invoker<T>> subInvokers = map.computeIfAbsent(routeGroup, k -> new ArrayList<>());
+            subInvokers.add(invoker);
+        });
+
+        return map;
+    }
+
+    @Override
+    public boolean isRuntime() {
+        return false;
+    }
+
+    public boolean isRuntime(Invocation invocation) {
+        return true;
+    }
+
+    private <T> List<Invoker<T>> filterInvoker(List<Invoker<T>> invokers, Predicate<Invoker<T>> predicate) {
+        return invokers.stream()
+                .filter(predicate)
+                .collect(Collectors.toList());
+    }
+
+    private boolean ipMatches(URL url, List<String> ips) {
+        return ips.contains(url.getHost());
+    }
+
+    @Override
+    public int compareTo(Router o) {
+        return 0;
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/GroupRouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/GroupRouterFactory.java
new file mode 100644
index 0000000000..761d02e922
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/GroupRouterFactory.java
@@ -0,0 +1,41 @@
+/*
+ * 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.rpc.cluster.router.group;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
+import org.apache.dubbo.rpc.cluster.Router;
+import org.apache.dubbo.rpc.cluster.RouterFactory;
+
+/**
+ *
+ */
+@Activate
+public class GroupRouterFactory implements RouterFactory {
+
+    public static final String NAME = "group";
+
+    @Override
+    public Router getRouter(URL url) {
+        return new GroupRouter(url);
+    }
+
+    public Router getRouter(DynamicConfiguration dynamicConfiguration) {
+        return new GroupRouter(dynamicConfiguration);
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/GroupRuleParser.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/GroupRuleParser.java
new file mode 100644
index 0000000000..86569565ed
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/GroupRuleParser.java
@@ -0,0 +1,29 @@
+/*
+ * 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.rpc.cluster.router.group;
+
+import org.apache.dubbo.rpc.cluster.router.group.model.GroupRouterRule;
+
+/**
+ *
+ */
+public class GroupRuleParser {
+
+    public static GroupRouterRule parse(String rawRule) {
+        return null;
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/model/GroupRouterRule.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/model/GroupRouterRule.java
new file mode 100644
index 0000000000..687a3fb945
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/group/model/GroupRouterRule.java
@@ -0,0 +1,28 @@
+/*
+ * 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.rpc.cluster.router.group.model;
+
+import java.util.List;
+
+/**
+ *
+ */
+public class GroupRouterRule {
+    public List<String> filter(String routeGroup, String app) {
+        return null;
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java
index 616432254a..c3f98155f3 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java
@@ -20,11 +20,13 @@
 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.CollectionUtils;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.RpcContext;
 import org.apache.dubbo.rpc.RpcException;
 import org.apache.dubbo.rpc.cluster.Router;
+import org.apache.dubbo.rpc.cluster.router.TreeNode;
 
 import javax.script.Bindings;
 import javax.script.Compilable;
@@ -34,6 +36,7 @@
 import javax.script.ScriptException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -114,6 +117,37 @@ public URL getUrl() {
         }
     }
 
+    @Override
+    public <T> Map<String, List<Invoker<T>>> preRoute(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
+        Map<String, List<Invoker<T>>> map = new HashMap<>();
+
+        if (CollectionUtils.isEmpty(invokers)) {
+            return map;
+        }
+
+        if (isRuntime()) {
+            map.put(TreeNode.FAILOVER_KEY, invokers);
+            return map;
+        }
+        return map;
+    }
+
+    @Override
+    public boolean isRuntime() {
+        // ignore config in url
+        return true;
+    }
+
+    @Override
+    public String getKey() {
+        return TreeNode.FAILOVER_KEY;
+    }
+
+    @Override
+    public boolean isForce() {
+        return url.getParameter(Constants.FORCE_KEY, false);
+    }
+
     @Override
     public int compareTo(Router o) {
         if (o == null || o.getClass() != ScriptRouter.class) {
diff --git a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory
index 0ada9c3be9..f8bd6990b5 100644
--- a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory
+++ b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.RouterFactory
@@ -1,3 +1,5 @@
 file=org.apache.dubbo.rpc.cluster.router.file.FileRouterFactory
 script=org.apache.dubbo.rpc.cluster.router.script.ScriptRouterFactory
-condition=org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory
\ No newline at end of file
+condition=org.apache.dubbo.rpc.cluster.router.condition.ConditionRouterFactory
+configcondition=org.apache.dubbo.rpc.cluster.router.condition.config.ConfigConditionRouterFactory
+group=org.apache.dubbo.rpc.cluster.router.group.GroupRouterFactory
\ No newline at end of file
diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterEngineTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterEngineTest.java
index 941e80cdd1..e596c74b05 100644
--- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterEngineTest.java
+++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterEngineTest.java
@@ -27,10 +27,10 @@
 import org.apache.dubbo.rpc.RpcResult;
 import org.apache.dubbo.rpc.cluster.Directory;
 import org.apache.dubbo.rpc.cluster.LoadBalance;
+import org.apache.dubbo.rpc.cluster.RouterChain;
 import org.apache.dubbo.rpc.cluster.RouterFactory;
 import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
 import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker;
-
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -159,7 +159,8 @@ private void initInvokers(URL url, boolean invoker1Status, boolean invoker2Statu
     }
 
     private void initDic(URL url) {
-        dic = new StaticDirectory<FileRouterEngineTest>(url, invokers, Arrays.asList(routerFactory.getRouter(url)));
+        RouterChain routerChain = new RouterChain(Arrays.asList(routerFactory.getRouter(url)));
+        dic = new StaticDirectory<FileRouterEngineTest>(url, invokers, routerChain);
     }
 
     static class MockClusterInvoker<T> extends AbstractClusterInvoker<T> {
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
index a1c8fac34c..6ad62975df 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
@@ -19,6 +19,7 @@
 
 import java.util.concurrent.ExecutorService;
 import java.util.regex.Pattern;
+
 /**
  * Constants
  */
@@ -44,8 +45,23 @@
 
     public static final String ROUTERS_CATEGORY = "routers";
 
+    public static final String DYNAMIC_ROUTERS_CATEGORY = "dynamicrouters";
+
     public static final String CONFIGURATORS_CATEGORY = "configurators";
 
+    public static final String DYNAMIC_CONFIGURATORS_CATEGORY = "dynamicconfigurators";
+    public static final String APP_DYNAMIC_CONFIGURATORS_CATEGORY = "appdynamicconfigurators";
+
+    public static final String CONFIGURATORS_SUFFIX = ".configurators";
+
+    public static final String ROUTERS_SUFFIX = ".routers";
+
+    public static final String CONFIG_TYPE_KEY = "config.type";
+    public static final String CONFIG_ADDRESS_KEY = "config.address";
+    public static final String CONFIG_ENV_KEY = "config.env";
+    public static final String CONFIG_CLUSTER_KEY = "config.cluster";
+    public static final String CONFIG_NAMESPACE_KEY = "config.namespace";
+
     public static final String DEFAULT_CATEGORY = PROVIDERS_CATEGORY;
 
     public static final String ENABLED_KEY = "enabled";
@@ -549,6 +565,8 @@
 
     public static final String OVERRIDE_PROTOCOL = "override";
 
+    public static final String CONFIG_PROTOCOL = "config";
+
     public static final String PRIORITY_KEY = "priority";
 
     public static final String RULE_KEY = "rule";
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
index b8e7bbf974..b965a6c8ce 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
@@ -757,6 +757,9 @@ private String createAdaptiveExtensionClassCode() {
         codeBuilder.append("\nimport ").append(ExtensionLoader.class.getName()).append(";");
         codeBuilder.append("\npublic class ").append(type.getSimpleName()).append("$Adaptive").append(" implements ").append(type.getCanonicalName()).append(" {");
 
+        codeBuilder.append("\nprivate static final org.apache.dubbo.common.logger.Logger logger = org.apache.dubbo.common.logger.LoggerFactory.getLogger(ExtensionLoader.class);");
+        codeBuilder.append("\nprivate java.util.concurrent.atomic.AtomicInteger count = new java.util.concurrent.atomic.AtomicInteger(0);\n");
+
         for (Method method : methods) {
             Class<?> rt = method.getReturnType();
             Class<?>[] pts = method.getParameterTypes();
@@ -893,8 +896,12 @@ private String createAdaptiveExtensionClassCode() {
                         type.getName(), Arrays.toString(value));
                 code.append(s);
 
-                s = String.format("\n%s extension = (%<s)%s.getExtensionLoader(%s.class).getExtension(extName);",
+                s = String.format("\n%s extension = null;\n try {\nextension = (%<s)%s.getExtensionLoader(%s.class).getExtension(extName);\n}catch(Exception e){\n",
                         type.getName(), ExtensionLoader.class.getSimpleName(), type.getName());
+                s += String.format("if (count.incrementAndGet() == 1) {\nlogger.warn(\"Failed to find extension named \" + extName + \" for type %s, will use default extension %s instead.\", e);\n}\n",
+                        type.getName(), defaultExtName);
+                s += String.format("extension = (%s)%s.getExtensionLoader(%s.class).getExtension(\"%s\");\n}",
+                        type.getName(), ExtensionLoader.class.getSimpleName(), type.getName(), defaultExtName);
                 code.append(s);
 
                 // return statement
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java
index a3d46a0895..9369939f83 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java
@@ -77,6 +77,10 @@
 
     private Boolean qosAcceptForeignIp;
 
+    // used for dynamic configuration
+    private String config;
+    private String address;
+
     // customized parameters
     private Map<String, String> parameters;
 
@@ -243,6 +247,24 @@ public void setQosAcceptForeignIp(Boolean qosAcceptForeignIp) {
         this.qosAcceptForeignIp = qosAcceptForeignIp;
     }
 
+    @Parameter(key = "config.type")
+    public String getConfig() {
+        return config;
+    }
+
+    public void setConfig(String config) {
+        this.config = config;
+    }
+
+    @Parameter(key = "config.address")
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
     public Map<String, String> getParameters() {
         return parameters;
     }
diff --git a/dubbo-config/dubbo-config-dynamic/pom.xml b/dubbo-config/dubbo-config-dynamic/pom.xml
new file mode 100644
index 0000000000..3243be6e84
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/pom.xml
@@ -0,0 +1,84 @@
+<!--
+  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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-config</artifactId>
+        <version>2.7.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>dubbo-config-dynamic</artifactId>
+    <packaging>jar</packaging>
+    <name>${project.artifactId}</name>
+    <description>The config api module of dubbo project</description>
+    <properties>
+        <skip_maven_deploy>false</skip_maven_deploy>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-common</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-remoting-zookeeper</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.ctrip.framework.apollo</groupId>
+            <artifactId>apollo-client</artifactId>
+            <version>1.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.netflix.archaius</groupId>
+            <artifactId>archaius-core</artifactId>
+            <version>0.7.6</version>
+        </dependency>
+        <dependency>
+            <groupId>com.netflix.archaius</groupId>
+            <artifactId>archaius-zookeeper</artifactId>
+            <version>0.7.6</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.curator</groupId>
+                    <artifactId>curator-client</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.curator</groupId>
+            <artifactId>curator-framework</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.curator</groupId>
+            <artifactId>curator-recipes</artifactId>
+            <version>2.12.0</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-configuration</groupId>
+            <artifactId>commons-configuration</artifactId>
+            <version>1.8</version>
+        </dependency>
+        <dependency>
+            <groupId>org.yaml</groupId>
+            <artifactId>snakeyaml</artifactId>
+            <version>1.20</version>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/AbstractDynamicConfiguration.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/AbstractDynamicConfiguration.java
new file mode 100644
index 0000000000..84129d6724
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/AbstractDynamicConfiguration.java
@@ -0,0 +1,61 @@
+/*
+ * 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.config.dynamic;
+
+import org.apache.dubbo.common.URL;
+
+/**
+ *
+ */
+public abstract class AbstractDynamicConfiguration implements DynamicConfiguration {
+    protected URL url;
+
+    public AbstractDynamicConfiguration() {
+    }
+
+    @Override
+    public void addListener(String key, ConfigurationListener listener) {
+
+    }
+
+    @Override
+    public String getConfig(String key, String group) {
+        return null;
+    }
+
+    @Override
+    public String getConfig(String key, String group, ConfigurationListener listener) {
+        return null;
+    }
+
+    @Override
+    public String getConfig(String key, String group, long timeout) {
+        return null;
+    }
+
+
+    public URL getUrl() {
+        return url;
+    }
+
+    public void setUrl(URL url) {
+        this.url = url;
+    }
+
+    protected abstract String getInternalProperty(String key, String group, long timeout);
+
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigChangeEvent.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigChangeEvent.java
new file mode 100644
index 0000000000..5993cd3927
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigChangeEvent.java
@@ -0,0 +1,70 @@
+/*
+ * 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.config.dynamic;
+
+/**
+ *
+ */
+public class ConfigChangeEvent {
+    private String key;
+    private String newValue;
+    private ConfigChangeType changeType;
+    private ConfigType type;
+
+    public ConfigChangeEvent(String key, String value, ConfigType type) {
+        this(key, value, type, ConfigChangeType.MODIFIED);
+    }
+
+    public ConfigChangeEvent(String key, String value, ConfigType type, ConfigChangeType changeType) {
+        this.key = key;
+        this.newValue = value;
+        this.type = type;
+        this.changeType = changeType;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getNewValue() {
+        return newValue;
+    }
+
+    public void setNewValue(String newValue) {
+        this.newValue = newValue;
+    }
+
+    public ConfigChangeType getChangeType() {
+        return changeType;
+    }
+
+    public void setChangeType(ConfigChangeType changeType) {
+        this.changeType = changeType;
+    }
+
+    public ConfigType getType() {
+        return type;
+    }
+
+    public void setType(ConfigType type) {
+        this.type = type;
+    }
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigChangeType.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigChangeType.java
new file mode 100644
index 0000000000..077d023772
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigChangeType.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.config.dynamic;
+
+/**
+ *
+ */
+public enum ConfigChangeType {
+    ADDED,
+    MODIFIED,
+    DELETED
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigType.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigType.java
new file mode 100644
index 0000000000..7073f94a07
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigType.java
@@ -0,0 +1,25 @@
+/*
+ * 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.config.dynamic;
+
+/**
+ *
+ */
+public enum ConfigType {
+    CONFIGURATORS,
+    ROUTERS
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigurationListener.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigurationListener.java
new file mode 100644
index 0000000000..3a51087935
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/ConfigurationListener.java
@@ -0,0 +1,29 @@
+/*
+ * 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.config.dynamic;
+
+import org.apache.dubbo.common.URL;
+
+/**
+ *
+ */
+public interface ConfigurationListener {
+
+    void process(ConfigChangeEvent event);
+
+    URL getUrl();
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/DynamicConfiguration.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/DynamicConfiguration.java
new file mode 100644
index 0000000000..8d05aca7c6
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/DynamicConfiguration.java
@@ -0,0 +1,42 @@
+/*
+ * 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.config.dynamic;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.SPI;
+
+/**
+ *
+ */
+@SPI("zookeeper")
+public interface DynamicConfiguration {
+
+    public void init();
+
+    URL getUrl();
+
+    void setUrl(URL url);
+
+    void addListener(String key, ConfigurationListener listener);
+
+    String getConfig(String key, String group);
+
+    String getConfig(String key, String group, long timeout);
+
+    String getConfig(String key, String group, ConfigurationListener listener);
+
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/DynamicConfigurationFactory.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/DynamicConfigurationFactory.java
new file mode 100644
index 0000000000..e2997d1c0d
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/DynamicConfigurationFactory.java
@@ -0,0 +1,33 @@
+/*
+ * 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.config.dynamic;
+
+import org.apache.dubbo.common.Constants;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.Adaptive;
+import org.apache.dubbo.common.extension.SPI;
+
+/**
+ *
+ */
+@SPI("nop")
+public interface DynamicConfigurationFactory {
+
+    @Adaptive({Constants.CONFIG_TYPE_KEY})
+    DynamicConfiguration getDynamicConfiguration(URL url);
+
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/apollo/ApolloDynamicConfiguration.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/apollo/ApolloDynamicConfiguration.java
new file mode 100644
index 0000000000..196581a84a
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/apollo/ApolloDynamicConfiguration.java
@@ -0,0 +1,137 @@
+/*
+ * 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.config.dynamic.support.apollo;
+
+import com.ctrip.framework.apollo.Config;
+import com.ctrip.framework.apollo.ConfigChangeListener;
+import com.ctrip.framework.apollo.ConfigService;
+import com.ctrip.framework.apollo.enums.PropertyChangeType;
+import com.ctrip.framework.apollo.model.ConfigChange;
+import com.ctrip.framework.apollo.model.ConfigChangeEvent;
+import org.apache.dubbo.common.Constants;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.config.dynamic.AbstractDynamicConfiguration;
+import org.apache.dubbo.config.dynamic.ConfigChangeType;
+import org.apache.dubbo.config.dynamic.ConfigType;
+import org.apache.dubbo.config.dynamic.ConfigurationListener;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ */
+public class ApolloDynamicConfiguration extends AbstractDynamicConfiguration {
+    private static final String APOLLO_ENV_KEY = "env";
+    private static final String APOLLO_ADDR_KEY = "apollo.meta";
+    private static final String APOLLO_CLUSTER_KEY = "apollo.cluster";
+    /**
+     * support two namespaces: application -> dubbo
+     */
+    private Config dubboConfig;
+    private Config appConfig;
+
+    public ApolloDynamicConfiguration() {
+
+    }
+
+    @Override
+    public void init() {
+        /**
+         * Instead of using Dubbo's configuration, I would suggest use the original configuration method Apollo provides.
+         */
+//        String configEnv = env.getCompositeConf().getString(ENV_KEY);
+//        String configCluster = env.getCompositeConf().getString(CLUSTER_KEY);
+        String configEnv = url.getParameter(Constants.CONFIG_ENV_KEY);
+        String configAddr = url.getAddress();
+        String configCluster = url.getParameter(Constants.CONFIG_CLUSTER_KEY);
+        if (configEnv != null) {
+            System.setProperty(APOLLO_ENV_KEY, configEnv);
+        }
+        if (StringUtils.isEmpty(configEnv) && !Constants.ANYHOST_VALUE.equals(configAddr)) {
+            System.setProperty(APOLLO_ADDR_KEY, configAddr);
+        }
+        if (configCluster != null) {
+            System.setProperty(APOLLO_CLUSTER_KEY, configCluster);
+        }
+
+        dubboConfig = ConfigService.getConfig("dubbo");
+        appConfig = ConfigService.getAppConfig();
+    }
+
+    @Override
+    public void addListener(String key, ConfigurationListener listener) {
+        Set<String> keys = new HashSet<>(1);
+        keys.add(key);
+        this.appConfig.addChangeListener(new ApolloListener(listener), keys);
+        this.dubboConfig.addChangeListener(new ApolloListener(listener), keys);
+    }
+
+    @Override
+    public String getConfig(String key, String group, ConfigurationListener listener) {
+        Set<String> keys = new HashSet<>(1);
+        keys.add(key);
+        this.appConfig.addChangeListener(new ApolloListener(listener), keys);
+        this.dubboConfig.addChangeListener(new ApolloListener(listener), keys);
+        return getInternalProperty(key, group, 0L);
+    }
+
+    @Override
+    protected String getInternalProperty(String key, String group, long timeout) {
+        String value = appConfig.getProperty(key, null);
+        if (value == null) {
+            value = dubboConfig.getProperty(key, null);
+        }
+
+        return value;
+    }
+
+    public ConfigChangeType getChangeType(PropertyChangeType changeType) {
+        if (changeType.equals(PropertyChangeType.DELETED)) {
+            return ConfigChangeType.DELETED;
+        }
+        return ConfigChangeType.MODIFIED;
+    }
+
+    private class ApolloListener implements ConfigChangeListener {
+        private ConfigurationListener listener;
+        private URL url;
+
+        public ApolloListener(ConfigurationListener listener) {
+            this(listener.getUrl(), listener);
+        }
+
+        public ApolloListener(URL url, ConfigurationListener listener) {
+            this.url = url;
+            this.listener = listener;
+        }
+
+        @Override
+        public void onChange(ConfigChangeEvent changeEvent) {
+            for (String key : changeEvent.changedKeys()) {
+                ConfigChange change = changeEvent.getChange(key);
+                if (change.getPropertyName().endsWith(Constants.CONFIGURATORS_SUFFIX)) {
+                    listener.process(new org.apache.dubbo.config.dynamic.ConfigChangeEvent(key, change.getNewValue(), ConfigType.CONFIGURATORS, getChangeType(change.getChangeType())));
+                } else if (change.getPropertyName().endsWith(Constants.ROUTERS_SUFFIX)) {
+                    listener.process(new org.apache.dubbo.config.dynamic.ConfigChangeEvent(key, change.getNewValue(), ConfigType.ROUTERS, getChangeType(change.getChangeType())));
+                }
+            }
+        }
+    }
+
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/apollo/ApolloDynamicConfigurationFactory.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/apollo/ApolloDynamicConfigurationFactory.java
new file mode 100644
index 0000000000..ef35b4b6ae
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/apollo/ApolloDynamicConfigurationFactory.java
@@ -0,0 +1,39 @@
+/*
+ * 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.config.dynamic.support.apollo;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
+import org.apache.dubbo.config.dynamic.DynamicConfigurationFactory;
+
+/**
+ *
+ */
+public class ApolloDynamicConfigurationFactory implements DynamicConfigurationFactory {
+
+    private DynamicConfiguration configuration;
+
+    @Override
+    public synchronized DynamicConfiguration getDynamicConfiguration(URL url) {
+        if (configuration == null) {
+            configuration = new ApolloDynamicConfiguration();
+            configuration.setUrl(url);
+            configuration.init();
+        }
+        return configuration;
+    }
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/archaius/ArchaiusDynamicConfiguration.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/archaius/ArchaiusDynamicConfiguration.java
new file mode 100644
index 0000000000..912eefa323
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/archaius/ArchaiusDynamicConfiguration.java
@@ -0,0 +1,123 @@
+/*
+ * 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.config.dynamic.support.archaius;
+
+import com.netflix.config.ConfigurationManager;
+import com.netflix.config.DynamicPropertyFactory;
+import com.netflix.config.DynamicStringProperty;
+import com.netflix.config.DynamicWatchedConfiguration;
+import org.apache.dubbo.common.Constants;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.config.dynamic.AbstractDynamicConfiguration;
+import org.apache.dubbo.config.dynamic.ConfigChangeEvent;
+import org.apache.dubbo.config.dynamic.ConfigChangeType;
+import org.apache.dubbo.config.dynamic.ConfigType;
+import org.apache.dubbo.config.dynamic.ConfigurationListener;
+import org.apache.dubbo.config.dynamic.support.archaius.sources.ZooKeeperConfigurationSource;
+
+/**
+ * Archaius supports various sources and it's extensiable: JDBC, ZK, Properties, ..., so should we make it extensiable?
+ */
+public class ArchaiusDynamicConfiguration extends AbstractDynamicConfiguration {
+
+    public ArchaiusDynamicConfiguration() {
+    }
+
+    @Override
+    public void init() {
+        //  String address = env.getCompositeConf().getString(ADDRESS_KEY);
+        //  String app = env.getCompositeConf().getString(APP_KEY);
+
+        String address = url.getAddress();
+        if (!address.equals(Constants.ANYHOST_VALUE)) {
+            System.setProperty(ZooKeeperConfigurationSource.ARCHAIUS_SOURCE_ADDRESS_KEY, address);
+        }
+        System.setProperty(ZooKeeperConfigurationSource.ARCHAIUS_CONFIG_ROOT_PATH_KEY, ZooKeeperConfigurationSource.DEFAULT_CONFIG_ROOT_PATH);
+
+        try {
+            ZooKeeperConfigurationSource zkConfigSource = new ZooKeeperConfigurationSource();
+            zkConfigSource.start();
+            DynamicWatchedConfiguration zkDynamicConfig = new DynamicWatchedConfiguration(zkConfigSource);
+            ConfigurationManager.install(zkDynamicConfig);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void addListener(String key, ConfigurationListener listener) {
+        DynamicStringProperty prop = DynamicPropertyFactory.getInstance()
+                .getStringProperty(key, null);
+        prop.addCallback(new ArchaiusListener(key, listener));
+    }
+
+    @Override
+    public String getConfig(String key, String group) {
+        return getConfig(key, group, null);
+    }
+
+    @Override
+    public String getConfig(String key, String group, ConfigurationListener listener) {
+        DynamicStringProperty prop = DynamicPropertyFactory.getInstance()
+                .getStringProperty(key, null);
+        if (listener != null) {
+            prop.addCallback(new ArchaiusListener(key, listener));
+        }
+        return prop.get();
+    }
+
+    @Override
+    protected String getInternalProperty(String key, String group, long timeout) {
+        return DynamicPropertyFactory.getInstance()
+                .getStringProperty(key, null)
+                .get();
+    }
+
+    private class ArchaiusListener implements Runnable {
+        private ConfigurationListener listener;
+        private URL url;
+        private String key;
+        private ConfigType type;
+
+        public ArchaiusListener(String key, ConfigurationListener listener) {
+            this.key = key;
+            this.listener = listener;
+            this.url = listener.getUrl();
+            if (key.endsWith(Constants.CONFIGURATORS_SUFFIX)) {
+                type = ConfigType.CONFIGURATORS;
+            } else if (key.endsWith(Constants.ROUTERS_SUFFIX)) {
+                type = ConfigType.ROUTERS;
+            }
+        }
+
+        @Override
+        public void run() {
+            DynamicStringProperty prop = DynamicPropertyFactory.getInstance()
+                    .getStringProperty(key, null);
+            String newValue = prop.get();
+            ConfigChangeEvent event = new ConfigChangeEvent(key, newValue, type);
+            if (StringUtils.isEmpty(newValue)) {
+                event.setChangeType(ConfigChangeType.DELETED);
+                listener.process(event);
+            } else {
+                event.setChangeType(ConfigChangeType.MODIFIED);
+                listener.process(event);
+            }
+        }
+    }
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/archaius/ArchaiusDynamicConfigurationFactory.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/archaius/ArchaiusDynamicConfigurationFactory.java
new file mode 100644
index 0000000000..20d0fb9f2e
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/archaius/ArchaiusDynamicConfigurationFactory.java
@@ -0,0 +1,39 @@
+/*
+ * 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.config.dynamic.support.archaius;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
+import org.apache.dubbo.config.dynamic.DynamicConfigurationFactory;
+
+/**
+ *
+ */
+public class ArchaiusDynamicConfigurationFactory implements DynamicConfigurationFactory {
+
+    private volatile DynamicConfiguration configuration;
+
+    @Override
+    public synchronized DynamicConfiguration getDynamicConfiguration(URL url) {
+        if (configuration == null) {
+            configuration = new ArchaiusDynamicConfiguration();
+            configuration.setUrl(url);
+            configuration.init();
+        }
+        return configuration;
+    }
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/archaius/sources/ZooKeeperConfigurationSource.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/archaius/sources/ZooKeeperConfigurationSource.java
new file mode 100644
index 0000000000..5dd364050e
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/archaius/sources/ZooKeeperConfigurationSource.java
@@ -0,0 +1,223 @@
+/*
+ * 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.config.dynamic.support.archaius.sources;
+
+import com.google.common.io.Closeables;
+import com.netflix.config.WatchedConfigurationSource;
+import com.netflix.config.WatchedUpdateListener;
+import com.netflix.config.WatchedUpdateResult;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.recipes.cache.ChildData;
+import org.apache.curator.framework.recipes.cache.TreeCache;
+import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
+import org.apache.curator.framework.recipes.cache.TreeCacheListener;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/**
+ *
+ */
+public class ZooKeeperConfigurationSource implements WatchedConfigurationSource, Closeable {
+    public static final String ARCHAIUS_SOURCE_ADDRESS_KEY = "archaius.zk.address";
+    public static final String ARCHAIUS_CONFIG_ROOT_PATH_KEY = "archaius.zk.rootpath";
+    public static final String DEFAULT_CONFIG_ROOT_PATH = "/dubbo/config";
+
+    private static final Logger logger = LoggerFactory.getLogger(com.netflix.config.source.ZooKeeperConfigurationSource.class);
+    private Executor executor = Executors.newFixedThreadPool(1);
+    private final CuratorFramework client;
+
+    private final String configRootPath;
+    private final TreeCache treeCache;
+
+    private final Charset charset = Charset.forName("UTF-8");
+
+    private List<WatchedUpdateListener> listeners = new CopyOnWriteArrayList<WatchedUpdateListener>();
+
+    public ZooKeeperConfigurationSource() {
+        this(System.getProperty(ARCHAIUS_SOURCE_ADDRESS_KEY), 60 * 1000, 60 * 1000, System.getProperty(ARCHAIUS_CONFIG_ROOT_PATH_KEY, DEFAULT_CONFIG_ROOT_PATH));
+    }
+
+    public ZooKeeperConfigurationSource(int sessionTimeout, int connectTimeout, String configRootPath) {
+        this(System.getProperty(ARCHAIUS_SOURCE_ADDRESS_KEY), sessionTimeout, connectTimeout, configRootPath);
+    }
+
+
+    public ZooKeeperConfigurationSource(String connectString, int sessionTimeout, int connectTimeout, String configRootPath) {
+        if (connectString == null) {
+            throw new IllegalArgumentException("connectString==null, must specify the address to connect for zookeeper archaius source.");
+        }
+        CuratorFramework client = CuratorFrameworkFactory.newClient(connectString, sessionTimeout, connectTimeout,
+                new ExponentialBackoffRetry(1000, 3));
+        client.start();
+
+        this.client = client;
+        this.configRootPath = configRootPath;
+        this.treeCache = new TreeCache(client, configRootPath);
+    }
+
+    /**
+     * Creates the pathChildrenCache using the CuratorFramework client and ZK root path node for the config
+     *
+     * @param client
+     * @param configRootPath path to ZK root parent node for the rest of the configuration properties (ie. /<my-app>/config)
+     */
+    public ZooKeeperConfigurationSource(CuratorFramework client, String configRootPath) {
+        this.client = client;
+        this.configRootPath = configRootPath;
+        this.treeCache = new TreeCache(client, configRootPath);
+    }
+
+    /**
+     * Adds a listener to the pathChildrenCache, initializes the cache, then starts the cache-management background thread
+     *
+     * @throws Exception
+     */
+    public void start() throws Exception {
+        // create the watcher for future configuration updatess
+        CountDownLatch latch = new CountDownLatch(1);
+        treeCache.getListenable().addListener(new TreeCacheListener() {
+            public void childEvent(CuratorFramework aClient, TreeCacheEvent event)
+                    throws Exception {
+
+                TreeCacheEvent.Type type = event.getType();
+                ChildData data = event.getData();
+                if (type == TreeCacheEvent.Type.INITIALIZED) {
+                    latch.countDown();
+                }
+
+                // TODO, ignore other event types
+                if (data == null) {
+                    return;
+                }
+
+                if (data.getPath().split("/").length == 5) {
+                    byte[] value = data.getData();
+                    String stringValue = new String(value, charset);
+
+                    // fire event to all listeners
+                    Map<String, Object> added = null;
+                    Map<String, Object> changed = null;
+                    Map<String, Object> deleted = null;
+
+                    switch (type) {
+                        case NODE_ADDED:
+                            added = new HashMap<>(1);
+                            added.put(pathToKey(data.getPath()), stringValue);
+                            break;
+                        case NODE_REMOVED:
+                            deleted = new HashMap<>(1);
+                            deleted.put(pathToKey(data.getPath()), stringValue);
+                            break;
+                        case NODE_UPDATED:
+                            changed = new HashMap<>(1);
+                            changed.put(pathToKey(data.getPath()), stringValue);
+                    }
+
+                    WatchedUpdateResult result = WatchedUpdateResult.createIncremental(added,
+                            changed, deleted);
+
+                    fireEvent(result);
+                }
+            }
+        }, executor);
+
+        // passing true to trigger an initial rebuild upon starting.  (blocking call)
+        treeCache.start();
+        latch.await(60 * 1000, TimeUnit.MILLISECONDS);
+    }
+
+    /**
+     * This is used to convert a configuration nodePath into a key
+     *
+     * @param path
+     * @return key (nodePath less the config root path)
+     */
+    private String pathToKey(String path) {
+        if (StringUtils.isEmpty(path)) {
+            return path;
+        }
+        return path.replace(configRootPath, "").replaceAll("/", ".");
+    }
+
+    @Override
+    public Map<String, Object> getCurrentData() throws Exception {
+        logger.debug("getCurrentData() retrieving current data.");
+
+        Map<String, Object> all = new HashMap<>();
+
+        Map<String, ChildData> dataMap = treeCache.getCurrentChildren(configRootPath);
+        if (dataMap != null && dataMap.size() > 0) {
+            dataMap.forEach((childPath, v) -> {
+                String fullChildPath = configRootPath + "/" + childPath;
+                treeCache.getCurrentChildren(fullChildPath).forEach((subChildPath, childData) -> {
+                    all.put(pathToKey(fullChildPath + "/" + subChildPath), new String(childData.getData(), charset));
+                });
+            });
+        }
+
+        logger.debug("getCurrentData() retrieved [{}] config elements.", all.size());
+
+        return all;
+    }
+
+    @Override
+    public void addUpdateListener(WatchedUpdateListener l) {
+        if (l != null) {
+            listeners.add(l);
+        }
+    }
+
+    @Override
+    public void removeUpdateListener(WatchedUpdateListener l) {
+        if (l != null) {
+            listeners.remove(l);
+        }
+    }
+
+    protected void fireEvent(WatchedUpdateResult result) {
+        for (WatchedUpdateListener l : listeners) {
+            try {
+                l.updateConfiguration(result);
+            } catch (Throwable ex) {
+                logger.error("Error in invoking WatchedUpdateListener", ex);
+            }
+        }
+    }
+
+    public void close() {
+        try {
+            Closeables.close(treeCache, true);
+        } catch (IOException exc) {
+            logger.error("IOException should not have been thrown.", exc);
+        }
+    }
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/nop/NopDynamicConfiguration.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/nop/NopDynamicConfiguration.java
new file mode 100644
index 0000000000..c8b0dd68d9
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/nop/NopDynamicConfiguration.java
@@ -0,0 +1,35 @@
+/*
+ * 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.config.dynamic.support.nop;
+
+import org.apache.dubbo.config.dynamic.AbstractDynamicConfiguration;
+
+/**
+ *
+ */
+public class NopDynamicConfiguration extends AbstractDynamicConfiguration {
+
+    @Override
+    protected String getInternalProperty(String key, String group, long timeout) {
+        return null;
+    }
+
+    @Override
+    public void init() {
+
+    }
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/nop/NopDynamicConfigurationFactory.java b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/nop/NopDynamicConfigurationFactory.java
new file mode 100644
index 0000000000..301943740f
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/nop/NopDynamicConfigurationFactory.java
@@ -0,0 +1,31 @@
+/*
+ * 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.config.dynamic.support.nop;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
+import org.apache.dubbo.config.dynamic.DynamicConfigurationFactory;
+
+/**
+ *
+ */
+public class NopDynamicConfigurationFactory implements DynamicConfigurationFactory {
+    @Override
+    public DynamicConfiguration getDynamicConfiguration(URL url) {
+        return new NopDynamicConfiguration();
+    }
+}
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.dynamic.DynamicConfiguration b/dubbo-config/dubbo-config-dynamic/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.dynamic.DynamicConfiguration
new file mode 100644
index 0000000000..eb1b9bb8a2
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.dynamic.DynamicConfiguration
@@ -0,0 +1,3 @@
+apollo=org.apache.dubbo.config.dynamic.support.apollo.ApolloDynamicConfiguration
+archaius=org.apache.dubbo.config.dynamic.support.archaius.ArchaiusDynamicConfiguration
+zookeeper=org.apache.dubbo.config.dynamic.support.archaius.ArchaiusDynamicConfiguration
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-dynamic/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.dynamic.DynamicConfigurationFactory b/dubbo-config/dubbo-config-dynamic/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.dynamic.DynamicConfigurationFactory
new file mode 100644
index 0000000000..de5e675390
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.config.dynamic.DynamicConfigurationFactory
@@ -0,0 +1,4 @@
+zookeeper=org.apache.dubbo.config.dynamic.support.archaius.ArchaiusDynamicConfigurationFactory
+archaius=org.apache.dubbo.config.dynamic.support.archaius.ArchaiusDynamicConfigurationFactory
+apollo=org.apache.dubbo.config.dynamic.support.apollo.ApolloDynamicConfigurationFactory
+nop=org.apache.dubbo.config.dynamic.support.nop.NopDynamicConfigurationFactory
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-dynamic/src/test/resources/AppAnyServices.yml b/dubbo-config/dubbo-config-dynamic/src/test/resources/AppAnyServices.yml
new file mode 100644
index 0000000000..93018592f8
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/test/resources/AppAnyServices.yml
@@ -0,0 +1,16 @@
+# Service scope, without  specific App
+---
+scope: application
+key: app1
+configs:
+ - addresses: [127.0.0.1, 0.0.0.0]
+   services: ['*']
+   side: provider
+   rules:
+    cluster:
+     loadbalance: random
+     cluster: failfast
+    config:
+     timeout: 6666
+     weight: 222
+...
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-dynamic/src/test/resources/AppMultiServices.yml b/dubbo-config/dubbo-config-dynamic/src/test/resources/AppMultiServices.yml
new file mode 100644
index 0000000000..a2bf987699
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/test/resources/AppMultiServices.yml
@@ -0,0 +1,16 @@
+# Service scope, without  specific App
+---
+scope: application
+key: app1
+configs:
+ - addresses: [127.0.0.1, 0.0.0.0]
+   services: [service1, service2]
+   side: provider
+   rules:
+    cluster:
+     loadbalance: random
+     cluster: failfast
+    config:
+     timeout: 6666
+     weight: 222
+...
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-dynamic/src/test/resources/AppNoService.yml b/dubbo-config/dubbo-config-dynamic/src/test/resources/AppNoService.yml
new file mode 100644
index 0000000000..763701609c
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/test/resources/AppNoService.yml
@@ -0,0 +1,15 @@
+# Service scope, without  specific App
+---
+scope: application
+key: app1
+configs:
+ - addresses:
+    - 127.0.0.1
+   rules:
+    cluster:
+     loadbalance: random
+     cluster: failfast
+    config:
+     timeout: 6666
+     weight: 222
+...
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceGroupVersion.yml b/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceGroupVersion.yml
new file mode 100644
index 0000000000..d4ef79ef20
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceGroupVersion.yml
@@ -0,0 +1,15 @@
+# Service scope, without any app
+---
+scope: service
+key: testgroup/servicekey:1.0.0
+configs:
+ - addresses: [127.0.0.1]
+   side: provider
+   rules:
+    cluster:
+     loadbalance: random
+     cluster: failfast
+    config:
+     timeout: 6666
+     weight: 222
+...
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceMultiApps.yml b/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceMultiApps.yml
new file mode 100644
index 0000000000..a6cd6ac3d3
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceMultiApps.yml
@@ -0,0 +1,16 @@
+# Service scope, with multiple apps
+---
+scope: service
+key: serviceKey
+configs:
+ - addresses: [127.0.0.1, 0.0.0.0]
+   applications: [app1, app2]
+   side: provider
+   rules:
+    cluster:
+     loadbalance: random
+     cluster: failfast
+    config:
+     timeout: 6666
+     weight: 222
+...
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceNoApp.yml b/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceNoApp.yml
new file mode 100644
index 0000000000..b850ffec2e
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceNoApp.yml
@@ -0,0 +1,15 @@
+# Service scope, without any app
+---
+scope: service
+key: serviceKey
+configs:
+ - addresses: [127.0.0.1, 0.0.0.0]
+   side: provider
+   rules:
+    cluster:
+     loadbalance: random
+     cluster: failfast
+    config:
+     timeout: 6666
+     weight: 222
+...
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceNoRule.yml b/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceNoRule.yml
new file mode 100644
index 0000000000..1b09658cbf
--- /dev/null
+++ b/dubbo-config/dubbo-config-dynamic/src/test/resources/ServiceNoRule.yml
@@ -0,0 +1,9 @@
+# Service scope, without  specific App
+---
+scope: service
+key: serviceKey
+configs:
+ - addresses: [127.0.0.1, 0.0.0.0]
+   applications: [app1, app2]
+   side: provider
+...
\ No newline at end of file
diff --git a/dubbo-config/pom.xml b/dubbo-config/pom.xml
index 9a75eea5cd..ea0e46c105 100644
--- a/dubbo-config/pom.xml
+++ b/dubbo-config/pom.xml
@@ -31,5 +31,6 @@
     <modules>
         <module>dubbo-config-api</module>
         <module>dubbo-config-spring</module>
+        <module>dubbo-config-dynamic</module>
     </modules>
 </project>
diff --git a/dubbo-demo/dubbo-demo-consumer/pom.xml b/dubbo-demo/dubbo-demo-consumer/pom.xml
index de9962b952..91468c8075 100644
--- a/dubbo-demo/dubbo-demo-consumer/pom.xml
+++ b/dubbo-demo/dubbo-demo-consumer/pom.xml
@@ -58,5 +58,9 @@
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-serialization-hessian2</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-config-dynamic</artifactId>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-demo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml b/dubbo-demo/dubbo-demo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
index a56a10ee7e..2a6c5ebfdd 100644
--- a/dubbo-demo/dubbo-demo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
+++ b/dubbo-demo/dubbo-demo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
@@ -23,7 +23,10 @@
 
     <!-- consumer's application name, used for tracing dependency relationship (not a matching criterion),
     don't set it same as provider -->
-    <dubbo:application name="demo-consumer"/>
+    <dubbo:application name="demo-consumer">
+        <dubbo:parameter key="config.type" value="zookeeper"/>
+        <dubbo:parameter key="config.address" value="127.0.0.1:2181"/>
+    </dubbo:application>
 
     <!-- use multicast registry center to discover service -->
     <dubbo:registry address="multicast://224.5.6.7:1234"/>
diff --git a/dubbo-demo/dubbo-demo-provider/pom.xml b/dubbo-demo/dubbo-demo-provider/pom.xml
index 7dd3541f8c..b9f46b1783 100644
--- a/dubbo-demo/dubbo-demo-provider/pom.xml
+++ b/dubbo-demo/dubbo-demo-provider/pom.xml
@@ -59,5 +59,9 @@
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-serialization-hessian2</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-config-dynamic</artifactId>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml b/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
index c2ab4a21e0..ed08464c88 100644
--- a/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
+++ b/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
@@ -25,7 +25,7 @@
     <dubbo:application name="demo-provider"/>
 
     <!-- use multicast registry center to export service -->
-    <dubbo:registry address="multicast://224.5.6.7:1234"/>
+    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
 
     <!-- use dubbo protocol to export service on port 20880 -->
     <dubbo:protocol name="dubbo" port="20880"/>
diff --git a/dubbo-registry/dubbo-registry-api/pom.xml b/dubbo-registry/dubbo-registry-api/pom.xml
index 2437eae7c9..e1f364e6c6 100644
--- a/dubbo-registry/dubbo-registry-api/pom.xml
+++ b/dubbo-registry/dubbo-registry-api/pom.xml
@@ -34,6 +34,11 @@
             <artifactId>dubbo-cluster</artifactId>
             <version>${project.parent.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-config-dynamic</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-container-api</artifactId>
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
index f444971838..8da068df94 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
@@ -24,13 +24,18 @@
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.config.dynamic.ConfigChangeEvent;
+import org.apache.dubbo.config.dynamic.ConfigChangeType;
+import org.apache.dubbo.config.dynamic.ConfigType;
+import org.apache.dubbo.config.dynamic.ConfigurationListener;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
 import org.apache.dubbo.registry.NotifyListener;
 import org.apache.dubbo.registry.Registry;
+import org.apache.dubbo.registry.integration.parser.ConfigParser;
 import org.apache.dubbo.rpc.Invocation;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.Protocol;
 import org.apache.dubbo.rpc.RpcException;
-import org.apache.dubbo.rpc.RpcInvocation;
 import org.apache.dubbo.rpc.cluster.Cluster;
 import org.apache.dubbo.rpc.cluster.Configurator;
 import org.apache.dubbo.rpc.cluster.ConfiguratorFactory;
@@ -49,15 +54,16 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * RegistryDirectory
- *
  */
-public class RegistryDirectory<T> extends AbstractDirectory<T> implements NotifyListener {
+public class RegistryDirectory<T> extends AbstractDirectory<T> implements NotifyListener, ConfigurationListener {
 
     private static final Logger logger = LoggerFactory.getLogger(RegistryDirectory.class);
 
@@ -74,6 +80,7 @@
     private final boolean multiGroup;
     private Protocol protocol; // Initialization at the time of injection, the assertion is not null
     private Registry registry; // Initialization at the time of injection, the assertion is not null
+    private DynamicConfiguration dynamicConfiguration;
     private volatile boolean forbidden = false;
 
     private volatile URL overrideDirectoryUrl; // Initialization at construction time, assertion not null, and always assign non null value
@@ -85,6 +92,8 @@
      * Rule two: for all providers <* ,timeout=5000>
      */
     private volatile List<Configurator> configurators; // The initial value is null and the midway may be assigned to null, please use the local variable reference
+    private volatile List<Configurator> dynamicConfigurators;
+    private volatile List<Configurator> appDynamicConfigurators;
 
     // Map<url, Invoker> cache service url to invoker mapping.
     private volatile Map<String, Invoker<T>> urlInvokerMap; // The initial value is null and the midway may be assigned to null, please use the local variable reference
@@ -146,6 +155,14 @@ public RegistryDirectory(Class<T> serviceType, URL url) {
         return configurators;
     }
 
+    public static List<Configurator> configToConfiguratiors(String rawConfig) {
+        if (StringUtils.isEmpty(rawConfig)) {
+            return new LinkedList<>();
+        }
+        List<URL> urls = ConfigParser.parseConfigurators(rawConfig);
+        return urls.stream().map(configuratorFactory::getConfigurator).collect(Collectors.toList());
+    }
+
     public void setProtocol(Protocol protocol) {
         this.protocol = protocol;
     }
@@ -156,6 +173,16 @@ public void setRegistry(Registry registry) {
 
     public void subscribe(URL url) {
         setConsumerUrl(url);
+        String rawConfig = dynamicConfiguration.getConfig(url.getServiceKey() + Constants.CONFIGURATORS_SUFFIX, "dubbo", this);
+        String rawConfigApp = dynamicConfiguration.getConfig(url.getParameter(Constants.APPLICATION_KEY) + Constants.CONFIGURATORS_SUFFIX, "dubbo", this);
+
+        if (StringUtils.isNotEmpty(rawConfig)) {
+            this.dynamicConfigurators = configToConfiguratiors(rawConfig);
+        }
+        if (StringUtils.isNotEmpty(rawConfigApp)) {
+            this.appDynamicConfigurators = configToConfiguratiors(rawConfigApp);
+        }
+
         registry.subscribe(url, this);
     }
 
@@ -182,15 +209,21 @@ public void destroy() {
 
     @Override
     public synchronized void notify(List<URL> urls) {
-        List<URL> invokerUrls = new ArrayList<URL>();
-        List<URL> routerUrls = new ArrayList<URL>();
-        List<URL> configuratorUrls = new ArrayList<URL>();
+        List<URL> invokerUrls = new ArrayList<>();
+        List<URL> routerUrls = new ArrayList<>();
+        List<URL> configuratorUrls = new ArrayList<>();
+        List<URL> dynamicConfiguratorUrls = new ArrayList<>();
+        List<URL> appDynamicConfiguratorUrls = new ArrayList<>();
         for (URL url : urls) {
             String protocol = url.getProtocol();
             String category = url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY);
             if (Constants.ROUTERS_CATEGORY.equals(category)
                     || Constants.ROUTE_PROTOCOL.equals(protocol)) {
                 routerUrls.add(url);
+            } else if (Constants.DYNAMIC_CONFIGURATORS_CATEGORY.equals(category)) {
+                dynamicConfiguratorUrls.add(url);
+            } else if (Constants.APP_DYNAMIC_CONFIGURATORS_CATEGORY.equals(category)) {
+                appDynamicConfiguratorUrls.add(url);
             } else if (Constants.CONFIGURATORS_CATEGORY.equals(category)
                     || Constants.OVERRIDE_PROTOCOL.equals(protocol)) {
                 configuratorUrls.add(url);
@@ -201,15 +234,21 @@ public synchronized void notify(List<URL> urls) {
             }
         }
         // configurators
-        if (configuratorUrls != null && !configuratorUrls.isEmpty()) {
+        if (!configuratorUrls.isEmpty()) {
             this.configurators = toConfigurators(configuratorUrls);
         }
+        // dynamic configurators
+        if (!dynamicConfiguratorUrls.isEmpty()) {
+            this.dynamicConfigurators = toConfigurators(dynamicConfiguratorUrls);
+        }
+        // dynamic configurators, app scope
+        if (!appDynamicConfiguratorUrls.isEmpty()) {
+            this.appDynamicConfigurators = toConfigurators(appDynamicConfiguratorUrls);
+        }
         // routers
-        if (routerUrls != null && !routerUrls.isEmpty()) {
+        if (!routerUrls.isEmpty()) {
             List<Router> routers = toRouters(routerUrls);
-            if (routers != null) { // null - do nothing
-                setRouters(routers);
-            }
+            addRouters(routers);
         }
         List<Configurator> localConfigurators = this.configurators; // local reference
         // merge override parameters
@@ -219,10 +258,16 @@ public synchronized void notify(List<URL> urls) {
                 this.overrideDirectoryUrl = configurator.configure(overrideDirectoryUrl);
             }
         }
+        // FIXME should we apply dynamicConfigurators to overrideDirectoryUrl?
+
         // providers
         refreshInvoker(invokerUrls);
     }
 
+/*    private List<URL> compositeDynamicConfiguration(List<URL> urls) {
+        return urls.stream().map(u -> dynamicConfiguration.instrument(u)).collect(Collectors.toList());
+    }*/
+
     /**
      * Convert the invokerURL list to the Invoker Map. The rules of the conversion are as follows:
      * 1.If URL has been converted to invoker, it is no longer re-referenced and obtained directly from the cache, and notice that any parameter changes in the URL will be re-referenced.
@@ -260,6 +305,8 @@ private void refreshInvoker(List<URL> invokerUrls) {
             }
             this.methodInvokerMap = multiGroup ? toMergeMethodInvokerMap(newMethodInvokerMap) : newMethodInvokerMap;
             this.urlInvokerMap = newUrlInvokerMap;
+            // Route and build cache
+            routerChain.notifyFullInvokers(methodInvokerMap, getConsumerUrl());
             try {
                 destroyUnusedInvokers(oldUrlInvokerMap, newUrlInvokerMap); // Close the unused Invoker
             } catch (Exception e) {
@@ -409,12 +456,7 @@ private void refreshInvoker(List<URL> invokerUrls) {
     private URL mergeUrl(URL providerUrl) {
         providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // Merge the consumer side parameters
 
-        List<Configurator> localConfigurators = this.configurators; // local reference
-        if (localConfigurators != null && !localConfigurators.isEmpty()) {
-            for (Configurator configurator : localConfigurators) {
-                providerUrl = configurator.configure(providerUrl);
-            }
-        }
+        providerUrl = overrideWithConfigurator(providerUrl);
 
         providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // Do not check whether the connection is successful or not, always create Invoker!
 
@@ -440,17 +482,29 @@ private URL mergeUrl(URL providerUrl) {
         return providerUrl;
     }
 
-    private List<Invoker<T>> route(List<Invoker<T>> invokers, String method) {
-        Invocation invocation = new RpcInvocation(method, new Class<?>[0], new Object[0]);
-        List<Router> routers = getRouters();
-        if (routers != null) {
-            for (Router router : routers) {
-                if (router.getUrl() != null) {
-                    invokers = router.route(invokers, getConsumerUrl(), invocation);
-                }
+    private URL overrideWithConfigurator(URL providerUrl) {
+        List<Configurator> localConfigurators = this.configurators; // local reference
+        if (localConfigurators != null && !localConfigurators.isEmpty()) {
+            for (Configurator configurator : localConfigurators) {
+                providerUrl = configurator.configure(providerUrl);
+            }
+        }
+
+        List<Configurator> localAppDynamicConfigurators = this.appDynamicConfigurators; // local reference
+        if (localAppDynamicConfigurators != null && !localAppDynamicConfigurators.isEmpty()) {
+            for (Configurator configurator : localAppDynamicConfigurators) {
+                providerUrl = configurator.configure(providerUrl);
+            }
+        }
+
+        List<Configurator> localDynamicConfigurators = this.dynamicConfigurators; // local reference
+        if (localDynamicConfigurators != null && !localDynamicConfigurators.isEmpty()) {
+            for (Configurator configurator : localDynamicConfigurators) {
+                providerUrl = configurator.configure(providerUrl);
             }
         }
-        return invokers;
+
+        return providerUrl;
     }
 
     /**
@@ -485,17 +539,7 @@ private URL mergeUrl(URL providerUrl) {
                 invokersList.add(invoker);
             }
         }
-        List<Invoker<T>> newInvokersList = route(invokersList, null);
-        newMethodInvokerMap.put(Constants.ANY_VALUE, newInvokersList);
-        if (serviceMethods != null && serviceMethods.length > 0) {
-            for (String method : serviceMethods) {
-                List<Invoker<T>> methodInvokers = newMethodInvokerMap.get(method);
-                if (methodInvokers == null || methodInvokers.isEmpty()) {
-                    methodInvokers = newInvokersList;
-                }
-                newMethodInvokerMap.put(method, route(methodInvokers, method));
-            }
-        }
+        newMethodInvokerMap.put(Constants.ANY_VALUE, invokersList);
         // sort and unmodifiable
         for (String method : new HashSet<String>(newMethodInvokerMap.keySet())) {
             List<Invoker<T>> methodInvokers = newMethodInvokerMap.get(method);
@@ -573,8 +617,8 @@ private void destroyUnusedInvokers(Map<String, Invoker<T>> oldUrlInvokerMap, Map
         if (forbidden) {
             // 1. No service provider 2. Service providers are disabled
             throw new RpcException(RpcException.FORBIDDEN_EXCEPTION,
-                "No provider available from registry " + getUrl().getAddress() + " for service " + getConsumerUrl().getServiceKey() + " on consumer " +  NetUtils.getLocalHost()
-                        + " use dubbo version " + Version.getVersion() + ", please check status of providers(disabled, not registered or in blacklist).");
+                    "No provider available from registry " + getUrl().getAddress() + " for service " + getConsumerUrl().getServiceKey() + " on consumer " + NetUtils.getLocalHost()
+                            + " use dubbo version " + Version.getVersion() + ", please check status of providers(disabled, not registered or in blacklist).");
         }
         List<Invoker<T>> invokers = null;
         Map<String, List<Invoker<T>>> localMethodInvokerMap = this.methodInvokerMap; // local reference
@@ -606,6 +650,28 @@ private void destroyUnusedInvokers(Map<String, Invoker<T>> oldUrlInvokerMap, Map
         return serviceType;
     }
 
+    @Override
+    public void process(ConfigChangeEvent event) {
+        ConfigType configType = event.getType();
+        ConfigChangeType changeType = event.getChangeType();
+
+        List<URL> urls = new ArrayList<>();
+        if (changeType.equals(ConfigChangeType.DELETED)) {
+            if (ConfigType.CONFIGURATORS.equals(configType)) {
+                urls.add(getConsumerUrl().clearParameters().addParameter(Constants.CATEGORY_KEY, Constants.DYNAMIC_CONFIGURATORS_CATEGORY).setProtocol(Constants.EMPTY_PROTOCOL));
+            } else if (ConfigType.ROUTERS.equals(configType)) {
+                urls.add(getConsumerUrl().clearParameters().addParameter(Constants.CATEGORY_KEY, Constants.DYNAMIC_ROUTERS_CATEGORY).setProtocol(Constants.EMPTY_PROTOCOL));
+            }
+        } else {
+            if (ConfigType.CONFIGURATORS.equals(configType)) {
+                urls = ConfigParser.parseConfigurators(event.getNewValue());
+            } else if (ConfigType.ROUTERS.equals(configType)) {
+                urls = ConfigParser.parseRouters(event.getNewValue());
+            }
+        }
+        notify(urls);
+    }
+
     @Override
     public URL getUrl() {
         return this.overrideDirectoryUrl;
@@ -627,6 +693,10 @@ public boolean isAvailable() {
         return false;
     }
 
+    public void setDynamicConfiguration(DynamicConfiguration dynamicConfiguration) {
+        this.dynamicConfiguration = dynamicConfiguration;
+    }
+
     /**
      * Haomin: added for test purpose
      */
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 b1e4c3d349..8bd469f8b1 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
@@ -25,10 +25,17 @@
 import org.apache.dubbo.common.utils.NamedThreadFactory;
 import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.common.utils.UrlUtils;
+import org.apache.dubbo.config.dynamic.ConfigChangeEvent;
+import org.apache.dubbo.config.dynamic.ConfigChangeType;
+import org.apache.dubbo.config.dynamic.ConfigType;
+import org.apache.dubbo.config.dynamic.ConfigurationListener;
+import org.apache.dubbo.config.dynamic.DynamicConfiguration;
+import org.apache.dubbo.config.dynamic.DynamicConfigurationFactory;
 import org.apache.dubbo.registry.NotifyListener;
 import org.apache.dubbo.registry.Registry;
 import org.apache.dubbo.registry.RegistryFactory;
 import org.apache.dubbo.registry.RegistryService;
+import org.apache.dubbo.registry.integration.parser.ConfigParser;
 import org.apache.dubbo.registry.support.ProviderConsumerRegTable;
 import org.apache.dubbo.rpc.Exporter;
 import org.apache.dubbo.rpc.Invoker;
@@ -37,25 +44,30 @@
 import org.apache.dubbo.rpc.RpcException;
 import org.apache.dubbo.rpc.cluster.Cluster;
 import org.apache.dubbo.rpc.cluster.Configurator;
+import org.apache.dubbo.rpc.cluster.RouterChain;
 import org.apache.dubbo.rpc.protocol.InvokerWrapper;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
 
 import static org.apache.dubbo.common.Constants.ACCEPT_FOREIGN_IP;
+import static org.apache.dubbo.common.Constants.CONFIG_PROTOCOL;
+import static org.apache.dubbo.common.Constants.EXPORT_KEY;
 import static org.apache.dubbo.common.Constants.INTERFACES;
 import static org.apache.dubbo.common.Constants.QOS_ENABLE;
 import static org.apache.dubbo.common.Constants.QOS_PORT;
+import static org.apache.dubbo.common.Constants.REFER_KEY;
 import static org.apache.dubbo.common.Constants.VALIDATION_KEY;
 
 /**
  * RegistryProtocol
- *
  */
 public class RegistryProtocol implements Protocol {
 
@@ -69,6 +81,7 @@
     private Protocol protocol;
     private RegistryFactory registryFactory;
     private ProxyFactory proxyFactory;
+    private DynamicConfiguration dynamicConfiguration;
 
     public RegistryProtocol() {
         INSTANCE = this;
@@ -97,6 +110,12 @@ public static RegistryProtocol getRegistryProtocol() {
         }
     }
 
+    public void initDynamicConfiguration(URL url) {
+        if (dynamicConfiguration == null) {
+            dynamicConfiguration = ExtensionLoader.getExtensionLoader(DynamicConfigurationFactory.class).getAdaptiveExtension().getDynamicConfiguration(getConfigUrl(url));
+        }
+    }
+
     public void setCluster(Cluster cluster) {
         this.cluster = cluster;
     }
@@ -129,20 +148,24 @@ public void register(URL registryUrl, URL registedProviderUrl) {
 
     @Override
     public <T> Exporter<T> export(final Invoker<T> originInvoker) throws RpcException {
-        //export invoker
-        final ExporterChangeableWrapper<T> exporter = doLocalExport(originInvoker);
-
         URL registryUrl = getRegistryUrl(originInvoker);
+        initDynamicConfiguration(registryUrl);
 
-        //registry provider
-        final Registry registry = getRegistry(originInvoker);
-        final URL registedProviderUrl = getRegistedProviderUrl(originInvoker);
+        // url to export locally
+        URL providerUrl = getProviderUrl(originInvoker);
+        providerUrl = overrideUrlWithConfig(providerUrl);
 
-        //to judge to delay publish whether or not
-        boolean register = registedProviderUrl.getParameter("register", true);
+        //export invoker
+        final ExporterChangeableWrapper<T> exporter = doLocalExport(originInvoker, providerUrl);
+
+        // url to registry
+        final Registry registry = getRegistry(originInvoker);
+        final URL registedProviderUrl = getRegistedProviderUrl(providerUrl);
 
         ProviderConsumerRegTable.registerProvider(originInvoker, registryUrl, registedProviderUrl);
 
+        //to judge if we need to delay publish
+        boolean register = registedProviderUrl.getParameter("register", true);
         if (register) {
             register(registryUrl, registedProviderUrl);
             ProviderConsumerRegTable.getProviderWrapper(originInvoker).setReg(true);
@@ -154,19 +177,50 @@ public void register(URL registryUrl, URL registedProviderUrl) {
         final OverrideListener overrideSubscribeListener = new OverrideListener(overrideSubscribeUrl, originInvoker);
         overrideListeners.put(overrideSubscribeUrl, overrideSubscribeListener);
         registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener);
+
+        dynamicConfiguration.addListener(overrideSubscribeUrl.getServiceKey() + Constants.CONFIGURATORS_SUFFIX, overrideSubscribeListener);
         //Ensure that a new exporter instance is returned every time export
         return new DestroyableExporter<T>(exporter, originInvoker, overrideSubscribeUrl, registedProviderUrl);
     }
 
+    private <T> URL overrideUrlWithConfig(URL providerUrl) {
+        List<Configurator> dynamicConfigurators = new LinkedList<>();
+        String appRawConfig = dynamicConfiguration.getConfig(providerUrl.getParameter(Constants.APPLICATION_KEY) + Constants.CONFIGURATORS_SUFFIX, "dubbo");
+        if (!StringUtils.isEmpty(appRawConfig)) {
+            dynamicConfigurators.addAll(RegistryDirectory.configToConfiguratiors(appRawConfig));
+        }
+        String rawConfig = dynamicConfiguration.getConfig(providerUrl.getServiceKey() + Constants.CONFIGURATORS_SUFFIX, "dubbo");
+        if (!StringUtils.isEmpty(rawConfig)) {
+            dynamicConfigurators.addAll(RegistryDirectory.configToConfiguratiors(rawConfig));
+        }
+        providerUrl = getConfigedInvokerUrl(dynamicConfigurators, providerUrl);
+        return providerUrl;
+    }
+
+    private URL getConfigUrl(URL registryUrl) {
+        URL url = registryUrl.removeParameters(EXPORT_KEY, REFER_KEY).setProtocol(CONFIG_PROTOCOL);
+        String configType = registryUrl.getParameter(Constants.CONFIG_TYPE_KEY);
+        if (StringUtils.isEmpty(configType)) {
+            url = url.addParameter(Constants.CONFIG_TYPE_KEY, registryUrl.getProtocol());
+        }
+
+        String configAddress = registryUrl.getParameter(Constants.CONFIG_ADDRESS_KEY);
+        if (StringUtils.isNotEmpty(configAddress)) {
+            url = url.setAddress(configAddress);
+        }
+        return url;
+    }
+
     @SuppressWarnings("unchecked")
-    private <T> ExporterChangeableWrapper<T> doLocalExport(final Invoker<T> originInvoker) {
+    private <T> ExporterChangeableWrapper<T> doLocalExport(final Invoker<T> originInvoker, URL providerUrl) {
         String key = getCacheKey(originInvoker);
         ExporterChangeableWrapper<T> exporter = (ExporterChangeableWrapper<T>) bounds.get(key);
         if (exporter == null) {
             synchronized (bounds) {
                 exporter = (ExporterChangeableWrapper<T>) bounds.get(key);
                 if (exporter == null) {
-                    final Invoker<?> invokerDelegete = new InvokerDelegete<T>(originInvoker, getProviderUrl(originInvoker));
+
+                    final Invoker<?> invokerDelegete = new InvokerDelegete<T>(originInvoker, providerUrl);
                     exporter = new ExporterChangeableWrapper<T>((Exporter<T>) protocol.export(invokerDelegete), originInvoker);
                     bounds.put(key, exporter);
                 }
@@ -217,11 +271,10 @@ private URL getRegistryUrl(Invoker<?> originInvoker) {
     /**
      * Return the url that is registered to the registry and filter the url parameter once
      *
-     * @param originInvoker
-     * @return
+     * @param providerUrl
+     * @return url to registry.
      */
-    private URL getRegistedProviderUrl(final Invoker<?> originInvoker) {
-        URL providerUrl = getProviderUrl(originInvoker);
+    private URL getRegistedProviderUrl(final URL providerUrl) {
         //The address you see at the registry
         final URL registedProviderUrl = providerUrl.removeParameters(getFilteredKeys(providerUrl))
                 .removeParameter(Constants.MONITOR_KEY)
@@ -248,13 +301,11 @@ private URL getSubscribedOverrideUrl(URL registedProviderUrl) {
      * @return
      */
     private URL getProviderUrl(final Invoker<?> origininvoker) {
-        String export = origininvoker.getUrl().getParameterAndDecoded(Constants.EXPORT_KEY);
+        String export = origininvoker.getUrl().getParameterAndDecoded(EXPORT_KEY);
         if (export == null || export.length() == 0) {
             throw new IllegalArgumentException("The registry export url is null! registry: " + origininvoker.getUrl());
         }
-
-        URL providerUrl = URL.valueOf(export);
-        return providerUrl;
+        return URL.valueOf(export);
     }
 
     /**
@@ -273,13 +324,14 @@ private String getCacheKey(final Invoker<?> originInvoker) {
     @SuppressWarnings("unchecked")
     public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
         url = url.setProtocol(url.getParameter(Constants.REGISTRY_KEY, Constants.DEFAULT_REGISTRY)).removeParameter(Constants.REGISTRY_KEY);
+        initDynamicConfiguration(url);
         Registry registry = registryFactory.getRegistry(url);
         if (RegistryService.class.equals(type)) {
             return proxyFactory.getInvoker((T) registry, type, url);
         }
 
         // group="a,b" or group="*"
-        Map<String, String> qs = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
+        Map<String, String> qs = StringUtils.parseQueryString(url.getParameterAndDecoded(REFER_KEY));
         String group = qs.get(Constants.GROUP_KEY);
         if (group != null && group.length() > 0) {
             if ((Constants.COMMA_SPLIT_PATTERN.split(group)).length > 1
@@ -298,6 +350,8 @@ private Cluster getMergeableCluster() {
         RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url);
         directory.setRegistry(registry);
         directory.setProtocol(protocol);
+        directory.setDynamicConfiguration(dynamicConfiguration);
+        directory.setRouterChain(RouterChain.buildChain(dynamicConfiguration));
         // all attributes of REFER_KEY
         Map<String, String> parameters = new HashMap<String, String>(directory.getUrl().getParameters());
         URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, parameters.remove(Constants.REGISTER_IP_KEY), 0, type.getName(), parameters);
@@ -325,6 +379,16 @@ public void destroy() {
         bounds.clear();
     }
 
+    //Merge the urls of configurators
+    private URL getConfigedInvokerUrl(List<Configurator> configurators, URL url) {
+        if (configurators != null && configurators.size() > 0) {
+            for (Configurator configurator : configurators) {
+                url = configurator.configure(url);
+            }
+        }
+        return url;
+    }
+
     public static class InvokerDelegete<T> extends InvokerWrapper<T> {
         private final Invoker<T> invoker;
 
@@ -346,16 +410,73 @@ public InvokerDelegete(Invoker<T> invoker, URL url) {
         }
     }
 
+    static private class DestroyableExporter<T> implements Exporter<T> {
+
+        public static final ExecutorService executor = Executors.newSingleThreadExecutor(new NamedThreadFactory("Exporter-Unexport", true));
+
+        private Exporter<T> exporter;
+        private Invoker<T> originInvoker;
+        private URL subscribeUrl;
+        private URL registerUrl;
+
+        public DestroyableExporter(Exporter<T> exporter, Invoker<T> originInvoker, URL subscribeUrl, URL registerUrl) {
+            this.exporter = exporter;
+            this.originInvoker = originInvoker;
+            this.subscribeUrl = subscribeUrl;
+            this.registerUrl = registerUrl;
+        }
+
+        @Override
+        public Invoker<T> getInvoker() {
+            return exporter.getInvoker();
+        }
+
+        @Override
+        public void unexport() {
+            Registry registry = RegistryProtocol.INSTANCE.getRegistry(originInvoker);
+            try {
+                registry.unregister(registerUrl);
+            } catch (Throwable t) {
+                logger.warn(t.getMessage(), t);
+            }
+            try {
+                NotifyListener listener = RegistryProtocol.INSTANCE.overrideListeners.remove(subscribeUrl);
+                registry.unsubscribe(subscribeUrl, listener);
+            } catch (Throwable t) {
+                logger.warn(t.getMessage(), t);
+            }
+
+            executor.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        int timeout = ConfigUtils.getServerShutdownTimeout();
+                        if (timeout > 0) {
+                            logger.info("Waiting " + timeout + "ms for registry to notify all consumers before unexport. Usually, this is called when you use dubbo API");
+                            Thread.sleep(timeout);
+                        }
+                        exporter.unexport();
+                    } catch (Throwable t) {
+                        logger.warn(t.getMessage(), t);
+                    }
+                }
+            });
+        }
+    }
+
     /**
      * Reexport: the exporter destroy problem in protocol
      * 1.Ensure that the exporter returned by registryprotocol can be normal destroyed
      * 2.No need to re-register to the registry after notify
      * 3.The invoker passed by the export method , would better to be the invoker of exporter
      */
-    private class OverrideListener implements NotifyListener {
+    private class OverrideListener implements NotifyListener, ConfigurationListener {
 
         private final URL subscribeUrl;
         private final Invoker originInvoker;
+        private List<Configurator> configurators;
+        private List<Configurator> dynamicConfigurators;
+        private List<Configurator> appDynamicConfigurators;
 
         public OverrideListener(URL subscribeUrl, Invoker originalInvoker) {
             this.subscribeUrl = subscribeUrl;
@@ -368,14 +489,28 @@ public OverrideListener(URL subscribeUrl, Invoker originalInvoker) {
         @Override
         public synchronized void notify(List<URL> urls) {
             logger.debug("original override urls: " + urls);
-            List<URL> matchedUrls = getMatchedUrls(urls, subscribeUrl);
+            List<URL> matchedUrls = getMatchedUrls(urls, subscribeUrl.addParameter(Constants.CATEGORY_KEY,
+                    Constants.CONFIGURATORS_CATEGORY
+                            + "," + Constants.DYNAMIC_CONFIGURATORS_CATEGORY
+                            + "," + Constants.APP_DYNAMIC_CONFIGURATORS_CATEGORY));
             logger.debug("subscribe url: " + subscribeUrl + ", override urls: " + matchedUrls);
             // No matching results
             if (matchedUrls.isEmpty()) {
                 return;
             }
 
-            List<Configurator> configurators = RegistryDirectory.toConfigurators(matchedUrls);
+            List<Configurator> localConfigurators = RegistryDirectory.toConfigurators(matchedUrls.stream().filter(u -> u.getParameter(Constants.CATEGORY_KEY).equals(Constants.CONFIGURATORS_CATEGORY)).collect(Collectors.toList()));
+            List<Configurator> localDynamicConfigurators = RegistryDirectory.toConfigurators(matchedUrls.stream().filter(u -> u.getParameter(Constants.CATEGORY_KEY).equals(Constants.DYNAMIC_CONFIGURATORS_CATEGORY)).collect(Collectors.toList()));
+            List<Configurator> localAppDynamicConfigurators = RegistryDirectory.toConfigurators(matchedUrls.stream().filter(u -> u.getParameter(Constants.CATEGORY_KEY).equals(Constants.APP_DYNAMIC_CONFIGURATORS_CATEGORY)).collect(Collectors.toList()));
+            if (localConfigurators != null && localConfigurators.size() > 0) {
+                configurators = localConfigurators;
+            }
+            if (localDynamicConfigurators != null && localDynamicConfigurators.size() > 0) {
+                dynamicConfigurators = localDynamicConfigurators;
+            }
+            if (localAppDynamicConfigurators != null && localAppDynamicConfigurators.size() > 0) {
+                appDynamicConfigurators = localAppDynamicConfigurators;
+            }
 
             final Invoker<?> invoker;
             if (originInvoker instanceof InvokerDelegete) {
@@ -395,6 +530,8 @@ public synchronized void notify(List<URL> urls) {
             URL currentUrl = exporter.getInvoker().getUrl();
             //Merged with this configuration
             URL newUrl = getConfigedInvokerUrl(configurators, originUrl);
+            newUrl = getConfigedInvokerUrl(appDynamicConfigurators, newUrl);
+            newUrl = getConfigedInvokerUrl(dynamicConfigurators, newUrl);
             if (!currentUrl.equals(newUrl)) {
                 RegistryProtocol.this.doChangeLocalExport(originInvoker, newUrl);
                 logger.info("exported provider url changed, origin url: " + originUrl + ", old export url: " + currentUrl + ", new export url: " + newUrl);
@@ -411,6 +548,11 @@ public synchronized void notify(List<URL> urls) {
                     overrideUrl = url.addParameter(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY);
                 }
 
+                // For provider side, we will simply change DYNAMIC_CONFIGURATORS_CATEGORY to CONFIGURATORS_CATEGORY.
+                if (Constants.DYNAMIC_CONFIGURATORS_CATEGORY.equals(url.getParameter(Constants.CATEGORY_KEY))) {
+                    overrideUrl = url.addParameter(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY);
+                }
+
                 // Check whether url is to be applied to the current service
                 if (UrlUtils.isMatch(currentSubscribe, overrideUrl)) {
                     result.add(url);
@@ -419,12 +561,25 @@ public synchronized void notify(List<URL> urls) {
             return result;
         }
 
-        //Merge the urls of configurators
-        private URL getConfigedInvokerUrl(List<Configurator> configurators, URL url) {
-            for (Configurator configurator : configurators) {
-                url = configurator.configure(url);
+        @Override
+        public void process(ConfigChangeEvent event) {
+            if (!event.getType().equals(ConfigType.CONFIGURATORS)) {
+                return;
             }
-            return url;
+            List<URL> urls;
+            if (event.getChangeType().equals(ConfigChangeType.DELETED)) {
+                URL originUrl = RegistryProtocol.this.getProviderUrl(originInvoker);
+                urls = new ArrayList<>();
+                urls.add(originUrl.clearParameters().addParameter(Constants.CATEGORY_KEY, Constants.DYNAMIC_CONFIGURATORS_CATEGORY).setProtocol(Constants.EMPTY_PROTOCOL));
+            } else {
+                urls = ConfigParser.parseConfigurators(event.getNewValue());
+            }
+            notify(urls);
+        }
+
+        @Override
+        public URL getUrl() {
+            return subscribeUrl;
         }
     }
 
@@ -463,58 +618,4 @@ public void unexport() {
             exporter.unexport();
         }
     }
-
-    static private class DestroyableExporter<T> implements Exporter<T> {
-
-        public static final ExecutorService executor = Executors.newSingleThreadExecutor(new NamedThreadFactory("Exporter-Unexport", true));
-
-        private Exporter<T> exporter;
-        private Invoker<T> originInvoker;
-        private URL subscribeUrl;
-        private URL registerUrl;
-
-        public DestroyableExporter(Exporter<T> exporter, Invoker<T> originInvoker, URL subscribeUrl, URL registerUrl) {
-            this.exporter = exporter;
-            this.originInvoker = originInvoker;
-            this.subscribeUrl = subscribeUrl;
-            this.registerUrl = registerUrl;
-        }
-
-        @Override
-        public Invoker<T> getInvoker() {
-            return exporter.getInvoker();
-        }
-
-        @Override
-        public void unexport() {
-            Registry registry = RegistryProtocol.INSTANCE.getRegistry(originInvoker);
-            try {
-                registry.unregister(registerUrl);
-            } catch (Throwable t) {
-                logger.warn(t.getMessage(), t);
-            }
-            try {
-                NotifyListener listener = RegistryProtocol.INSTANCE.overrideListeners.remove(subscribeUrl);
-                registry.unsubscribe(subscribeUrl, listener);
-            } catch (Throwable t) {
-                logger.warn(t.getMessage(), t);
-            }
-
-            executor.submit(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        int timeout = ConfigUtils.getServerShutdownTimeout();
-                        if (timeout > 0) {
-                            logger.info("Waiting " + timeout + "ms for registry to notify all consumers before unexport. Usually, this is called when you use dubbo API");
-                            Thread.sleep(timeout);
-                        }
-                        exporter.unexport();
-                    } catch (Throwable t) {
-                        logger.warn(t.getMessage(), t);
-                    }
-                }
-            });
-        }
-    }
 }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/ConfigParser.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/ConfigParser.java
new file mode 100644
index 0000000000..147f45400e
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/ConfigParser.java
@@ -0,0 +1,187 @@
+/*
+ * 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.integration.parser;
+
+import org.apache.dubbo.common.Constants;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.registry.integration.parser.model.ConfigItem;
+import org.apache.dubbo.registry.integration.parser.model.ConfiguratorConfig;
+import org.apache.dubbo.registry.integration.parser.model.ConfiguratorRule;
+import org.yaml.snakeyaml.TypeDescription;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ *
+ */
+public class ConfigParser {
+
+    public static List<URL> parseConfigurators(String rawConfig) {
+        List<URL> urls = new ArrayList<>();
+        ConfiguratorConfig configuratorConfig = parseObject(rawConfig, ConfiguratorConfig.class);
+        String scope = configuratorConfig.getScope();
+        List<ConfigItem> items = configuratorConfig.getConfigs();
+
+        if (ConfiguratorConfig.SCOPE_APPLICATION.equals(scope)) {
+            items.forEach(item -> urls.addAll(
+                    appItemToUrls(item, configuratorConfig.getKey())
+                            .stream()
+                            .map(u -> u.addParameter(Constants.CATEGORY_KEY, Constants.APP_DYNAMIC_CONFIGURATORS_CATEGORY))
+                            .collect(Collectors.toList())
+            ));
+        } else { // servcie scope by default.
+            items.forEach(item -> urls.addAll(serviceItemToUrls(item, configuratorConfig.getKey())));
+        }
+        return urls;
+    }
+
+    public static <T> T parseObject(String rawConfig, Class<T> clazz) {
+        Constructor constructor = new Constructor(clazz);
+        TypeDescription carDescription = new TypeDescription(clazz);
+        carDescription.addPropertyParameters("items", ConfigItem.class);
+        constructor.addTypeDescription(carDescription);
+
+        Yaml yaml = new Yaml(constructor);
+        return yaml.load(rawConfig);
+    }
+
+    public static List<URL> parseRouters(String rawConfig) {
+        List<URL> urls = new ArrayList<>();
+        urls.add(URL.valueOf(""));
+        return urls;
+    }
+
+    private static List<URL> serviceItemToUrls(ConfigItem item, String serviceKey) {
+        List<URL> urls = new ArrayList<>();
+        List<String> addresses = item.getAddresses();
+        if (addresses == null) {
+            addresses = new ArrayList<>();
+        }
+        if (addresses.size() == 0) {
+            addresses.add(Constants.ANYHOST_VALUE);
+        }
+
+        addresses.forEach(addr -> {
+            String urlStr = "override://" + addr + "/";
+            List<String> apps = item.getApplications();
+            if (apps != null && apps.size() > 0) {
+                apps.forEach(app -> {
+                    urls.add(URL.valueOf(urlStr + appendService(serviceKey) + toParameterString(item) + "&application=" + app));
+                });
+            } else {
+                urls.add(URL.valueOf(urlStr + appendService(serviceKey) + toParameterString(item)));
+            }
+        });
+
+        return urls;
+    }
+
+    private static List<URL> appItemToUrls(ConfigItem item, String appKey) {
+        List<URL> urls = new ArrayList<>();
+        List<String> addresses = item.getAddresses();
+        if (addresses == null) {
+            addresses = new ArrayList<>();
+        }
+        if (addresses.size() == 0) {
+            addresses.add(Constants.ANYHOST_VALUE);
+        }
+        for (String addr : addresses) {
+            String urlStr = "override://" + addr + "/";
+            List<String> services = item.getServices();
+            if (services == null) {
+                services = new ArrayList<>();
+            }
+            if (services.size() == 0) {
+                services.add("*/*:*");
+            }
+            for (String s : services) {
+                urls.add(URL.valueOf(urlStr + appendService(s) + toParameterString(item) + "&application=" + appKey));
+            }
+        }
+        return urls;
+    }
+
+    private static String toParameterString(ConfigItem item) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("category=");
+        sb.append(Constants.DYNAMIC_CONFIGURATORS_CATEGORY);
+        if (item.getSide() != null) {
+            sb.append("&side=");
+            sb.append(item.getSide());
+        }
+        ConfiguratorRule rules = item.getRules();
+        if (rules == null || (rules.getThreadpool() == null && rules.getConfig() == null && rules.getCluster() == null)) {
+            throw new IllegalStateException("Invalid configurator rules!");
+        }
+        if (rules.getThreadpool() != null) {
+            rules.getThreadpool().forEach((k, v) -> {
+                sb.append("&");
+                sb.append(k);
+                sb.append("=");
+                sb.append(v);
+            });
+        }
+        if (rules.getCluster() != null) {
+            rules.getCluster().forEach((k, v) -> {
+                sb.append("&");
+                sb.append(k);
+                sb.append("=");
+                sb.append(v);
+            });
+        }
+        if (rules.getConfig() != null) {
+            rules.getConfig().forEach((k, v) -> {
+                sb.append("&");
+                sb.append(k);
+                sb.append("=");
+                sb.append(v);
+            });
+        }
+
+        return sb.toString();
+    }
+
+    private static String appendService(String serviceKey) {
+        StringBuilder sb = new StringBuilder();
+        if (StringUtils.isEmpty(serviceKey)) {
+            throw new IllegalStateException("service field in coniguration is null!");
+        }
+        String interfaceName = serviceKey;
+        int i = interfaceName.indexOf("/");
+        if (i > 0) {
+            sb.append("group=");
+            sb.append(interfaceName.substring(0, i));
+
+            interfaceName = interfaceName.substring(i + 1);
+        }
+        int j = interfaceName.indexOf(":");
+        if (j > 0) {
+            sb.append("version=");
+            sb.append(interfaceName.substring(j + 1));
+            interfaceName = interfaceName.substring(0, j);
+        }
+        sb.insert(0, interfaceName + "?");
+
+        return sb.toString();
+    }
+
+}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfigItem.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfigItem.java
new file mode 100644
index 0000000000..71d93c965e
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfigItem.java
@@ -0,0 +1,70 @@
+/*
+ * 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.integration.parser.model;
+
+import java.util.List;
+
+/**
+ *
+ */
+public class ConfigItem {
+    private List<String> addresses;
+    private List<String> services;
+    private List<String> applications;
+    private ConfiguratorRule rules;
+    private String side;
+
+    public List<String> getAddresses() {
+        return addresses;
+    }
+
+    public void setAddresses(List<String> addresses) {
+        this.addresses = addresses;
+    }
+
+    public List<String> getServices() {
+        return services;
+    }
+
+    public void setServices(List<String> services) {
+        this.services = services;
+    }
+
+    public List<String> getApplications() {
+        return applications;
+    }
+
+    public void setApplications(List<String> applications) {
+        this.applications = applications;
+    }
+
+    public ConfiguratorRule getRules() {
+        return rules;
+    }
+
+    public void setRules(ConfiguratorRule rules) {
+        this.rules = rules;
+    }
+
+    public String getSide() {
+        return side;
+    }
+
+    public void setSide(String side) {
+        this.side = side;
+    }
+}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfiguratorConfig.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfiguratorConfig.java
new file mode 100644
index 0000000000..db7aab76e1
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfiguratorConfig.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.registry.integration.parser.model;
+
+import java.util.List;
+
+/**
+ *
+ */
+public class ConfiguratorConfig {
+    public static final String SCOPE_SERVICE = "service";
+    public static final String SCOPE_APPLICATION = "application";
+
+    private String scope;
+    private String key;
+    private List<ConfigItem> configs;
+
+    public String getScope() {
+        return scope;
+    }
+
+    public void setScope(String scope) {
+        this.scope = scope;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public List<ConfigItem> getConfigs() {
+        return configs;
+    }
+
+    public void setConfigs(List<ConfigItem> configs) {
+        this.configs = configs;
+    }
+}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfiguratorRule.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfiguratorRule.java
new file mode 100644
index 0000000000..7fbdb87e2c
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfiguratorRule.java
@@ -0,0 +1,54 @@
+/*
+ * 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.integration.parser.model;
+
+import java.util.Map;
+
+/**
+ *
+ */
+public class ConfiguratorRule {
+    private Map<String, String> threadpool;
+
+    private Map<String, String> cluster;
+
+    private Map<String, String> config;
+
+    public Map<String, String> getThreadpool() {
+        return threadpool;
+    }
+
+    public void setThreadpool(Map<String, String> threadpool) {
+        this.threadpool = threadpool;
+    }
+
+    public Map<String, String> getCluster() {
+        return cluster;
+    }
+
+    public void setCluster(Map<String, String> cluster) {
+        this.cluster = cluster;
+    }
+
+    public Map<String, String> getConfig() {
+        return config;
+    }
+
+    public void setConfig(Map<String, String> config) {
+        this.config = config;
+    }
+}
diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/ConfigParserTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/ConfigParserTest.java
new file mode 100644
index 0000000000..bb90b9d8a1
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/ConfigParserTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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;
+
+import org.apache.dubbo.common.Constants;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.registry.integration.parser.ConfigParser;
+import org.apache.dubbo.registry.integration.parser.model.ConfigItem;
+import org.apache.dubbo.registry.integration.parser.model.ConfiguratorConfig;
+import org.junit.Assert;
+import org.junit.Test;
+import org.yaml.snakeyaml.TypeDescription;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
+
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ *
+ */
+public class ConfigParserTest {
+
+    private String streamToString(InputStream stream) {
+        try {
+            byte[] bytes = new byte[stream.available()];
+            stream.read(bytes);
+            return new String(bytes);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    @Test
+    public void snakeYamlBasicTest() {
+        InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml");
+
+        Constructor constructor = new Constructor(ConfiguratorConfig.class);
+        TypeDescription carDescription = new TypeDescription(ConfiguratorConfig.class);
+        carDescription.addPropertyParameters("items", ConfigItem.class);
+        constructor.addTypeDescription(carDescription);
+
+        Yaml yaml = new Yaml(constructor);
+        ConfiguratorConfig config = yaml.load(yamlStream);
+        System.out.println(config);
+    }
+
+    @Test
+    public void parseConfiguratorsServiceNoAppTest() throws Exception {
+        InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml");
+        List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+        Assert.assertNotNull(urls);
+        Assert.assertEquals(2, urls.size());
+        URL url = urls.get(0);
+        Assert.assertEquals(url.getAddress(), "127.0.0.1");
+        Assert.assertEquals(url.getParameter(Constants.TIMEOUT_KEY, 0), 6666);
+        Assert.assertEquals(url.getParameter(Constants.WEIGHT_KEY, 0), 222);
+        Assert.assertEquals(url.getParameter(Constants.LOADBALANCE_KEY), "random");
+        Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY, ""), "");
+    }
+
+    @Test
+    public void parseConfiguratorsServiceGroupVersionTest() throws Exception {
+        InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceGroupVersion.yml");
+        List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+        Assert.assertNotNull(urls);
+        Assert.assertEquals(1, urls.size());
+        URL url = urls.get(0);
+        Assert.assertEquals("testgroup", url.getParameter(Constants.GROUP_KEY));
+        Assert.assertEquals("1.0.0", url.getParameter(Constants.GROUP_KEY));
+    }
+
+    @Test
+    public void parseConfiguratorsServiceMultiAppsTest() {
+        InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceMultiApps.yml");
+        List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+        Assert.assertNotNull(urls);
+        Assert.assertEquals(4, urls.size());
+        URL url = urls.get(0);
+        Assert.assertEquals("127.0.0.1", url.getAddress());
+        Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
+        Assert.assertEquals(222, url.getParameter(Constants.WEIGHT_KEY, 0));
+        Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
+        Assert.assertNotNull(url.getParameter(Constants.APPLICATION_KEY));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void parseConfiguratorsServiceNoRuleTest() {
+        InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoRule.yml");
+        ConfigParser.parseConfigurators(streamToString(yamlStream));
+        Assert.fail();
+    }
+
+    @Test
+    public void parseConfiguratorsAppMultiServicesTest() {
+        InputStream yamlStream = this.getClass().getResourceAsStream("/AppMultiServices.yml");
+        List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+        Assert.assertNotNull(urls);
+        Assert.assertEquals(4, urls.size());
+        URL url = urls.get(0);
+        Assert.assertEquals("127.0.0.1", url.getAddress());
+        Assert.assertEquals("service1", url.getServiceInterface());
+        Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
+        Assert.assertEquals(222, url.getParameter(Constants.WEIGHT_KEY, 0));
+        Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
+        Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "app1");
+    }
+
+
+    @Test
+    public void parseConfiguratorsAppAnyServicesTest() {
+        InputStream yamlStream = this.getClass().getResourceAsStream("/AppAnyServices.yml");
+        List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+        Assert.assertNotNull(urls);
+        Assert.assertEquals(2, urls.size());
+        URL url = urls.get(0);
+        Assert.assertEquals("127.0.0.1", url.getAddress());
+        Assert.assertEquals("*", url.getServiceInterface());
+        Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
+        Assert.assertEquals(222, url.getParameter(Constants.WEIGHT_KEY, 0));
+        Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
+        Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "app1");
+    }
+
+    @Test
+    public void parseConfiguratorsAppNoServiceTest() {
+        InputStream yamlStream = this.getClass().getResourceAsStream("/AppNoService.yml");
+        List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+        Assert.assertNotNull(urls);
+        Assert.assertEquals(1, urls.size());
+        URL url = urls.get(0);
+        Assert.assertEquals("127.0.0.1", url.getAddress());
+        Assert.assertEquals("*", url.getServiceInterface());
+        Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
+        Assert.assertEquals(222, url.getParameter(Constants.WEIGHT_KEY, 0));
+        Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
+        Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "app1");
+    }
+
+}
diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/ZKTools.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/ZKTools.java
new file mode 100644
index 0000000000..5042068a25
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/ZKTools.java
@@ -0,0 +1,213 @@
+/*
+ * 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;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.recipes.cache.ChildData;
+import org.apache.curator.framework.recipes.cache.PathChildrenCache;
+import org.apache.curator.framework.recipes.cache.TreeCache;
+import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
+import org.apache.curator.framework.recipes.cache.TreeCacheListener;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.dubbo.common.utils.StringUtils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+
+/**
+ *
+ */
+public class ZKTools {
+    private static CuratorFramework client;
+
+    public static void main(String[] args) throws Exception {
+        client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000,
+                new ExponentialBackoffRetry(1000, 3));
+        client.start();
+
+//        testConsumerConfig();
+//        testPathCache();
+        testTreeCache();
+//        testCuratorListener();
+        System.in.read();
+    }
+
+    public static void testProviderConfig() {
+        String str = "{\n" +
+                "\t\"service\": \"org.apache.dubbo.demo.DemoService\",\n" +
+                "\t\"items\": [{\n" +
+                "\t\t\"addresses\": [\"30.5.120.49\"],\n" +
+                "\t\t\"rules\": [{\n" +
+                "\t\t\t\"key\": \"weight\",\n" +
+                "\t\t\t\"value\": 500\n" +
+                "\t\t}],\n" +
+                "\t\t\"app\": \"demo-provider\",\n" +
+                "\t\t\"side\": \"provider\"\n" +
+                "\t}]\n" +
+                "}";
+        try {
+            String path = "/dubbo/config/demo-provider/org.apache.dubbo.demo.DemoService.CONFIGURATORS";
+            if (client.checkExists().forPath(path) == null) {
+                client.create().creatingParentsIfNeeded().forPath(path);
+            }
+            setData(path, str);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void testConsumerConfig() {
+        String str = "{\n" +
+                "\t\"service\": \"org.apache.dubbo.demo.DemoService\",\n" +
+                "\t\"items\": [{\n" +
+                "\t\t\"addresses\": [\"30.5.120.48\"],\n" +
+                "\t\t\"rules\": [{\n" +
+                "\t\t\t\"key\": \"loadbalance\",\n" +
+                "\t\t\t\"value\": \"roundrobin\"\n" +
+                "\t\t}],\n" +
+                "\t\t\"app\": \"demo-consumer\",\n" +
+                "\t\t\"side\": \"consumer\"\n" +
+                "\t}]\n" +
+                "}";
+        try {
+            String path = "/dubbo/config/demo-consumer/org.apache.dubbo.demo.DemoService.CONFIGURATORS";
+            if (client.checkExists().forPath(path) == null) {
+                client.create().creatingParentsIfNeeded().forPath(path);
+            }
+            setData(path, str);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void setData(String path, String data) throws Exception {
+        client.setData().forPath(path, data.getBytes());
+    }
+
+    public static void testPathCache() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000,
+                new ExponentialBackoffRetry(1000, 3));
+        client.start();
+        PathChildrenCache pathChildrenCache = new PathChildrenCache(client, "/dubbo/config", true);
+        pathChildrenCache.start(true);
+        pathChildrenCache.getListenable().addListener((zkClient, event) -> {
+            System.out.println(event.getData().getPath());
+        }, Executors.newFixedThreadPool(1));
+        List<ChildData> dataList = pathChildrenCache.getCurrentData();
+        dataList.stream().map(ChildData::getPath).forEach(System.out::println);
+    }
+
+    public static void testTreeCache() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000,
+                new ExponentialBackoffRetry(1000, 3));
+        client.start();
+
+        CountDownLatch latch = new CountDownLatch(1);
+
+        TreeCache treeCache = TreeCache.newBuilder(client, "/dubbo/config").setCacheData(true).build();
+        treeCache.start();
+        treeCache.getListenable().addListener(new TreeCacheListener() {
+            @Override
+            public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
+
+                TreeCacheEvent.Type type = event.getType();
+                ChildData data = event.getData();
+
+                if (type == TreeCacheEvent.Type.INITIALIZED) {
+                    latch.countDown();
+                }
+
+                System.out.println(data.getPath() + "\n");
+
+                if (data.getPath().split("/").length == 5) {
+                    byte[] value = data.getData();
+                    String stringValue = new String(value, "utf-8");
+
+                    // fire event to all listeners
+                    Map<String, Object> added = null;
+                    Map<String, Object> changed = null;
+                    Map<String, Object> deleted = null;
+
+                    switch (type) {
+                        case NODE_ADDED:
+                            added = new HashMap<>(1);
+                            added.put(pathToKey(data.getPath()), stringValue);
+                            added.forEach((k, v) -> System.out.println(k + "  " + v));
+                            break;
+                        case NODE_REMOVED:
+                            deleted = new HashMap<>(1);
+                            deleted.put(pathToKey(data.getPath()), stringValue);
+                            deleted.forEach((k, v) -> System.out.println(k + "  " + v));
+                            break;
+                        case NODE_UPDATED:
+                            changed = new HashMap<>(1);
+                            changed.put(pathToKey(data.getPath()), stringValue);
+                            changed.forEach((k, v) -> System.out.println(k + "  " + v));
+                    }
+                }
+            }
+        });
+
+        latch.await();
+
+       /* Map<String, ChildData> dataMap = treeCache.getCurrentChildren("/dubbo/config");
+        dataMap.forEach((k, v) -> {
+            System.out.println(k);
+            treeCache.getCurrentChildren("/dubbo/config/" + k).forEach((ck, cv) -> {
+                System.out.println(ck);
+            });
+        });*/
+    }
+
+    private static String pathToKey(String path) {
+        if (StringUtils.isEmpty(path)) {
+            return path;
+        }
+        return path.replace("/dubbo/config/", "").replaceAll("/", ".");
+    }
+
+    public static void testCuratorListener() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000,
+                new ExponentialBackoffRetry(1000, 3));
+        client.start();
+
+        List<String> children = client.getChildren().forPath("/dubbo/config");
+        children.forEach(System.out::println);
+/*
+
+        client.getCuratorListenable().addListener(new CuratorListener() {
+            @Override
+            public void eventReceived(CuratorFramework curatorFramework, CuratorEvent curatorEvent) throws Exception {
+                curatorEvent.get
+            }
+        });
+*/
+
+        /*client.getChildren().usingWatcher(new CuratorWatcher() {
+            @Override
+            public void process(WatchedEvent watchedEvent) throws Exception {
+                System.out.println(watchedEvent.getPath());
+                client.getChildren().usingWatcher(this).forPath("/dubbo/config");
+                System.out.println(watchedEvent.getWrapper().getPath());
+            }
+        }).forPath("/dubbo/config");*/
+    }
+}
diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml b/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml
index a6cb828d87..e7a0298e29 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml
+++ b/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml
@@ -45,6 +45,11 @@
             <groupId>org.apache.curator</groupId>
             <artifactId>curator-framework</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.curator</groupId>
+            <artifactId>curator-recipes</artifactId>
+            <version>2.12.0</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.curator</groupId>
             <artifactId>curator-test</artifactId>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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