You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by li...@apache.org on 2019/01/17 06:15:31 UTC

[incubator-dubbo-samples] branch samples-for-2.7.0-SNAPSHOT updated: Add apollo sample

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

liujun pushed a commit to branch samples-for-2.7.0-SNAPSHOT
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo-samples.git


The following commit(s) were added to refs/heads/samples-for-2.7.0-SNAPSHOT by this push:
     new e4c9947  Add apollo sample
e4c9947 is described below

commit e4c9947d1f58465970dc301395d717d6b711cfdd
Author: ken.lj <ke...@gmail.com>
AuthorDate: Thu Jan 17 14:15:19 2019 +0800

    Add apollo sample
---
 .../pom.xml                                        |  26 +--
 .../dubbo/samples/configcenter/ApolloConsumer.java |  45 ++++
 .../dubbo/samples/configcenter/ApolloProvider.java |  35 +++
 .../samples/configcenter/EmbeddedZooKeeper.java    | 250 +++++++++++++++++++++
 .../apache/dubbo/samples/configcenter/ZKTools.java |  89 ++++++++
 .../samples/configcenter/api/DemoService.java      |  26 +++
 .../samples/configcenter/impl/DemoServiceImpl.java |  38 ++++
 .../src/main/resources/META-INF/app.properties     |   1 +
 .../META-INF/spring/configcenter-consumer.xml      |  34 +++
 .../META-INF/spring/configcenter-provider.xml      |  37 +++
 .../src/main/resources/config-center.properties    |  24 ++
 .../src/main/resources/log4j.properties            |  25 +++
 dubbo-samples-configcenter/pom.xml                 |   2 +-
 13 files changed, 609 insertions(+), 23 deletions(-)

diff --git a/dubbo-samples-configcenter/pom.xml b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/pom.xml
similarity index 58%
copy from dubbo-samples-configcenter/pom.xml
copy to dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/pom.xml
index b8764dc..cd06f72 100644
--- a/dubbo-samples-configcenter/pom.xml
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/pom.xml
@@ -22,37 +22,19 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>dubbo-samples-all</artifactId>
+        <artifactId>dubbo-samples-configcenter</artifactId>
         <groupId>org.apache.dubbo</groupId>
         <version>1.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-    <packaging>pom</packaging>
 
-    <modules>
-        <module>dubbo-samples-configcenter-xml</module>
-        <module>dubbo-samples-configcenter-multiprotocol</module>
-        <module>dubbo-samples-configcenter-multi-registries</module>
-        <module>dubbo-samples-configcenter-annotation</module>
-        <module>dubbo-samples-configcenter-externalconfiguration</module>
-        <module>dubbo-samples-configcenter-api</module>
-        <!--<module>dubbo-samples-configcenter-springboot</module>-->
-    </modules>
+    <artifactId>dubbo-samples-configcenter-apollo</artifactId>
 
-
-    <artifactId>dubbo-samples-configcenter</artifactId>
     <dependencies>
         <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-context</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.apache.dubbo</groupId>
-            <artifactId>dubbo-configcenter-zookeeper</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.dubbo</groupId>
-            <artifactId>dubbo-metadata-report-api</artifactId>
+            <artifactId>dubbo-configcenter-apollo</artifactId>
         </dependency>
     </dependencies>
+
 </project>
