From e9cf47bec1aba4c062085e93b547d721ebea9db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20M=C3=A9sz=C3=A1rovics?= Date: Fri, 2 Sep 2016 14:07:35 +0200 Subject: [PATCH] added reactive collapser example --- hystrix-contrib/hystrix-javanica/README.md | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/hystrix-contrib/hystrix-javanica/README.md b/hystrix-contrib/hystrix-javanica/README.md index 49a730dfd..a09147f3f 100644 --- a/hystrix-contrib/hystrix-javanica/README.md +++ b/hystrix-contrib/hystrix-javanica/README.md @@ -580,10 +580,18 @@ Suppose you have some command which calls should be collapsed in one backend cal Example: ```java + + /** Asynchronous Execution */ @HystrixCollapser(batchMethod = "getUserByIds") - public Future getUserById(String id) { + public Future getUserByIdAsync(String id) { return null; } + + /** Reactive Execution */ + @HystrixCollapser(batchMethod = "getUserByIds") + public Observable getUserByIdReact(String id) { + return null; + } @HystrixCommand public List getUserByIds(List ids) { @@ -593,13 +601,23 @@ Example: } return users; } - - Future f1 = userService.getUserById("1"); - Future f2 = userService.getUserById("2"); - Future f3 = userService.getUserById("3"); - Future f4 = userService.getUserById("4"); - Future f5 = userService.getUserById("5"); + // Async + Future f1 = userService.getUserByIdAsync("1"); + Future f2 = userService.getUserByIdAsync("2"); + Future f3 = userService.getUserByIdAsync("3"); + Future f4 = userService.getUserByIdAsync("4"); + Future f5 = userService.getUserByIdAsync("5"); + + // Reactive + Observable u1 = getUserByIdReact("1"); + Observable u2 = getUserByIdReact("2"); + Observable u3 = getUserByIdReact("3"); + Observable u4 = getUserByIdReact("4"); + Observable u5 = getUserByIdReact("5"); + + // Materialize reactive commands + Iterable users = Observables.merge(u1, u2, u3, u4, u5).toBlocking().toIterable(); ``` A method annotated with ```@HystrixCollapser``` annotation can return any value with compatible type, it does not affect the result of collapser execution, collapser method can even return ```null``` or another stub. There are several rules applied for methods signatures.