You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by gu...@apache.org on 2021/09/01 09:21:06 UTC

[dubbo] branch 3.0 updated: optimize: example add Triple protocol Demo (#8643)

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

guohao pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 2c5d60f  optimize: example add Triple protocol Demo (#8643)
2c5d60f is described below

commit 2c5d60f21455c674f7f70d473fb7e0c6c1b466fe
Author: FUNKYE <36...@qq.com>
AuthorDate: Wed Sep 1 17:20:27 2021 +0800

    optimize: example add Triple protocol Demo (#8643)
    
    * optimize: tri protocol prompt
    
    * optimize: example add Triple protocol Demo
    
    * optimize
    
    * optimize
    
    * bugfix
    
    * Revert to use applcation service discovery
    
    Co-authored-by: guohao <gu...@gmail.com>
---
 .../java/org/apache/dubbo/demo/TripleService.java  | 21 ++++++++++++++++
 .../dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml |  4 ++++
 .../apache/dubbo/demo/consumer/Application.java    | 17 +++++++++++++
 .../src/main/resources/spring/dubbo-consumer.xml   |  3 +++
 .../dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml |  4 ++++
 .../dubbo/demo/provider/TripleServiceImpl.java     | 28 ++++++++++++++++++++++
 .../src/main/resources/spring/dubbo-provider.xml   |  4 ++++
 7 files changed, 81 insertions(+)

diff --git a/dubbo-demo/dubbo-demo-interface/src/main/java/org/apache/dubbo/demo/TripleService.java b/dubbo-demo/dubbo-demo-interface/src/main/java/org/apache/dubbo/demo/TripleService.java
new file mode 100644
index 0000000..8aed07b
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-interface/src/main/java/org/apache/dubbo/demo/TripleService.java
@@ -0,0 +1,21 @@
+/*
+ * 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.demo;
+
+public interface TripleService {
+    String hello();
+}
diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml
index 917d108..663c76f 100644
--- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml
+++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml
@@ -87,5 +87,9 @@
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-serialization-jdk</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-rpc-triple</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java
index d13b6c1..01adf4a 100644
--- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java
+++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java
@@ -19,6 +19,7 @@ package org.apache.dubbo.demo.consumer;
 import org.apache.dubbo.demo.DemoService;
 import org.apache.dubbo.demo.GreetingService;
 import org.apache.dubbo.demo.RestDemoService;
+import org.apache.dubbo.demo.TripleService;
 
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
@@ -35,6 +36,7 @@ public class Application {
         DemoService demoService = context.getBean("demoService", DemoService.class);
         GreetingService greetingService = context.getBean("greetingService", GreetingService.class);
         RestDemoService restDemoService = context.getBean("restDemoService", RestDemoService.class);
+        TripleService tripleService = context.getBean("tripleService", TripleService.class);
 
         new Thread(() -> {
             while (true) {
@@ -66,6 +68,21 @@ public class Application {
             }
         }).start();
 
+        new Thread(() -> {
+            while (true) {
+                try {
+                    String restResult = tripleService.hello();
+                    System.out.println(restResult + " from separated thread.");
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                try {
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                }
+            }
+        }).start();
+
         while (true) {
             try {
                 CompletableFuture<String> hello = demoService.sayHelloAsync("world");
diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml
index cb90215..be27b4c 100644
--- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml
+++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml
@@ -37,4 +37,7 @@
     <dubbo:reference protocol="rest" version="1.0.0" id="restDemoService" check="false"
                      interface="org.apache.dubbo.demo.RestDemoService"/>
 
+    <dubbo:reference protocol="tri" version="1.0.0" id="tripleService" check="false"
+                     interface="org.apache.dubbo.demo.TripleService"/>
+
 </beans>
diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml
index 0b4544e..e252cf8 100644
--- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml
+++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml
@@ -107,5 +107,9 @@
             <groupId>log4j</groupId>
             <artifactId>log4j</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-rpc-triple</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/TripleServiceImpl.java b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/TripleServiceImpl.java
new file mode 100644
index 0000000..75c27f8
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/TripleServiceImpl.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.demo.provider;
+
+import org.apache.dubbo.demo.TripleService;
+
+public class TripleServiceImpl implements TripleService {
+
+    @Override
+    public String hello() {
+        return "Triple!";
+    }
+
+}
diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml
index d159627..64c81e1 100644
--- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml
+++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml
@@ -30,15 +30,19 @@
 
     <dubbo:protocol name="dubbo" port="-1"/>
     <dubbo:protocol name="rest" port="-1"/>
+    <dubbo:protocol name="tri" port="-1"/>
 
     <bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl"/>
     <bean id="greetingService" class="org.apache.dubbo.demo.provider.GreetingServiceImpl"/>
     <bean id="restDemoService" class="org.apache.dubbo.demo.provider.RestDemoServiceImpl"/>
+    <bean id="tripleService" class="org.apache.dubbo.demo.provider.TripleServiceImpl"/>
 
     <dubbo:service delay="5000" interface="org.apache.dubbo.demo.DemoService" timeout="3000" ref="demoService" registry="registry1" protocol="dubbo"/>
     <dubbo:service delay="5000" version="1.0.0" group="greeting" timeout="5000" interface="org.apache.dubbo.demo.GreetingService"
                    ref="greetingService" protocol="dubbo"/>
     <dubbo:service delay="5000" version="1.0.0" timeout="5000" interface="org.apache.dubbo.demo.RestDemoService"
                    ref="restDemoService" protocol="rest"/>
+    <dubbo:service delay="5000" version="1.0.0" timeout="5000" interface="org.apache.dubbo.demo.TripleService"
+                   ref="tripleService" protocol="tri"/>
 
 </beans>