\ No newline at end of file
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/ApolloConsumer.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/ApolloConsumer.java
new file mode 100644
index 0000000..3f15903
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/ApolloConsumer.java
@@ -0,0 +1,45 @@
+/*
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements.  See the NOTICE file distributed with
+ *   this work for additional information regarding copyright ownership.
+ *   The ASF licenses this file to You under the Apache License, Version 2.0
+ *   (the "License"); you may not use this file except in compliance with
+ *   the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.dubbo.samples.configcenter;
+
+import org.apache.dubbo.samples.configcenter.api.DemoService;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class ApolloConsumer {
+
+    public static void main(String[] args) {
+        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/configcenter-consumer.xml"});
+        context.start();
+        DemoService demoService = (DemoService) context.getBean("demoService"); // get remote service proxy
+
+        while (true) {
+            try {
+                Thread.sleep(1000);
+                String hello = demoService.sayHello("world"); // call remote method
+                System.out.println(hello); // get result
+
+            } catch (Throwable throwable) {
+                throwable.printStackTrace();
+            }
+        }
+
+    }
+}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/ApolloProvider.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/ApolloProvider.java
new file mode 100644
index 0000000..7f3b59e
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/ApolloProvider.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.samples.configcenter;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class ApolloProvider {
+
+    public static void main(String[] args) throws Exception {
+//        new EmbeddedZooKeeper(2181, false).start();
+        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/configcenter-provider.xml"});
+        context.registerShutdownHook();
+        context.start();
+
+        System.in.read(); // press any key to exit
+    }
+
+}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/EmbeddedZooKeeper.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/EmbeddedZooKeeper.java
new file mode 100644
index 0000000..e2013f3
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/EmbeddedZooKeeper.java
@@ -0,0 +1,250 @@
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.samples.configcenter;
+
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.util.ErrorHandler;
+import org.springframework.util.SocketUtils;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
+ * <p>
+ * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper.
+ * <p>
+ * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for
+ * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
+ *
+ * @author Patrick Peralta
+ * @author Mark Fisher
+ * @author David Turanski
+ */
+public class EmbeddedZooKeeper implements SmartLifecycle {
+
+    /**
+     * Logger.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class);
+
+    /**
+     * ZooKeeper client port. This will be determined dynamically upon startup.
+     */
+    private final int clientPort;
+
+    /**
+     * Whether to auto-start. Default is true.
+     */
+    private boolean autoStartup = true;
+
+    /**
+     * Lifecycle phase. Default is 0.
+     */
+    private int phase = 0;
+
+    /**
+     * Thread for running the ZooKeeper server.
+     */
+    private volatile Thread zkServerThread;
+
+    /**
+     * ZooKeeper server.
+     */
+    private volatile ZooKeeperServerMain zkServer;
+
+    /**
+     * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread.
+     */
+    private ErrorHandler errorHandler;
+
+    private boolean daemon = true;
+
+    /**
+     * Construct an EmbeddedZooKeeper with a random port.
+     */
+    public EmbeddedZooKeeper() {
+        clientPort = SocketUtils.findAvailableTcpPort();
+    }
+
+    /**
+     * Construct an EmbeddedZooKeeper with the provided port.
+     *
+     * @param clientPort port for ZooKeeper server to bind to
+     */
+    public EmbeddedZooKeeper(int clientPort, boolean daemon) {
+        this.clientPort = clientPort;
+        this.daemon = daemon;
+    }
+
+    /**
+     * Returns the port that clients should use to connect to this embedded server.
+     *
+     * @return dynamically determined client port
+     */
+    public int getClientPort() {
+        return this.clientPort;
+    }
+
+    /**
+     * Specify whether to start automatically. Default is true.
+     *
+     * @param autoStartup whether to start automatically
+     */
+    public void setAutoStartup(boolean autoStartup) {
+        this.autoStartup = autoStartup;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isAutoStartup() {
+        return this.autoStartup;
+    }
+
+    /**
+     * Specify the lifecycle phase for the embedded server.
+     *
+     * @param phase the lifecycle phase
+     */
+    public void setPhase(int phase) {
+        this.phase = phase;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int getPhase() {
+        return this.phase;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isRunning() {
+        return (zkServerThread != null);
+    }
+
+    /**
+     * Start the ZooKeeper server in a background thread.
+     * <p>
+     * Register an error handler via {@link #setErrorHandler} in order to handle
+     * any exceptions thrown during startup or execution.
+     */
+    @Override
+    public synchronized void start() {
+        if (zkServerThread == null) {
+            zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter");
+            zkServerThread.setDaemon(daemon);
+            zkServerThread.start();
+        }
+    }
+
+    /**
+     * Shutdown the ZooKeeper server.
+     */
+    @Override
+    public synchronized void stop() {
+        if (zkServerThread != null) {
+            // The shutdown method is protected...thus this hack to invoke it.
+            // This will log an exception on shutdown; see
+            // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details.
+            try {
+                Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
+                shutdown.setAccessible(true);
+                shutdown.invoke(zkServer);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+
+            // It is expected that the thread will exit after
+            // the server is shutdown; this will block until
+            // the shutdown is complete.
+            try {
+                zkServerThread.join(5000);
+                zkServerThread = null;
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+                logger.warn("Interrupted while waiting for embedded ZooKeeper to exit");
+                // abandoning zk thread
+                zkServerThread = null;
+            }
+        }
+    }
+
+    /**
+     * Stop the server if running and invoke the callback when complete.
+     */
+    @Override
+    public void stop(Runnable callback) {
+        stop();
+        callback.run();
+    }
+
+    /**
+     * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none
+     * is provided, only error-level logging will occur.
+     *
+     * @param errorHandler the {@link ErrorHandler} to be invoked
+     */
+    public void setErrorHandler(ErrorHandler errorHandler) {
+        this.errorHandler = errorHandler;
+    }
+
+    /**
+     * Runnable implementation that starts the ZooKeeper server.
+     */
+    private class ServerRunnable implements Runnable {
+
+        @Override
+        public void run() {
+            try {
+                Properties properties = new Properties();
+                File file = new File(System.getProperty("java.io.tmpdir")
+                        + File.separator + UUID.randomUUID());
+                file.deleteOnExit();
+                properties.setProperty("dataDir", file.getAbsolutePath());
+                properties.setProperty("clientPort", String.valueOf(clientPort));
+
+                QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
+                quorumPeerConfig.parseProperties(properties);
+
+                zkServer = new ZooKeeperServerMain();
+                ServerConfig configuration = new ServerConfig();
+                configuration.readFrom(quorumPeerConfig);
+
+                zkServer.runFromConfig(configuration);
+            } catch (Exception e) {
+                if (errorHandler != null) {
+                    errorHandler.handleError(e);
+                } else {
+                    logger.error("Exception running embedded ZooKeeper", e);
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/ZKTools.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/ZKTools.java
new file mode 100644
index 0000000..a66802c
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/ZKTools.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.samples.configcenter;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+
+/**
+ *
+ */
+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();
+
+        generateDubboPropertiesForGlobal();
+        System.in.read();
+        generateDubboPropertiesForApp();
+    }
+
+    public static void generateDubboPropertiesForGlobal() {
+        String str = "dubbo.registry.address=zookeeper://127.0.0.1:2181\n" +
+                "dubbo.metadata-report.address=zookeeper://127.0.0.1:2181\n" +
+                "dubbo.protocol.port=-1\n" +
+                "dubbo.registry.simplified=true\n";
+
+        System.out.println(str);
+
+        try {
+            String path = "/dubbo/config/dubbo/dubbo.properties";
+            if (client.checkExists().forPath(path) == null) {
+                client.create().creatingParentsIfNeeded().forPath(path);
+            }
+            setData(path, str);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void generateDubboPropertiesForApp() {
+        String str = "dubbo.consumer.timeout=6666\n" +
+                "dubbo.application.qos.port=33333\n" +
+                "dubbo.reference.org.apache.dubbo.samples.configcenter.api.DemoService.timeout=9999";
+
+        System.out.println(str);
+
+        try {
+            String path = "/dubbo/config/configcenter-consumer/dubbo.properties";
+            if (client.checkExists().forPath(path) == null) {
+                client.create().creatingParentsIfNeeded().forPath(path);
+            }
+            setData(path, str);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static void createNode(String path) throws Exception {
+        client.create().forPath(path);
+    }
+
+    private static void deleteNode(String path) throws Exception {
+        client.delete().forPath(path);
+    }
+
+    private static void setData(String path, String data) throws Exception {
+        client.setData().forPath(path, data.getBytes());
+    }
+
+
+}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/api/DemoService.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/api/DemoService.java
new file mode 100644
index 0000000..b42cbc5
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/api/DemoService.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.samples.configcenter.api;
+
+public interface DemoService {
+
+    String sayHello(String name);
+
+}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
new file mode 100644
index 0000000..a8fd926
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
@@ -0,0 +1,38 @@
+/*
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements.  See the NOTICE file distributed with
+ *   this work for additional information regarding copyright ownership.
+ *   The ASF licenses this file to You under the Apache License, Version 2.0
+ *   (the "License"); you may not use this file except in compliance with
+ *   the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.dubbo.samples.configcenter.impl;
+
+
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.samples.configcenter.api.DemoService;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class DemoServiceImpl implements DemoService {
+
+    @Override
+    public String sayHello(String name) {
+        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name + ", request from consumer: " + RpcContext
+                .getContext().getRemoteAddress());
+        return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
+    }
+
+}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/META-INF/app.properties b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/META-INF/app.properties
new file mode 100644
index 0000000..21593cb
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/META-INF/app.properties
@@ -0,0 +1 @@
+app.id=dubbo-configcenter-apollo
\ No newline at end of file
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/META-INF/spring/configcenter-consumer.xml b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/META-INF/spring/configcenter-consumer.xml
new file mode 100644
index 0000000..c34bc4d
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/META-INF/spring/configcenter-consumer.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~
+  ~   Licensed to the Apache Software Foundation (ASF) under one or more
+  ~   contributor license agreements.  See the NOTICE file distributed with
+  ~   this work for additional information regarding copyright ownership.
+  ~   The ASF licenses this file to You under the Apache License, Version 2.0
+  ~   (the "License"); you may not use this file except in compliance with
+  ~   the License.  You may obtain a copy of the License at
+  ~
+  ~       http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~   Unless required by applicable law or agreed to in writing, software
+  ~   distributed under the License is distributed on an "AS IS" BASIS,
+  ~   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~   See the License for the specific language governing permissions and
+  ~   limitations under the License.
+  ~
+  -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+       xmlns="http://www.springframework.org/schema/beans"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
+       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+
+    <!-- optional -->
+    <dubbo:application name="dubbo-configcenter-apollo-consumer"/>
+
+    <dubbo:config-center highest-priority="false" protocol="apollo" address="106.12.25.204:8080"/>
+
+    <dubbo:reference group="*" id="demoService" interface="org.apache.dubbo.samples.configcenter.api.DemoService"/>
+
+</beans>
\ No newline at end of file
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/META-INF/spring/configcenter-provider.xml b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/META-INF/spring/configcenter-provider.xml
new file mode 100644
index 0000000..61e9173
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/META-INF/spring/configcenter-provider.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~
+  ~   Licensed to the Apache Software Foundation (ASF) under one or more
+  ~   contributor license agreements.  See the NOTICE file distributed with
+  ~   this work for additional information regarding copyright ownership.
+  ~   The ASF licenses this file to You under the Apache License, Version 2.0
+  ~   (the "License"); you may not use this file except in compliance with
+  ~   the License.  You may obtain a copy of the License at
+  ~
+  ~       http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~   Unless required by applicable law or agreed to in writing, software
+  ~   distributed under the License is distributed on an "AS IS" BASIS,
+  ~   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~   See the License for the specific language governing permissions and
+  ~   limitations under the License.
+  ~
+  -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+       xmlns="http://www.springframework.org/schema/beans"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
+       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+
+    <!-- optional -->
+    <dubbo:application name="dubbo-configcenter-apollo"/>
+
+    <!--<dubbo:registry address="zookeeper://127.0.0.1:2181"/>-->
+    <!--<dubbo:protocol port="-1"/>-->
+
+    <dubbo:config-center address="apollo://106.12.25.204:8080"/>
+
+    <bean id="demoService" class="org.apache.dubbo.samples.configcenter.impl.DemoServiceImpl"/>
+    <dubbo:service group="test2" interface="org.apache.dubbo.samples.configcenter.api.DemoService" ref="demoService"/>
+</beans>
\ No newline at end of file
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/config-center.properties b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/config-center.properties
new file mode 100644
index 0000000..9e3fbc5
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/config-center.properties
@@ -0,0 +1,24 @@
+#   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.
+# Add the following global external properties to `/dubbo/config/dubbo/dubbo.properties`
+dubbo.registry.address=zookeeper://127.0.0.1:2181
+dubbo.protocol.port=-1
+dubbo.metadata-report.address=zookeeper://127.0.0.1:2181
+dubbo.registry.simplified=true
+# Optional. Add the following application(Consumer) specific external properties
+# to `/dubbo/config/configcenter-consumer/dubbo.properties`
+dubbo.consumer.timeout=6666
+dubbo.application.qos.port=33333
+dubbo.reference.org.apache.dubbo.samples.configcenter.api.DemoService.timeout=9999
\ No newline at end of file
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/log4j.properties b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/log4j.properties
new file mode 100644
index 0000000..f30fda0
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-apollo/src/main/resources/log4j.properties
@@ -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.
+#
+#
+###set log levels###
+log4j.rootLogger=info, stdout
+###output to the console###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy hh:mm:ss:sss z}] %t %5p %c{2}: %m%n
\ No newline at end of file
diff --git a/dubbo-samples-configcenter/pom.xml b/dubbo-samples-configcenter/pom.xml
index b8764dc..b2a2f5d 100644
--- a/dubbo-samples-configcenter/pom.xml
+++ b/dubbo-samples-configcenter/pom.xml
@@ -36,7 +36,7 @@
         <module>dubbo-samples-configcenter-annotation</module>
         <module>dubbo-samples-configcenter-externalconfiguration</module>
         <module>dubbo-samples-configcenter-api</module>
-        <!--<module>dubbo-samples-configcenter-springboot</module>-->
+        <module>dubbo-samples-configcenter-apollo</module>
     </modules>
 
 


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