nobodyiam commented on a change in 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#discussion_r208119317
 
 

 ##########
 File path: 
dubbo-config/dubbo-config-dynamic/src/main/java/org/apache/dubbo/config/dynamic/support/apollo/ApolloDynamicConfiguration.java
 ##########
 @@ -0,0 +1,134 @@
+/*
+ * 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.config.dynamic.AbstractDynamicConfiguration;
+import org.apache.dubbo.config.dynamic.ConfigChangeType;
+import org.apache.dubbo.config.dynamic.ConfigType;
+import org.apache.dubbo.config.dynamic.ConfigurationListener;
+
+/**
+ *
+ */
+public class ApolloDynamicConfiguration extends AbstractDynamicConfiguration {
+    private static final String APOLLO_ENV_KEY = "env";
+    // FIXME the key?
+    private static final String APOLLO_ADDR_KEY = "";
+    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.getParameter(Constants.CONFIG_ADDRESS_KEY);
+        String configCluster = url.getParameter(Constants.CONFIG_CLUSTER_KEY);
+        if (configEnv != null) {
+            System.setProperty(APOLLO_ENV_KEY, configEnv);
+        }
+        if (configAddr != null) {
+            System.setProperty(APOLLO_ADDR_KEY, configAddr);
+        }
+        if (configCluster != null) {
+            System.setProperty(APOLLO_CLUSTER_KEY, configCluster);
+        }
+
+        dubboConfig = ConfigService.getConfig("dubbo");
 
 Review comment:
   I think it may be better to let the user pass the namespace name for dubbo 
config?
   
   If not specified, then we could use a default namespace, such as 
`application`.
   
   Because I think in some companies, they will tend to maintain a public 
inheritable config to provide an optimized default, and also allow the specific 
application to override some of the configs. And for those configs, the name 
will not be `dubbo` because in apollo, public namespaces are always prefixed 
with department prefix to ensure uniqueness.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to