This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git
The following commit(s) were added to refs/heads/master by this push:
new 864569582 Add broadcast test (#1157)
864569582 is described below
commit 864569582fa6eef887c02254f5ecaf41cd924951
Author: 王聪洋 <[email protected]>
AuthorDate: Thu Nov 7 17:04:49 2024 +0800
Add broadcast test (#1157)
---
.../dubbo-samples-broadcast/case-configuration.yml | 69 +++++++++++++
.../dubbo-samples-broadcast/case-versions.conf | 25 +++++
2-advanced/dubbo-samples-broadcast/pom.xml | 113 +++++++++++++++++++++
.../dubbo/samples/broadcast/BroadcastConsumer.java | 39 +++++++
.../dubbo/samples/broadcast/BroadcastProvider.java | 36 +++++++
.../samples/broadcast/BroadcastProvider2.java | 36 +++++++
.../dubbo/samples/broadcast/api/DemoService.java | 28 +++++
.../samples/broadcast/impl/DemoServiceImpl.java | 45 ++++++++
.../src/main/resources/log4j.properties | 25 +++++
.../main/resources/spring/broadcast-consumer.xml | 32 ++++++
.../main/resources/spring/broadcast-provider.xml | 39 +++++++
.../main/resources/spring/broadcast-provider2.xml | 39 +++++++
.../src/test/java/BroadcastConsumerIT.java | 87 ++++++++++++++++
2-advanced/pom.xml | 1 +
14 files changed, 614 insertions(+)
diff --git a/2-advanced/dubbo-samples-broadcast/case-configuration.yml
b/2-advanced/dubbo-samples-broadcast/case-configuration.yml
new file mode 100644
index 000000000..be15607cb
--- /dev/null
+++ b/2-advanced/dubbo-samples-broadcast/case-configuration.yml
@@ -0,0 +1,69 @@
+# 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
+
+ dubbo-samples-broadcast-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
+
+ dubbo-samples-broadcast-provider2:
+ type: app
+ basedir: .
+ mainClass: org.apache.dubbo.samples.broadcast.BroadcastProvider2
+ systemProps:
+ - zookeeper.address=zookeeper
+ - zookeeper.port=2181
+ - dubbo.port=20881
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ checkPorts:
+ - 20881
+ checkLog: "dubbo service started"
+ depends_on:
+ - zookeeper
+
+ dubbo-samples-broadcast-test:
+ type: test
+ basedir: .
+ tests:
+ - "**/*IT.class"
+ systemProps:
+ - zookeeper.address=zookeeper
+ - zookeeper.port=2181
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ - dubbo-samples-broadcast-provider1:20880
+ - dubbo-samples-broadcast-provider2:20881
+ depends_on:
+ - zookeeper
+ - dubbo-samples-broadcast-provider1
+ - dubbo-samples-broadcast-provider2
+
diff --git a/2-advanced/dubbo-samples-broadcast/case-versions.conf
b/2-advanced/dubbo-samples-broadcast/case-versions.conf
new file mode 100644
index 000000000..f7373a530
--- /dev/null
+++ b/2-advanced/dubbo-samples-broadcast/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/2-advanced/dubbo-samples-broadcast/pom.xml
b/2-advanced/dubbo-samples-broadcast/pom.xml
new file mode 100644
index 000000000..2ccd6431d
--- /dev/null
+++ b/2-advanced/dubbo-samples-broadcast/pom.xml
@@ -0,0 +1,113 @@
+<?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>
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+
+ <artifactId>dubbo-samples-broadcast</artifactId>
+
+ <properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <dubbo.version>3.2.6</dubbo.version>
+ <spring.version>4.3.30.RELEASE</spring.version>
+ <log4j2.version>2.20.0</log4j2.version>
+ <junit.version>4.13.1</junit.version>
+
+ <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+ </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</groupId>
+ <artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <version>${log4j2.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </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>1.3.2</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/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/BroadcastConsumer.java
b/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/BroadcastConsumer.java
new file mode 100644
index 000000000..03eb72cfe
--- /dev/null
+++
b/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/BroadcastConsumer.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.broadcast;
+
+import org.apache.dubbo.samples.broadcast.api.DemoService;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class BroadcastConsumer {
+
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext("spring/broadcast-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/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/BroadcastProvider.java
b/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/BroadcastProvider.java
new file mode 100644
index 000000000..2e0987413
--- /dev/null
+++
b/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/BroadcastProvider.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.broadcast;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+public class BroadcastProvider {
+
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext("spring/broadcast-provider.xml");
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
+ }
+
+}
diff --git
a/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/BroadcastProvider2.java
b/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/BroadcastProvider2.java
new file mode 100644
index 000000000..66ff9a6f4
--- /dev/null
+++
b/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/BroadcastProvider2.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.broadcast;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+public class BroadcastProvider2 {
+
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext("spring/broadcast-provider2.xml");
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
+ }
+
+}
diff --git
a/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/api/DemoService.java
b/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/api/DemoService.java
new file mode 100644
index 000000000..24bbae08a
--- /dev/null
+++
b/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/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.broadcast.api;
+
+public interface DemoService {
+
+ String sayHello(String name);
+
+ boolean isInvoke();
+
+}
diff --git
a/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/impl/DemoServiceImpl.java
b/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/impl/DemoServiceImpl.java
new file mode 100644
index 000000000..5f333424a
--- /dev/null
+++
b/2-advanced/dubbo-samples-broadcast/src/main/java/org/apache/dubbo/samples/broadcast/impl/DemoServiceImpl.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.broadcast.impl;
+
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.samples.broadcast.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() {
+ System.out.println("The value of isInvoke:" + isInvoke);
+ return isInvoke;
+ }
+
+}
diff --git
a/2-advanced/dubbo-samples-broadcast/src/main/resources/log4j.properties
b/2-advanced/dubbo-samples-broadcast/src/main/resources/log4j.properties
new file mode 100644
index 000000000..1f8fe1ece
--- /dev/null
+++ b/2-advanced/dubbo-samples-broadcast/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
diff --git
a/2-advanced/dubbo-samples-broadcast/src/main/resources/spring/broadcast-consumer.xml
b/2-advanced/dubbo-samples-broadcast/src/main/resources/spring/broadcast-consumer.xml
new file mode 100644
index 000000000..d600dd85e
--- /dev/null
+++
b/2-advanced/dubbo-samples-broadcast/src/main/resources/spring/broadcast-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.broadcast.api.DemoService"
cluster="broadcast" timeout="10000" version="*"/>
+
+</beans>
diff --git
a/2-advanced/dubbo-samples-broadcast/src/main/resources/spring/broadcast-provider.xml
b/2-advanced/dubbo-samples-broadcast/src/main/resources/spring/broadcast-provider.xml
new file mode 100644
index 000000000..d86d2c7f6
--- /dev/null
+++
b/2-advanced/dubbo-samples-broadcast/src/main/resources/spring/broadcast-provider.xml
@@ -0,0 +1,39 @@
+<?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:20880}"/>
+
+ <bean id="demoService"
class="org.apache.dubbo.samples.broadcast.impl.DemoServiceImpl"/>
+
+
+ <dubbo:service
interface="org.apache.dubbo.samples.broadcast.api.DemoService"
+ ref="demoService" version="1.1.1"/>
+
+</beans>
diff --git
a/2-advanced/dubbo-samples-broadcast/src/main/resources/spring/broadcast-provider2.xml
b/2-advanced/dubbo-samples-broadcast/src/main/resources/spring/broadcast-provider2.xml
new file mode 100644
index 000000000..7e71e6fed
--- /dev/null
+++
b/2-advanced/dubbo-samples-broadcast/src/main/resources/spring/broadcast-provider2.xml
@@ -0,0 +1,39 @@
+<?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.broadcast.impl.DemoServiceImpl"/>
+
+
+ <dubbo:service
interface="org.apache.dubbo.samples.broadcast.api.DemoService"
+ ref="demoService" version="1.1.2"/>
+
+</beans>
diff --git
a/2-advanced/dubbo-samples-broadcast/src/test/java/BroadcastConsumerIT.java
b/2-advanced/dubbo-samples-broadcast/src/test/java/BroadcastConsumerIT.java
new file mode 100644
index 000000000..fc2a4e22d
--- /dev/null
+++ b/2-advanced/dubbo-samples-broadcast/src/test/java/BroadcastConsumerIT.java
@@ -0,0 +1,87 @@
+/*
+ * 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.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
+import org.apache.dubbo.config.bootstrap.builders.ApplicationBuilder;
+import org.apache.dubbo.config.bootstrap.builders.ReferenceBuilder;
+import org.apache.dubbo.samples.broadcast.api.DemoService;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.net.UnknownHostException;
+
+/**
+ * Consumer test side
+ */
+public class BroadcastConsumerIT {
+
+ private static final String ZOOKEEPER_HOST =
System.getProperty("zookeeper.address", "127.0.0.1");
+ private static final String ZOOKEEPER_PORT =
System.getProperty("zookeeper.port", "2181");
+ private static final String ZOOKEEPER_ADDRESS = "zookeeper://" +
ZOOKEEPER_HOST + ":" + ZOOKEEPER_PORT;
+
+ private DemoService broadcastService;
+ private DemoService demoService;
+ private DemoService demoService2;
+
+ @Before
+ public void setup() throws UnknownHostException {
+
+ System.out.println("ZOOKEEPER_HOST = " + ZOOKEEPER_HOST);
+ System.out.println("ZOOKEEPER_ADDRESS = " + ZOOKEEPER_ADDRESS);
+
+ ReferenceConfig<DemoService> broadcastReference =
ReferenceBuilder.<DemoService>newBuilder()
+ .interfaceClass(DemoService.class)
+ .addRegistry(new RegistryConfig(ZOOKEEPER_ADDRESS))
+ .cluster("broadcast")
+ .version("*")
+ .build();
+ ReferenceConfig<DemoService> demoReference =
ReferenceBuilder.<DemoService>newBuilder()
+ .interfaceClass(DemoService.class)
+ .addRegistry(new RegistryConfig(ZOOKEEPER_ADDRESS))
+ .version("1.1.1")
+ .build();
+ ReferenceConfig<DemoService> demoReference2 =
ReferenceBuilder.<DemoService>newBuilder()
+ .interfaceClass(DemoService.class)
+ .addRegistry(new RegistryConfig(ZOOKEEPER_ADDRESS))
+ .version("1.1.2")
+ .build();
+
+ DubboBootstrap.getInstance()
+
.application(ApplicationBuilder.newBuilder().qosPort(22223).name("broadcast").build())
+ .reference(broadcastReference)
+ .reference(demoReference)
+ .reference(demoReference2)
+ .start();
+
+ broadcastService = broadcastReference.get(false);
+ demoService = demoReference.get(false);
+ demoService2 = demoReference2.get(false);
+ }
+
+ @Test
+ public void testSayHello() {
+
Assert.assertTrue(broadcastService.sayHello("world").contains("Hello"));
+ Assert.assertTrue(demoService.isInvoke());
+ Assert.assertTrue(demoService2.isInvoke());
+ }
+
+
+}
diff --git a/2-advanced/pom.xml b/2-advanced/pom.xml
index 4c8b356c2..6b7d53d9d 100644
--- a/2-advanced/pom.xml
+++ b/2-advanced/pom.xml
@@ -71,5 +71,6 @@
<module>dubbo-samples-triple-servlet</module>
<module>dubbo-samples-gateway</module>
<module>dubbo-samples-multiple-protocols</module>
+ <module>dubbo-samples-broadcast</module>
</modules>
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]