You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by mi...@apache.org on 2019/07/03 05:46:48 UTC

[dubbo-samples] branch master updated (7a4f25e -> aae8e91)

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

min pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git.


    from 7a4f25e  Add README for nacos sample
     new e264daa  add metrics sample
     new aae8e91  add metrics module

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


Summary of changes:
 dubbo-samples-metrics/README.md                    | 26 ++++++++
 .../pom.xml                                        | 31 +++++-----
 .../dubbo/samples/metrics}/EmbeddedZooKeeper.java  |  3 +-
 .../dubbo/samples/metrics/MetricsConsumer.java     | 39 ++++++++++++
 .../dubbo/samples/metrics/MetricsProvider.java     | 24 ++++----
 .../dubbo/samples/metrics/api/DemoService.java     | 34 +++++++++++
 .../samples/metrics/impl/DemoServiceImpl.java      | 70 ++++++++++++++++++++++
 .../apache/dubbo/samples/metrics/model/Result.java | 52 ++++++++++++++++
 .../apache/dubbo/samples/metrics/model/User.java   | 49 +++++++++++++++
 .../src/main/resources/log4j.properties            |  0
 .../main/resources/spring/dubbo-demo-consumer.xml  |  2 +-
 .../main/resources/spring/dubbo-demo-provider.xml  | 10 +++-
 pom.xml                                            |  1 +
 13 files changed, 309 insertions(+), 32 deletions(-)
 create mode 100644 dubbo-samples-metrics/README.md
 copy {dubbo-samples-basic => dubbo-samples-metrics}/pom.xml (93%)
 copy {dubbo-samples-compatible/src/main/java/org/apache/dubbo/samples/compat => dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics}/EmbeddedZooKeeper.java (99%)
 create mode 100644 dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsConsumer.java
 copy dubbo-samples-consul/src/main/java/org/apache/dubbo/samples/consul/ConsulProvider.java => dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsProvider.java (52%)
 create mode 100644 dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/api/DemoService.java
 create mode 100644 dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/impl/DemoServiceImpl.java
 create mode 100644 dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/model/Result.java
 create mode 100644 dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/model/User.java
 copy {dubbo-samples-zipkin => dubbo-samples-metrics}/src/main/resources/log4j.properties (100%)
 copy {dubbo-samples-basic => dubbo-samples-metrics}/src/main/resources/spring/dubbo-demo-consumer.xml (97%)
 copy {dubbo-samples-basic => dubbo-samples-metrics}/src/main/resources/spring/dubbo-demo-provider.xml (78%)


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


[dubbo-samples] 02/02: add metrics module

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

min pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git

commit aae8e91cf2184bc7ee11d12fd5321e63e44dfcd3
Author: nzomkxia <z8...@gmail.com>
AuthorDate: Wed Jul 3 13:47:27 2019 +0800

    add metrics module
---
 pom.xml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pom.xml b/pom.xml
index 98ba925..7173797 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,6 +71,7 @@
         <module>dubbo-samples-consul</module>
         <module>dubbo-samples-edas</module>
         <module>dubbo-samples-nacos</module>
+        <module>dubbo-samples-metrics</module>
     </modules>
     <properties>
         <!-- Test libs -->


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


[dubbo-samples] 01/02: add metrics sample

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

min pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git

commit e264daa940ec3aaa66ac0bde1aa7076de277d941
Author: nzomkxia <z8...@gmail.com>
AuthorDate: Wed Jul 3 13:45:45 2019 +0800

    add metrics sample
---
 dubbo-samples-metrics/README.md                    |  26 +++
 dubbo-samples-metrics/pom.xml                      | 199 ++++++++++++++++
 .../dubbo/samples/metrics/EmbeddedZooKeeper.java   | 256 +++++++++++++++++++++
 .../dubbo/samples/metrics/MetricsConsumer.java     |  39 ++++
 .../dubbo/samples/metrics/MetricsProvider.java     |  32 +++
 .../dubbo/samples/metrics/api/DemoService.java     |  34 +++
 .../samples/metrics/impl/DemoServiceImpl.java      |  70 ++++++
 .../apache/dubbo/samples/metrics/model/Result.java |  52 +++++
 .../apache/dubbo/samples/metrics/model/User.java   |  49 ++++
 .../src/main/resources/log4j.properties            |  26 +++
 .../main/resources/spring/dubbo-demo-consumer.xml  |  36 +++
 .../main/resources/spring/dubbo-demo-provider.xml  |  42 ++++
 12 files changed, 861 insertions(+)

