From 89f0a23f1beca354ece18f5d8ed95f7e2d7f88a4 Mon Sep 17 00:00:00 2001 From: chickenlj Date: Thu, 28 Mar 2024 21:45:26 +0800 Subject: [PATCH] add multiple protocol example --- .../pom.xml | 4 - .../README.md | 62 ++++++++++ .../pom.xml | 72 ++++++++++++ .../consumer/DubboConsumerApplication.java | 31 +++++ .../protocol/multiple/demo/consumer/Task.java | 49 ++++++++ .../src/main/resources/application.yml | 22 ++++ .../pom.xml | 29 +++++ .../protocol/multiple/demo/DemoService.java | 22 ++++ .../pom.xml | 66 +++++++++++ .../demo/provider/DemoServiceImpl.java | 30 +++++ .../demo/provider/ProviderApplication.java | 31 +++++ .../src/main/resources/application.yml | 26 +++++ .../pom.xml | 72 ++++++++++++ .../protocol/multiple/demo/consumer/Task.java | 48 ++++++++ .../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, 724 insertions(+), 4 deletions(-) create mode 100644 2-advanced/dubbo-samples-multiple-protocols/README.md create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/pom.xml create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/DubboConsumerApplication.java create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/Task.java create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/src/main/resources/application.yml create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-interface/pom.xml create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-interface/src/main/java/org/apache/dubbo/protocol/multiple/demo/DemoService.java create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/pom.xml create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/java/org/apache/dubbo/protocol/multiple/demo/provider/DemoServiceImpl.java create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/java/org/apache/dubbo/protocol/multiple/demo/provider/ProviderApplication.java create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/src/main/resources/application.yml create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/pom.xml create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/Task.java create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/java/org/apache/dubbo/protocol/multiple/demo/consumer/TripleConsumerApplication.java create mode 100644 2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/src/main/resources/application.yml create mode 100644 2-advanced/dubbo-samples-multiple-protocols/pom.xml 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 @@ - - org.apache.dubbo - dubbo-nacos-spring-boot-starter - 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/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/pom.xml b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/pom.xml new file mode 100644 index 000000000..2c2919477 --- /dev/null +++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-dubbo-consumer/pom.xml @@ -0,0 +1,72 @@ + + + + dubbo-samples-multiple-protocols + org.apache.dubbo + 1.0-SNAPSHOT + + 4.0.0 + + dubbo-samples-multiple-protocols-dubbo-consumer + + + + org.apache.dubbo + dubbo-samples-multiple-protocols-interface + ${project.parent.version} + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + org.apache.dubbo + dubbo-nacos-spring-boot-starter + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + 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 @@ + + + + dubbo-samples-multiple-protocols + org.apache.dubbo + 1.0-SNAPSHOT + + 4.0.0 + + dubbo-samples-multiple-protocols-interface + + 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/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/pom.xml b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/pom.xml new file mode 100644 index 000000000..9a6e5a9d0 --- /dev/null +++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-provider/pom.xml @@ -0,0 +1,66 @@ + + + + dubbo-samples-multiple-protocols + org.apache.dubbo + 1.0-SNAPSHOT + + 4.0.0 + + dubbo-samples-multiple-protocols-provider + + + + org.apache.dubbo + dubbo-samples-multiple-protocols-interface + ${project.parent.version} + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + org.apache.dubbo + dubbo-nacos-spring-boot-starter + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + 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/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/pom.xml b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/pom.xml new file mode 100644 index 000000000..e5b7509ed --- /dev/null +++ b/2-advanced/dubbo-samples-multiple-protocols/dubbo-samples-multiple-protocols-triple-consumer/pom.xml @@ -0,0 +1,72 @@ + + + + dubbo-samples-multiple-protocols + org.apache.dubbo + 1.0-SNAPSHOT + + 4.0.0 + + dubbo-samples-multiple-protocols-triple-consumer + + + + org.apache.dubbo + dubbo-samples-multiple-protocols-interface + ${project.parent.version} + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + org.apache.dubbo + dubbo-nacos-spring-boot-starter + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + 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 @@ + + + + + + org.apache + apache + 23 + + + 4.0.0 + + org.apache.dubbo + dubbo-samples-multiple-protocols + 1.0-SNAPSHOT + pom + + Dubbo Samples Multiple Protocols + Dubbo Samples Multiple Protocols + + + 17 + 17 + UTF-8 + + 3.3.0-beta.2 + 3.2.3 + + + + dubbo-samples-multiple-protocols-interface + dubbo-samples-multiple-protocols-provider + dubbo-samples-multiple-protocols-dubbo-consumer + dubbo-samples-multiple-protocols-triple-consumer + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + org.springframework.boot + spring-boot-starter + ${spring-boot.version} + + + spring-boot-starter-logging + org.springframework.boot + + + + + org.apache.dubbo + dubbo-bom + ${dubbo.version} + pom + import + + + + + + + junit + junit + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + + 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 @@ dubbo-samples-api-with-registry dubbo-samples-dubbo dubbo-samples-triple-rest + dubbo-samples-multiple-protocols