This is an automated email from the ASF dual-hosted git repository. liujun pushed a commit to branch 3.0 in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit bf34c16992a13a243fb36892e711921f654a083a Author: ken.lj <[email protected]> AuthorDate: Mon Jul 27 15:35:49 2020 +0800 add demo --- .../apache/dubbo/demo/consumer/Application.java | 19 ++++++++++++++ .../src/main/resources/spring/dubbo-consumer.xml | 3 +++ .../dubbo/demo/provider/GreetingServiceImpl.java | 29 ++++++++++++++++++++++ .../src/main/resources/spring/dubbo-provider.xml | 7 ++++-- 4 files changed, 56 insertions(+), 2 deletions(-) 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 f637eb2..fba18bc 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 @@ -17,6 +17,7 @@ package org.apache.dubbo.demo.consumer; import org.apache.dubbo.demo.DemoService; +import org.apache.dubbo.demo.GreetingService; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -31,9 +32,27 @@ public class Application { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml"); context.start(); DemoService demoService = context.getBean("demoService", DemoService.class); + GreetingService greetingService = context.getBean("greetingService", GreetingService.class); + + new Thread(() -> { + while (true) { + String greetings = greetingService.hello(); + System.out.println(greetings + " from separated thread."); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }).start(); + while (true) { CompletableFuture<String> hello = demoService.sayHelloAsync("world"); System.out.println("result: " + hello.get()); + + String greetings = greetingService.hello(); + System.out.println("result: " + greetings); + Thread.sleep(500); } } 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 bec81fe..44e8712 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 @@ -33,4 +33,7 @@ <dubbo:reference provided-by="demo-provider" id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService"/> + <dubbo:reference provided-by="demo-provider" version="1.0.0" group="greeting" id="greetingService" check="false" + interface="org.apache.dubbo.demo.GreetingService"/> + </beans> diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/GreetingServiceImpl.java b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/GreetingServiceImpl.java new file mode 100644 index 0000000..cc1b5de --- /dev/null +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/GreetingServiceImpl.java @@ -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. + */ +package org.apache.dubbo.demo.provider; + +import org.apache.dubbo.demo.GreetingService; + +/** + * + */ +public class GreetingServiceImpl implements GreetingService { + @Override + public String hello() { + return "Greetings!"; + } +} 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 90a6ae3..856ff73 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 @@ -29,10 +29,13 @@ <dubbo:metadata-report address="zookeeper://127.0.0.1:2181"/> <dubbo:registry id="registry1" address="zookeeper://127.0.0.1:2181?registry-type=service"/> - <dubbo:protocol name="dubbo"/> + <dubbo:protocol name="dubbo" port="-1"/> <bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl"/> + <bean id="greetingService" class="org.apache.dubbo.demo.provider.GreetingServiceImpl"/> - <dubbo:service interface="org.apache.dubbo.demo.DemoService" ref="demoService" registry="registry1"/> + <dubbo:service interface="org.apache.dubbo.demo.DemoService" timeout="3000" ref="demoService" registry="registry1"/> + <dubbo:service version="1.0.0" group="greeting" timeout="5000" interface="org.apache.dubbo.demo.GreetingService" + ref="greetingService"/> </beans>