diff --git a/dubbo-samples-metrics/README.md b/dubbo-samples-metrics/README.md
new file mode 100644
index 0000000..433a7fd
--- /dev/null
+++ b/dubbo-samples-metrics/README.md
@@ -0,0 +1,26 @@
+# 使用Metrics模块进行数据采集
+Dubbo使用开源的[Dubbo Metrics](https://github.com/alibaba/metrics)进行数据埋点,并且通过服务暴露,使用的时候,首先需要进行配置:  
+
+* 依赖(其中dubbo版本在2.7.2及以后)
+```xml
+<dependency>
+    <groupId>org.apache.dubbo</groupId>
+    <artifactId>dubbo-monitor-default</artifactId>
+    <version>${dubbo.version}</version> 
+</dependency>
+```
+* 服务端
+```xml
+<dubbo:metrics port="20880" protocol="dubbo"/>
+<dubbo:provider filter="metrics" />
+```
+
+* 客户端
+```xml
+<dubbo:metrics port="20880" protocol="dubbo"/>
+<dubbo:consumer filter="metrics" />
+```
+其中,`<dubbo:metrics />`的配置指定了metrics暴露的协议和端口,这些信息会被放在元数据里面,而`<dubbo:provider />`和`<dubbo: consuer />`则在服务端和客户端分别激活了metrics的filter,如果你的服务分别含有服务端和客户端,选择在一端激活就可以。
+
+* dubbo admin  
+完成这些配置后,获取[dubbo admin](https://github.com/apache/dubbo-admin)在`develop`分支的最新代码,启动后,在左侧Metrics(统计)标签输入目标机器的IP,可以看到调用,线程池等Metrics信息
diff --git a/dubbo-samples-metrics/pom.xml b/dubbo-samples-metrics/pom.xml
new file mode 100644
index 0000000..392840e
--- /dev/null
+++ b/dubbo-samples-metrics/pom.xml
@@ -0,0 +1,199 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>dubbo-samples-all</artifactId>
+        <groupId>org.apache.dubbo</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>dubbo-samples-metrics</artifactId>
+
+    <properties>
+        <source.level>1.8</source.level>
+        <target.level>1.8</target.level>
+        <dubbo.version>2.7.2</dubbo.version>
+        <junit.version>4.12</junit.version>
+        <docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
+        <jib-maven-plugin.version>1.2.0</jib-maven-plugin.version>
+        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+        <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
+        <image.name>${artifactId}:${dubbo.version}</image.name>
+        <dubbo.port>20880</dubbo.port>
+        <main-class>org.apache.dubbo.samples.basic.BasicProvider</main-class>
+        <spring-test.version>4.3.16.RELEASE</spring-test.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo</artifactId>
+            <version>${dubbo.version}</version>
+        </dependency>
+
+
+<!--        dependency for metrics-->
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-monitor-default</artifactId>
+            <version>${dubbo.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-dependencies-zookeeper</artifactId>
+            <version>${dubbo.version}</version>
+            <type>pom</type>
+        </dependency>
+
+    </dependencies>
+
+    <profiles>
+        <profile>
+            <id>dubbo-integration-test</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.dubbo</groupId>
+                        <artifactId>dubbo-maven-address-plugin</artifactId>
+                        <version>1.0-SNAPSHOT</version>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>local-address</goal>
+                                </goals>
+                                <configuration>
+                                    <localAddress>dubbo-local-address</localAddress>
+                                </configuration>
+                                <phase>initialize</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>com.google.cloud.tools</groupId>
+                        <artifactId>jib-maven-plugin</artifactId>
+                        <version>${jib-maven-plugin.version}</version>
+                        <configuration>
+                            <from>
+                                <image>${java-image.name}</image>
+                            </from>
+                            <to>
+                                <image>${image.name}</image>
+                            </to>
+                            <container>
+                                <mainClass>${main-class}</mainClass>
+                                <ports>
+                                    <port>${dubbo.port}</port>
+                                    <port>2181</port>
+                                </ports>
+                                <environment>
+                                    <DUBBO_IP_TO_REGISTRY>${dubbo-local-address}</DUBBO_IP_TO_REGISTRY>
+                                </environment>
+                            </container>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>dockerBuild</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>io.fabric8</groupId>
+                        <artifactId>docker-maven-plugin</artifactId>
+                        <version>${docker-maven-plugin.version}</version>
+                        <configuration>
+                            <images>
+                                <image>
+                                    <name>${image.name}</name>
+                                    <run>
+                                        <ports>
+                                            <port>${dubbo.port}:${dubbo.port}</port>
+                                            <port>2181:2181</port>
+                                        </ports>
+                                        <wait>
+                                            <log>dubbo service started</log>
+                                        </wait>
+                                    </run>
+                                </image>
+                            </images>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <id>start</id>
+                                <phase>pre-integration-test</phase>
+                                <goals>
+                                    <goal>start</goal>
+                                </goals>
+                            </execution>
+                            <execution>
+                                <id>stop</id>
+                                <phase>post-integration-test</phase>
+                                <goals>
+                                    <goal>stop</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <version>${maven-failsafe-plugin.version}</version>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>integration-test</goal>
+                                    <goal>verify</goal>
+                                </goals>
+                                <configuration>
+                                    <includes>
+                                        <include>**/*IT.java</include>
+                                    </includes>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${maven-compiler-plugin.version}</version>
+                <configuration>
+                    <source>${source.level}</source>
+                    <target>${target.level}</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>
diff --git a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/EmbeddedZooKeeper.java b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/EmbeddedZooKeeper.java
new file mode 100644
index 0000000..1ead3d0
--- /dev/null
+++ b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/EmbeddedZooKeeper.java
@@ -0,0 +1,256 @@
+/*
+ * 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.metrics;
+
+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
+ *
+ * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper.
+ *
+ * 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);
+                }
+            }
+        }
+    }
+
+}
+
diff --git a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsConsumer.java b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsConsumer.java
new file mode 100644
index 0000000..d8c7b5c
--- /dev/null
+++ b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsConsumer.java
@@ -0,0 +1,39 @@
+/*
+ * 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.metrics;
+
+import org.apache.dubbo.samples.metrics.api.DemoService;
+import org.apache.dubbo.samples.metrics.model.Result;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class MetricsConsumer {
+
+    public static void main(String[] args) {
+        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
+        context.start();
+        DemoService demoService = (DemoService) context.getBean("demoService");
+        while (true) {
+            try {
+                Thread.sleep(3000);
+                Result hello = demoService.sayHello("world");
+                System.out.println(hello.getMsg());
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}
diff --git a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsProvider.java b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsProvider.java
new file mode 100644
index 0000000..745056d
--- /dev/null
+++ b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/MetricsProvider.java
@@ -0,0 +1,32 @@
+/*
+ * 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.metrics;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class MetricsProvider {
+
+    public static void main(String[] args) throws Exception {
+        new EmbeddedZooKeeper(2181, false).start();
+        // wait for embedded zookeeper start completely.
+        Thread.sleep(1000);
+        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml");
+        context.start();
+        System.out.println("dubbo service started");
+        System.in.read();
+    }
+}
diff --git a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/api/DemoService.java b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/api/DemoService.java
new file mode 100644
index 0000000..72ef1eb
--- /dev/null
+++ b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/api/DemoService.java
@@ -0,0 +1,34 @@
+/*
+ * 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.metrics.api;
+
+import org.apache.dubbo.samples.metrics.model.Result;
+import org.apache.dubbo.samples.metrics.model.User;
+
+import java.util.concurrent.CompletableFuture;
+
+public interface DemoService {
+    CompletableFuture<Integer> sayHello();
+
+    Result sayHello(String name);
+
+    Result sayHello(Long id, String name);
+
+    Result sayHello(User user);
+
+    String stringArray(String[] bytes);
+}
diff --git a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/impl/DemoServiceImpl.java b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/impl/DemoServiceImpl.java
new file mode 100644
index 0000000..bf7392f
--- /dev/null
+++ b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/impl/DemoServiceImpl.java
@@ -0,0 +1,70 @@
+/*
+ * 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.metrics.impl;
+
+import com.alibaba.dubbo.rpc.RpcContext;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.samples.metrics.api.DemoService;
+import org.apache.dubbo.samples.metrics.model.Result;
+import org.apache.dubbo.samples.metrics.model.User;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.concurrent.CompletableFuture;
+
+public class DemoServiceImpl implements DemoService {
+
+    public static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class);
+
+    private String name = "Han MeiMei";
+
+    @Override
+    public CompletableFuture<Integer> sayHello() {
+        return CompletableFuture.completedFuture(2122);
+    }
+
+
+
+    @Override
+    public Result sayHello(String localName) {
+        logger.info("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name + ", request from consumer: " + RpcContext
+                .getContext().getRemoteAddress());
+        return new Result(name, "Hello " + localName + ", response from provider: " + RpcContext.getContext().getLocalAddress());
+    }
+
+    @Override
+    public Result sayHello(final Long id, final String name) {
+        return sayHello(new User(id, name));
+    }
+
+    @Override
+    public Result sayHello(final User user) {
+        String localName = user.getUsername();
+        Long id = user.getId();
+        logger.info("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name + ", request from consumer: " + RpcContext
+                .getContext().getRemoteAddress());
+        return new Result(name, "Hello " + id + " " + localName +
+//                " " + "bytes: " + user.getBytes().toString() +
+                ", response from provider: " + RpcContext.getContext().getLocalAddress());
+    }
+
+    @Override
+    public String stringArray(String[] bytes) {
+        return bytes.toString();
+    }
+}
diff --git a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/model/Result.java b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/model/Result.java
new file mode 100644
index 0000000..6612fd5
--- /dev/null
+++ b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/model/Result.java
@@ -0,0 +1,52 @@
+/*
+ * 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.metrics.model;
+
+import java.io.Serializable;
+
+/**
+ * @author zmx ON 2019-07-03
+ */
+public class Result implements Serializable {
+    public Result(){
+
+    }
+
+    public Result(String userName, String msg){
+        this.msg = msg;
+        this.userName = userName;
+    }
+
+    private String userName;
+    private String msg;
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+}
diff --git a/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/model/User.java b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/model/User.java
new file mode 100644
index 0000000..fd28961
--- /dev/null
+++ b/dubbo-samples-metrics/src/main/java/org/apache/dubbo/samples/metrics/model/User.java
@@ -0,0 +1,49 @@
+/*
+ * 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.metrics.model;
+
+import java.io.Serializable;
+
+public class User implements Serializable {
+    private Long id;
+    private String username;
+
+    public User() {
+    }
+
+    public User(final Long id, final String username) {
+        this.id = id;
+        this.username = username;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(final Long id) {
+        this.id = id;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(final String username) {
+        this.username = username;
+    }
+
+}
diff --git a/dubbo-samples-metrics/src/main/resources/log4j.properties b/dubbo-samples-metrics/src/main/resources/log4j.properties
new file mode 100644
index 0000000..d6ecd5c
--- /dev/null
+++ b/dubbo-samples-metrics/src/main/resources/log4j.properties
@@ -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.
+#
+#
+
+###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-metrics/src/main/resources/spring/dubbo-demo-consumer.xml b/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-consumer.xml
new file mode 100644
index 0000000..b29fcad
--- /dev/null
+++ b/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-consumer.xml
@@ -0,0 +1,36 @@
+<?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.xsd
+       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+
+    <!-- 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"/>
+
+    <!-- use multicast registry center to discover service -->
+    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
+
+    <!-- generate proxy for the remote service, then demoService can be used in the same way as the
+    local regular interface -->
+    <dubbo:reference id="demoService" check="true" interface="org.apache.dubbo.samples.metrics.api.DemoService"/>
+
+</beans>
diff --git a/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-provider.xml
new file mode 100644
index 0000000..4281103
--- /dev/null
+++ b/dubbo-samples-metrics/src/main/resources/spring/dubbo-demo-provider.xml
@@ -0,0 +1,42 @@
+<?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.xsd
+       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+
+    <!-- provider's application name, used for tracing dependency relationship -->
+    <dubbo:application name="demo-provider"/>
+
+    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
+    <dubbo:config-center address="zookeeper://127.0.0.1:2181" />
+    <dubbo:metadata-report address="zookeeper://127.0.0.1:2181" />
+
+    <dubbo:metrics port="20880" protocol="dubbo"/>
+    <dubbo:provider filter="metrics" />
+
+
+    <!-- service implementation, as same as regular local bean -->
+    <bean id="demoService" class="org.apache.dubbo.samples.metrics.impl.DemoServiceImpl"/>
+
+    <!-- declare the service interface to be exported -->
+    <dubbo:service interface="org.apache.dubbo.samples.metrics.api.DemoService" ref="demoService"/>
+
+</beans>


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