You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by li...@apache.org on 2024/03/28 13:56:51 UTC
(dubbo-samples) branch master updated: add multiple protocol example (#1117)
This is an automated email from the ASF dual-hosted git repository.
liujun 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 bfabeb173 add multiple protocol example (#1117)
bfabeb173 is described below
commit bfabeb173a6b3912ebda73e3f6cef75270c7f953
Author: Ken Liu <ke...@gmail.com>
AuthorDate: Thu Mar 28 21:56:45 2024 +0800
add multiple protocol example (#1117)
---
.../dubbo-samples-spring-boot-provider/pom.xml | 4 -
.../dubbo-samples-multiple-protocols/README.md | 62 ++++++++++++
.../pom.xml | 37 ++-----
.../demo/consumer/DubboConsumerApplication.java | 31 ++++++
.../protocol/multiple/demo/consumer/Task.java | 49 +++++++++
.../src/main/resources/application.yml | 22 +++++
.../pom.xml | 29 ++++++
.../dubbo/protocol/multiple/demo/DemoService.java | 22 +++++
.../pom.xml | 31 +-----
.../multiple/demo/provider/DemoServiceImpl.java | 30 ++++++
.../demo/provider/ProviderApplication.java | 31 ++++++
.../src/main/resources/application.yml | 26 +++++
.../pom.xml | 37 ++-----
.../protocol/multiple/demo/consumer/Task.java | 48 +++++++++
.../demo/consumer/TripleConsumerApplication.java | 31 ++++++
.../src/main/resources/application.yml | 22 +++++
.../dubbo-samples-multiple-protocols/pom.xml | 110 +++++++++++++++++++++
2-advanced/pom.xml | 1 +
18 files changed, 535 insertions(+), 88 deletions(-)
diff --git a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml b/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml
index 62795ea74..0633cc76f 100644
--- a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml
+++ b/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml
@@ -57,10 +57,6 @@
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-nacos-spring-boot-starter</artifactId>
- </dependency>
<!-- spring starter -->
<dependency>
diff --git a/2-advanced/dubbo-samples-multiple-protocols/README.md b/2-advanced/dubbo-samples-multiple-protocols/README.md
new file mode 100644
index 000000000..8e6ae7ed9
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/README.md
@@ -0,0 +1,62 @@
+# Dubbo Multiple Protocol Example
+
+This example shows how the `multiple protocols on one port` works in Dubbo. We will
+1. Start one provider which supports `dubbo` and `tri` protocol at the same time on one port.
+2. Start two consumers that consumes `dubbo` and `tri` protocol respectively.
+
+# How to run
+
+## Start Nacos
+This example replies on Nacos as service discovery registry center, so you need to run the Nacos server first, there are two ways to do so:
+1. [Download Nacos binary and start it directly](https://dubbo-next.staged.apache.org/zh-cn/overview/reference/integrations/nacos/#本地下载)
+2. [Start Nacos using docker](https://dubbo-next.staged.apache.org/zh-cn/overview/reference/integrations/nacos/#docker)
+
+## Install dependencies
+Enter 'dubbo-samples-multiple-protocols' directory, run the following command:
+
+```shell
+$ mvn clean install
+```
+
+## Start provider
+Enter provider directory:
+
+```shell
+$ cd dubbo-samples-multiple-protocols-provider
+```
+
+then, run the following command to start provider:
+```shell
+$ mvn compile exec:java -Dexec.mainClass="org.apache.dubbo.protocol.multiple.demo.provider.ProviderApplication"
+```
+
+Run the following command to see server works as expected:
+```shell
+curl \
+ --header "Content-Type: application/json" \
+ --data '["Dubbo"]' \
+ http://localhost:20880/org.apache.dubbo.protocol.multiple.demo.DemoService/sayHello
+```
+
+## Start `dubbo` consumer
+Enter `dubbo` consumer directory:
+```shell
+$ cd dubbo-samples-multiple-protocols-dubbo-consumer
+```
+
+then, run the following command to start consumer:
+```shell
+$ mvn compile exec:java -Dexec.mainClass="org.apache.dubbo.protocol.multiple.demo.consumer.DubboConsumerApplication"
+```
+
+## Start `triple` consumer
+Enter `triple` consumer directory:
+```shell
+$ cd dubbo-samples-multiple-protocols-triple-consumer
+```
+
+then, run the following command to start consumer:
+```shell
+$ mvn compile exec:java -Dexec.mainClass="org.apache.dubbo.protocol.multiple.demo.consumer.TripleConsumerApplication"
+```
+
diff --git a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/pom.xml
similarity index 66%
copy from 1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml
copy to 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/pom.xml
index 62795ea74..2c2919477 100644
--- a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/pom.xml
@@ -18,19 +18,18 @@
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-spring-boot</artifactId>
+ <artifactId>dubbo-samples-multiple-protocols</artifactId>
<groupId>org.apache.dubbo</groupId>
<version>1.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>dubbo-samples-spring-boot-provider</artifactId>
+ <artifactId>dubbo-samples-multiple-protocols-dubbo-consumer</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-samples-spring-boot-interface</artifactId>
+ <artifactId>dubbo-samples-multiple-protocols-interface</artifactId>
<version>${project.parent.version}</version>
</dependency>
@@ -39,24 +38,6 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-zookeeper-curator5-spring-boot-starter</artifactId>
- <exclusions>
- <exclusion>
- <groupId>io.netty</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- <exclusion>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- </exclusion>
- <exclusion>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-nacos-spring-boot-starter</artifactId>
@@ -66,18 +47,18 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-logging</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/DubboConsumerApplication.java b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/DubboConsumerApplication.java
new file mode 100644
index 000000000..fff79da16
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/DubboConsumerApplication.java
@@ -0,0 +1,31 @@
+/*
+ * 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.protocol.multiple.demo.consumer;
+
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@EnableDubbo
+public class DubboConsumerApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(DubboConsumerApplication.class, args);
+ }
+}
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/Task.java b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/Task.java
new file mode 100644
index 000000000..7a9047248
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/Task.java
@@ -0,0 +1,49 @@
+/*
+ * 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.protocol.multiple.demo.consumer;
+
+import java.util.Date;
+
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.dubbo.protocol.multiple.demo.DemoService;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+@Component
+public class Task implements CommandLineRunner {
+ // in this case, if not set, default protocol is also dubbo; depending on the primary protocol configuration on provider side, it can be tri.
+ @DubboReference(protocol="dubbo")
+ private DemoService demoService;
+
+ @Override
+ public void run(String... args) throws Exception {
+ String result = demoService.sayHello("world");
+ System.out.println("Receive result ======> " + result);
+
+ new Thread(()-> {
+ while (true) {
+ try {
+ Thread.sleep(1000);
+ System.out.println(new Date() + " Receive result ======> " + demoService.sayHello("world"));
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ Thread.currentThread().interrupt();
+ }
+ }
+ }).start();
+ }
+}
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/resources/application.yml
new file mode 100644
index 000000000..c299ea618
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/resources/application.yml
@@ -0,0 +1,22 @@
+# 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.
+
+dubbo:
+ application:
+ name: dubbo-protocol-consumer
+ qos-enable: false
+ registry:
+ address: nacos://${nacos.address:localhost}:8848?username=nacos&password=nacos
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-interface/pom.xml b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-interface/pom.xml
new file mode 100644
index 000000000..4e43ca877
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-interface/pom.xml
@@ -0,0 +1,29 @@
+<!--
+ 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-multiple-protocols</artifactId>
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-samples-multiple-protocols-interface</artifactId>
+
+</project>
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-interface/src/main/java/org/apache/dubbo/protocol/multiple/demo/DemoService.java b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-interface/src/main/java/org/apache/dubbo/protocol/multiple/demo/DemoService.java
new file mode 100644
index 000000000..8ae38139f
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-interface/src/main/java/org/apache/dubbo/protocol/multiple/demo/DemoService.java
@@ -0,0 +1,22 @@
+/*
+ * 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.protocol.multiple.demo;
+
+public interface DemoService {
+
+ String sayHello(String name);
+}
diff --git a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/pom.xml
similarity index 65%
copy from 1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml
copy to 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/pom.xml
index 62795ea74..9a6e5a9d0 100644
--- a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/pom.xml
@@ -18,19 +18,18 @@
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-spring-boot</artifactId>
+ <artifactId>dubbo-samples-multiple-protocols</artifactId>
<groupId>org.apache.dubbo</groupId>
<version>1.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>dubbo-samples-spring-boot-provider</artifactId>
+ <artifactId>dubbo-samples-multiple-protocols-provider</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-samples-spring-boot-interface</artifactId>
+ <artifactId>dubbo-samples-multiple-protocols-interface</artifactId>
<version>${project.parent.version}</version>
</dependency>
@@ -39,24 +38,6 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-zookeeper-curator5-spring-boot-starter</artifactId>
- <exclusions>
- <exclusion>
- <groupId>io.netty</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- <exclusion>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- </exclusion>
- <exclusion>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-nacos-spring-boot-starter</artifactId>
@@ -66,12 +47,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-logging</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/java/org/apache/dubbo/protocol/multiple/demo/provider/DemoServiceImpl.java b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/java/org/apache/dubbo/protocol/multiple/demo/provider/DemoServiceImpl.java
new file mode 100644
index 000000000..3596c0725
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/java/org/apache/dubbo/protocol/multiple/demo/provider/DemoServiceImpl.java
@@ -0,0 +1,30 @@
+/*
+ * 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.protocol.multiple.demo.provider;
+
+
+import org.apache.dubbo.config.annotation.DubboService;
+import org.apache.dubbo.protocol.multiple.demo.DemoService;
+
+@DubboService
+public class DemoServiceImpl implements DemoService {
+
+ @Override
+ public String sayHello(String name) {
+ return "Hello " + name;
+ }
+}
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/java/org/apache/dubbo/protocol/multiple/demo/provider/ProviderApplication.java b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/java/org/apache/dubbo/protocol/multiple/demo/provider/ProviderApplication.java
new file mode 100644
index 000000000..beafe2521
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/java/org/apache/dubbo/protocol/multiple/demo/provider/ProviderApplication.java
@@ -0,0 +1,31 @@
+/*
+ * 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.protocol.multiple.demo.provider;
+
+
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@EnableDubbo
+public class ProviderApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(ProviderApplication.class, args);
+ }
+}
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/resources/application.yml
new file mode 100644
index 000000000..428984f03
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/resources/application.yml
@@ -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.
+
+dubbo:
+ application:
+ name: dubbo-protocol-provider
+ qos-enable: false
+ protocol:
+ name: dubbo
+ port: 20880
+ ext-protocol: tri
+ registry:
+ address: nacos://${nacos.address:localhost}:8848?username=nacos&password=nacos
diff --git a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/pom.xml
similarity index 66%
copy from 1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml
copy to 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/pom.xml
index 62795ea74..e5b7509ed 100644
--- a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/pom.xml
@@ -18,19 +18,18 @@
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-spring-boot</artifactId>
+ <artifactId>dubbo-samples-multiple-protocols</artifactId>
<groupId>org.apache.dubbo</groupId>
<version>1.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>dubbo-samples-spring-boot-provider</artifactId>
+ <artifactId>dubbo-samples-multiple-protocols-triple-consumer</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-samples-spring-boot-interface</artifactId>
+ <artifactId>dubbo-samples-multiple-protocols-interface</artifactId>
<version>${project.parent.version}</version>
</dependency>
@@ -39,24 +38,6 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-zookeeper-curator5-spring-boot-starter</artifactId>
- <exclusions>
- <exclusion>
- <groupId>io.netty</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- <exclusion>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- </exclusion>
- <exclusion>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-nacos-spring-boot-starter</artifactId>
@@ -66,18 +47,18 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-logging</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/Task.java b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/Task.java
new file mode 100644
index 000000000..e7faf6222
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/Task.java
@@ -0,0 +1,48 @@
+/*
+ * 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.protocol.multiple.demo.consumer;
+
+import java.util.Date;
+
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.dubbo.protocol.multiple.demo.DemoService;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+@Component
+public class Task implements CommandLineRunner {
+ @DubboReference(protocol="tri")
+ private DemoService demoService;
+
+ @Override
+ public void run(String... args) throws Exception {
+ String result = demoService.sayHello("world");
+ System.out.println("Receive result ======> " + result);
+
+ new Thread(()-> {
+ while (true) {
+ try {
+ Thread.sleep(1000);
+ System.out.println(new Date() + " Receive result ======> " + demoService.sayHello("world"));
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ Thread.currentThread().interrupt();
+ }
+ }
+ }).start();
+ }
+}
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/TripleConsumerApplication.java b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/TripleConsumerApplication.java
new file mode 100644
index 000000000..37cbb875c
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/TripleConsumerApplication.java
@@ -0,0 +1,31 @@
+/*
+ * 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.protocol.multiple.demo.consumer;
+
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@EnableDubbo
+public class TripleConsumerApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(TripleConsumerApplication.class, args);
+ }
+}
diff --git a/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/resources/application.yml
new file mode 100644
index 000000000..c299ea618
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/resources/application.yml
@@ -0,0 +1,22 @@
+# 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.
+
+dubbo:
+ application:
+ name: dubbo-protocol-consumer
+ qos-enable: false
+ registry:
+ address: nacos://${nacos.address:localhost}:8848?username=nacos&password=nacos
diff --git a/2-advanced/dubbo-samples-multiple-protocols/pom.xml b/2-advanced/dubbo-samples-multiple-protocols/pom.xml
new file mode 100644
index 000000000..d27dc6275
--- /dev/null
+++ b/2-advanced/dubbo-samples-multiple-protocols/pom.xml
@@ -0,0 +1,110 @@
+<?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>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>23</version>
+ <relativePath/>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-samples-multiple-protocols</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>Dubbo Samples Multiple Protocols</name>
+ <description>Dubbo Samples Multiple Protocols</description>
+
+ <properties>
+ <maven.compiler.source>17</maven.compiler.source>
+ <maven.compiler.target>17</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <dubbo.version>3.3.0-beta.2</dubbo.version>
+ <spring-boot.version>3.2.3</spring-boot.version>
+ </properties>
+
+ <modules>
+ <module>dubbo-samples-multiple-protocols-interface</module>
+ <module>dubbo-samples-multiple-protocols-provider</module>
+ <module>dubbo-samples-multiple-protocols-dubbo-consumer</module>
+ <module>dubbo-samples-multiple-protocols-triple-consumer</module>
+ </modules>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring-boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ <version>${spring-boot.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>spring-boot-starter-logging</artifactId>
+ <groupId>org.springframework.boot</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-bom</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/2-advanced/pom.xml b/2-advanced/pom.xml
index cdd0c993a..0439c77df 100644
--- a/2-advanced/pom.xml
+++ b/2-advanced/pom.xml
@@ -67,5 +67,6 @@
<module>dubbo-samples-api-with-registry</module>
<module>dubbo-samples-dubbo</module>
<module>dubbo-samples-triple-rest</module>
+ <module>dubbo-samples-multiple-protocols</module>
</modules>
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org