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

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


The following commit(s) were added to refs/heads/main by this push:
     new 4d8d1c6  add broadcast1 (#10)
4d8d1c6 is described below

commit 4d8d1c659174c63d12970009c0fe5ca5071ba15f
Author: 王聪洋 <[email protected]>
AuthorDate: Wed Jun 5 18:44:04 2024 +0800

    add broadcast1 (#10)
---
 .../case-versions.conf                             |  25 ++
 .../nocase-configuration.yml                       |  68 ++++++
 .../samples-spi-cluster-broadcast1/pom.xml         | 156 +++++++++++++
 .../samples/spi/broadcast1/Broadcast1Consumer.java |  39 ++++
 .../samples/spi/broadcast1/Broadcast1Provider.java |  37 +++
 .../samples/spi/broadcast1/EmbeddedZooKeeper.java  | 251 +++++++++++++++++++++
 .../samples/spi/broadcast1/api/DemoService.java    |  28 +++
 .../spi/broadcast1/impl/DemoServiceImpl.java       |  44 ++++
 .../src/main/resources/log4j2.xml                  |  29 +++
 .../main/resources/spring/broadcast1-consumer.xml  |  32 +++
 .../main/resources/spring/broadcast1-provider.xml  |  38 ++++
 .../src/test/java/Broadcast1ConsumerIT.java        |  52 +++++
 pom.xml                                            |   1 +
 13 files changed, 800 insertions(+)

diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/case-versions.conf 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/case-versions.conf
new file mode 100644
index 0000000..f7373a5
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/case-versions.conf
@@ -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.
+#
+
+
+# Supported component versions of the test case
+
+# Spring app
+dubbo.version=2.7*, 3.*
+spring.version=4.*, 5.*
+java.version= [>= 8]
diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/nocase-configuration.yml
 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/nocase-configuration.yml
new file mode 100644
index 0000000..4f97fff
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/nocase-configuration.yml
@@ -0,0 +1,68 @@
+# 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.
+
+services:
+  zookeeper:
+    image: zookeeper:latest
+
+  samples-spi-cluster-broadcast1-provider1:
+    type: app
+    basedir: .
+    mainClass: org.apache.dubbo.samples.broadcast.BroadcastProvider
+    systemProps:
+      - zookeeper.address=zookeeper
+      - zookeeper.port=2181
+      - dubbo.port=20880
+    waitPortsBeforeRun:
+      - zookeeper:2181
+    checkPorts:
+      - 20880
+    checkLog: "dubbo service started"
+    depends_on:
+      - zookeeper
+
+  samples-spi-cluster-broadcast1-provider2:
+    type: app
+    basedir: .
+    mainClass: org.apache.dubbo.samples.broadcast.BroadcastProvider
+    systemProps:
+      - zookeeper.address=zookeeper
+      - zookeeper.port=2181
+      - dubbo.port=20881
+    waitPortsBeforeRun:
+      - zookeeper:2181
+    checkPorts:
+      - 20881
+    checkLog: "dubbo service started"
+    depends_on:
+      - zookeeper
+
+  dubbo-smples-broadcast-test:
+    type: test
+    basedir: .
+    tests:
+      - "**/*IT.class"
+    systemProps:
+      - zookeeper.address=zookeeper
+      - zookeeper.port=2181
+    waitPortsBeforeRun:
+      - zookeeper:2181
+      - samples-spi-cluster-broadcast1-provider1:20880
+      - samples-spi-cluster-broadcast1-provider2:20881
+    depends_on:
+      - zookeeper
+      - samples-spi-cluster-broadcast1-provider1
+      - samples-spi-cluster-broadcast1-provider2
diff --git a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/pom.xml 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/pom.xml
new file mode 100644
index 0000000..2e6e529
--- /dev/null
+++ b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/pom.xml
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.dubbo</groupId>
+        <artifactId>dubbo-samples-spi</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>samples-spi-cluster-broadcast1</artifactId>
+
+    <properties>
+        <zookeeper.version>3.8.4</zookeeper.version>
+        <metrics.version>4.1.12.1</metrics.version>
+        <snappy.version>1.1.10.5</snappy.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework</groupId>
+                <artifactId>spring-framework-bom</artifactId>
+                <version>${spring.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-bom</artifactId>
+                <version>${dubbo.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.dubbo.extensions</groupId>
+                <artifactId>dubbo-extensions-bom</artifactId>
+                <version>${spi.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
+                <version>${dubbo.version}</version>
+                <type>pom</type>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.zookeeper</groupId>
+                <artifactId>zookeeper</artifactId>
+                <version>${zookeeper.version}</version>
+                <exclusions>
+                    <exclusion>
+                        <artifactId>logback-core</artifactId>
+                        <groupId>ch.qos.logback</groupId>
+                    </exclusion>
+                    <exclusion>
+                        <artifactId>logback-classic</artifactId>
+                        <groupId>ch.qos.logback</groupId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo</artifactId>
+            <version>${dubbo.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context-support</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo.extensions</groupId>
+            <artifactId>dubbo-cluster-broadcast-1</artifactId>
+            <version>${spi.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-dependencies-zookeeper</artifactId>
+            <type>pom</type>
+        </dependency>
+
+        <dependency>
+            <groupId>io.dropwizard.metrics</groupId>
+            <artifactId>metrics-core</artifactId>
+            <version>${metrics.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.xerial.snappy</groupId>
+            <artifactId>snappy-java</artifactId>
+            <version>${snappy.version}</version>
+        </dependency>
+    </dependencies>
+
+    <profiles>
+        <!-- For jdk 11 above JavaEE annotation -->
+        <profile>
+            <id>javax.annotation</id>
+            <activation>
+                <jdk>[1.11,)</jdk>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>javax.annotation</groupId>
+                    <artifactId>javax.annotation-api</artifactId>
+                    <version>${javax.annotation-api.version}</version>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${maven-compiler-plugin.version}</version>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/Broadcast1Consumer.java
 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/Broadcast1Consumer.java
new file mode 100644
index 0000000..a96160d
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/Broadcast1Consumer.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.samples.spi.broadcast1;
+
+import org.apache.dubbo.samples.spi.broadcast1.api.DemoService;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class Broadcast1Consumer {
+
+    public static void main(String[] args) throws Exception {
+        ClassPathXmlApplicationContext context = new 
ClassPathXmlApplicationContext("spring/broadcast1-consumer.xml");
+        context.start();
+
+        DemoService demoService = (DemoService) context.getBean("demoService");
+        for (int i = 0; i < 10000; i++) {
+            String hello = demoService.sayHello("world");
+            System.out.println(hello);
+            Thread.sleep(2000);
+        }
+    }
+}
diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/Broadcast1Provider.java
 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/Broadcast1Provider.java
new file mode 100644
index 0000000..20a9581
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/Broadcast1Provider.java
@@ -0,0 +1,37 @@
+/*
+ *
+ *   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.spi.broadcast1;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+public class Broadcast1Provider {
+
+    public static void main(String[] args) throws Exception {
+//        new EmbeddedZooKeeper().start();
+        ClassPathXmlApplicationContext context = new 
ClassPathXmlApplicationContext("spring/broadcast1-provider.xml");
+        context.start();
+
+        System.out.println("dubbo service started");
+        new CountDownLatch(1).await();
+    }
+
+}
diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/EmbeddedZooKeeper.java
 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/EmbeddedZooKeeper.java
new file mode 100644
index 0000000..3cdfcc8
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/EmbeddedZooKeeper.java
@@ -0,0 +1,251 @@
+/*
+ * 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.spi.broadcast1;
+
+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);
+                }
+            }
+        }
+    }
+
+}
diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/api/DemoService.java
 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/api/DemoService.java
new file mode 100644
index 0000000..c4976b6
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/api/DemoService.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.samples.spi.broadcast1.api;
+
+public interface DemoService {
+
+    String sayHello(String name);
+
+    boolean isInvoke();
+
+}
diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/impl/DemoServiceImpl.java
 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/impl/DemoServiceImpl.java
new file mode 100644
index 0000000..247a66a
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/java/org/apache/dubbo/samples/spi/broadcast1/impl/DemoServiceImpl.java
@@ -0,0 +1,44 @@
+/*
+ *
+ *   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.spi.broadcast1.impl;
+
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.samples.spi.broadcast1.api.DemoService;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class DemoServiceImpl implements DemoService {
+
+    boolean isInvoke;
+    @Override
+    public String sayHello(String name) {
+        isInvoke = true;
+        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();
+    }
+
+    @Override
+    public boolean isInvoke() {
+        return isInvoke;
+    }
+
+}
diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/resources/log4j2.xml
 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..69e1321
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/resources/log4j2.xml
@@ -0,0 +1,29 @@
+<?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.
+  -->
+<Configuration status="WARN">
+    <Appenders>
+        <Console name="Console" target="SYSTEM_OUT" follow="true">
+            <PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} 
%style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} 
%style{-|}{White} 
%m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}" 
disableAnsi="false" charset="UTF-8"/>
+        </Console>
+    </Appenders>
+    <Loggers>
+        <Root level="info">
+            <AppenderRef ref="Console"/>
+        </Root>
+    </Loggers>
+</Configuration>
diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/resources/spring/broadcast1-consumer.xml
 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/resources/spring/broadcast1-consumer.xml
new file mode 100644
index 0000000..c63400a
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/resources/spring/broadcast1-consumer.xml
@@ -0,0 +1,32 @@
+<?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"; 
xmlns:context="http://www.springframework.org/schema/context";
+       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 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd";>
+    <context:property-placeholder/>
+
+    <dubbo:application name="broadcast-consumer"/>
+
+    <dubbo:registry 
address="zookeeper://${zookeeper.address:127.0.0.1}:${zookeeper.port:2181}"/>
+
+    <dubbo:reference id="demoService" 
interface="org.apache.dubbo.samples.spi.broadcast1.api.DemoService" 
cluster="broadcast1"/>
+
+</beans>
diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/resources/spring/broadcast1-provider.xml
 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/resources/spring/broadcast1-provider.xml
new file mode 100644
index 0000000..227d288
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/main/resources/spring/broadcast1-provider.xml
@@ -0,0 +1,38 @@
+<?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"; 
xmlns:context="http://www.springframework.org/schema/context";
+       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 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd";>
+    <context:property-placeholder/>
+
+    <dubbo:application name="broadcast-provider"/>
+
+    <dubbo:registry 
address="zookeeper://${zookeeper.address:127.0.0.1}:${zookeeper.port:2181}"/>
+
+
+    <dubbo:protocol name="dubbo" port="${dubbo.port:20881}"/>
+
+    <bean id="demoService" 
class="org.apache.dubbo.samples.spi.broadcast1.impl.DemoServiceImpl"/>
+
+    <dubbo:service 
interface="org.apache.dubbo.samples.spi.broadcast1.api.DemoService"
+                   ref="demoService"/>
+
+</beans>
diff --git 
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/test/java/Broadcast1ConsumerIT.java
 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/test/java/Broadcast1ConsumerIT.java
new file mode 100644
index 0000000..ccd2981
--- /dev/null
+++ 
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1/src/test/java/Broadcast1ConsumerIT.java
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+import org.apache.dubbo.samples.spi.broadcast1.api.DemoService;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * Consumer test side
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = "classpath*:spring/broadcast1-consumer.xml")
+public class Broadcast1ConsumerIT {
+
+    @Autowired
+    @Qualifier("demoService")
+    private DemoService demoService;
+
+//    fixme error when invoke
+    @Test
+    public void testSayHello() {
+        Assert.assertTrue(demoService.sayHello("world").contains("Hello"));
+    }
+
+    @Test
+    public void testBroadcast() {
+        Assert.assertTrue(demoService.sayHello("world").contains("Hello"));
+        Assert.assertTrue(demoService.isInvoke());
+    }
+
+
+
+}
diff --git a/pom.xml b/pom.xml
index c294b56..b137b88 100755
--- a/pom.xml
+++ b/pom.xml
@@ -43,6 +43,7 @@
 
     <modules>
         <module>tools</module>
+        
<module>6-dubbo-spi-cluster-samples/samples-spi-cluster-broadcast1</module>
         
<module>9-dubbo-spi-serialize-samples/samples-spi-serialization</module>
         <module>4-dubbo-spi-config-samples/samples-spi-configcenter</module>
         <module>2-dubbo-spi-protocol-samples/samples-spi-protocol</module>


Reply via email to