This is an automated email from the ASF dual-hosted git repository. liujun pushed a commit to branch samples-for-2.7.0-SNAPSHOT in repository https://gitbox.apache.org/repos/asf/incubator-dubbo-samples.git
commit 8660a3f80081d27975d7387f48c055b64351f9e1 Author: ken.lj <ken.lj...@gmail.com> AuthorDate: Wed Jan 2 19:52:20 2019 +0800 rewrite async sample --- dubbo-samples-api/pom.xml | 17 +++++++++-------- .../org/apache/dubbo/samples/api/GreetingsService.java | 10 +++++++--- .../apache/dubbo/samples/governance/AsyncConsumer.java | 9 ++++++--- .../main/resources/META-INF/spring/async-consumer.xml | 3 +-- .../governance/filter/AsyncPostprocessFilter.java | 8 ++++---- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/dubbo-samples-api/pom.xml b/dubbo-samples-api/pom.xml index d343e93..6d9900e 100644 --- a/dubbo-samples-api/pom.xml +++ b/dubbo-samples-api/pom.xml @@ -32,7 +32,7 @@ <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo-async-processer</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.0.0</version> </dependency> </dependencies> @@ -57,13 +57,14 @@ <configuration> <source>1.8</source> <target>1.8</target> - <annotationProcessorPaths> - <path> - <groupId>com.alibaba</groupId> - <artifactId>dubbo-async-processer</artifactId> - <version>1.0.0-SNAPSHOT</version> - </path> - </annotationProcessorPaths> + <!-- should be obsoleted --> + <!--<annotationProcessorPaths>--> + <!--<path>--> + <!--<groupId>com.alibaba</groupId>--> + <!--<artifactId>dubbo-async-processer</artifactId>--> + <!--<version>1.0.0-SNAPSHOT</version>--> + <!--</path>--> + <!--</annotationProcessorPaths>--> </configuration> </plugin> </plugins> diff --git a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java b/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java index 5d21f1d..cb002f5 100644 --- a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java +++ b/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java @@ -1,4 +1,3 @@ - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,9 +17,14 @@ package org.apache.dubbo.samples.api; -import com.alibaba.dubbo.config.async.DubboAsync; +import com.alibaba.dubbo.config.async.AsyncSignal; + +import java.util.concurrent.CompletableFuture; -@DubboAsync public interface GreetingsService { String sayHi(String name); + + default CompletableFuture<String> sayHi(String name, AsyncSignal signal) { + return CompletableFuture.completedFuture(sayHi(name)); + } } diff --git a/dubbo-samples-async/dubbo-samples-async-generated-future/src/main/java/org/apache/dubbo/samples/governance/AsyncConsumer.java b/dubbo-samples-async/dubbo-samples-async-generated-future/src/main/java/org/apache/dubbo/samples/governance/AsyncConsumer.java index 7198a88..84359b0 100644 --- a/dubbo-samples-async/dubbo-samples-async-generated-future/src/main/java/org/apache/dubbo/samples/governance/AsyncConsumer.java +++ b/dubbo-samples-async/dubbo-samples-async-generated-future/src/main/java/org/apache/dubbo/samples/governance/AsyncConsumer.java @@ -19,7 +19,10 @@ package org.apache.dubbo.samples.governance; -import org.apache.dubbo.samples.api.GreetingsServiceAsync; +import org.apache.dubbo.samples.api.GreetingsService; + +import com.alibaba.dubbo.config.async.AsyncSignal; + import org.springframework.context.support.ClassPathXmlApplicationContext; import java.util.concurrent.CompletableFuture; @@ -33,9 +36,9 @@ public class AsyncConsumer { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/async-consumer.xml"}); context.start(); - final GreetingsServiceAsync greetingsService = (GreetingsServiceAsync) context.getBean("greetingsService"); + final GreetingsService greetingsService = (GreetingsService) context.getBean("greetingsService"); - CompletableFuture<String> future = greetingsService.sayHiAsync("async call reqeust"); + CompletableFuture<String> future = greetingsService.sayHi("async call reqeust", AsyncSignal.SIGNAL); System.out.println("async call ret :" + future.get()); System.out.println(greetingsService.sayHi("normal sync call request")); diff --git a/dubbo-samples-async/dubbo-samples-async-generated-future/src/main/resources/META-INF/spring/async-consumer.xml b/dubbo-samples-async/dubbo-samples-async-generated-future/src/main/resources/META-INF/spring/async-consumer.xml index ed47276..43e3b61 100644 --- a/dubbo-samples-async/dubbo-samples-async-generated-future/src/main/resources/META-INF/spring/async-consumer.xml +++ b/dubbo-samples-async/dubbo-samples-async-generated-future/src/main/resources/META-INF/spring/async-consumer.xml @@ -28,6 +28,5 @@ <dubbo:registry address="zookeeper://127.0.0.1:2181"/> - <dubbo:reference id="greetingsService" interface="org.apache.dubbo.samples.api.GreetingsServiceAsync"/> - <!--<dubbo:reference id="greetingsService" interface="org.apache.dubbo.samples.api.GreetingsService"/>--> + <dubbo:reference id="greetingsService" interface="org.apache.dubbo.samples.api.GreetingsService"/> </beans> \ No newline at end of file diff --git a/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/governance/filter/AsyncPostprocessFilter.java b/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/governance/filter/AsyncPostprocessFilter.java index dfc89e2..6739b3d 100644 --- a/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/governance/filter/AsyncPostprocessFilter.java +++ b/dubbo-samples-async/dubbo-samples-async-original-future/src/main/java/org/apache/dubbo/samples/governance/filter/AsyncPostprocessFilter.java @@ -18,7 +18,7 @@ package org.apache.dubbo.samples.governance.filter; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.rpc.AbstractPostProcessFilter; +import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; @@ -28,9 +28,9 @@ import org.apache.dubbo.rpc.RpcException; * */ @Activate(group = {Constants.PROVIDER, Constants.CONSUMER}) -public class AsyncPostprocessFilter extends AbstractPostProcessFilter { +public class AsyncPostprocessFilter implements Filter { @Override - protected Result doPostProcess(Result result, Invoker<?> invoker, Invocation invocation) { + public Result onResponse(Result result, Invoker<?> invoker, Invocation invocation) { System.out.println(Thread.currentThread().getName()); System.out.println("Filter get the return value: " + result.getValue()); return result; @@ -39,6 +39,6 @@ public class AsyncPostprocessFilter extends AbstractPostProcessFilter { @Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { System.out.println(Thread.currentThread().getName()); - return postProcessResult(invoker.invoke(invocation), invoker, invocation); + return invoker.invoke(invocation); } }