Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RxJava in Microservices World
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Piotr Kafel
January 27, 2016
Programming
1.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RxJava in Microservices World
Piotr Kafel
January 27, 2016
More Decks by Piotr Kafel
See All by Piotr Kafel
Reactive - land of confusion
pkafel
0
560
Apache Kafka - short introduction
pkafel
0
140
Whats new in Java 8
pkafel
0
130
Immutability in Java
pkafel
0
85
Other Decks in Programming
See All in Programming
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.3k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
160
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.2k
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
290
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
190
Webフレームワークの ベンチマークについて
yusukebe
0
170
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
670
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.9k
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
180
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.5k
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
100
6.2k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
200
Everyday Curiosity
cassininazir
0
230
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
New Earth Scene 8
popppiees
3
2.3k
Building Adaptive Systems
keathley
44
3.1k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
Mind Mapping
helmedeiros
PRO
1
260
Joys of Absence: A Defence of Solitary Play
codingconduct
1
400
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
340
Rails Girls Zürich Keynote
gr2m
96
14k
Transcript
26-27/05/2016 RxJava in Microservices World Piotr Kafel (@PiotrKafel)
26-27/05/2016 Microservices
26-27/05/2016 Trade-offs
26-27/05/2016 Microservices time
26-27/05/2016 Microservices time
26-27/05/2016 CompletableFuture CompletableFuture<String> result = getUuid().thenApply(this::getString); public CompletableFuture<UUID> getUuid() {
// incredibly smart code goes here } public String getString(UUID uuid) { // incredibly smart code goes here }
26-27/05/2016 CompletableFuture CompletableFuture<List<CompletableFuture<String>>> ohMyGod = getUuids() .thenApply(uuids -> uuids.stream() .map(this::getString)
.collect(Collectors.toList())); public CompletableFuture<List<UUID>> getUuids() { // incredibly smart code goes here } public CompletableFuture<String> getString(UUID uuid) { // incredibly smart code goes here }
26-27/05/2016 Observable Observable<String> result = getUuids().flatMap(this::getString); public Observable<UUID> getUuids() {
// incredibly smart code goes here } public Observable<String> getString(UUID uuid) { // incredibly smart code goes here }
26-27/05/2016 RxJava
26-27/05/2016 Observable Observable.create(subscriber -> { subscriber.onNext("Hello World !"); subscriber.onCompleted(); }).forEach(System.out::println);
26-27/05/2016 Observable Observable.create(subscriber -> { subscriber.onNext("Hello"); subscriber.onNext("World"); subscriber.onNext("!"); subscriber.onCompleted(); })
.subscribeOn(Schedulers.newThread()) .forEach(System.out::println);
26-27/05/2016 Observable Observable.create(subscriber -> { try { subscriber.onNext(doSomething()); subscriber.onCompleted(); }
catch(Exception e) { subscriber.onError(e); } }).forEach( i -> System.out.print(i), e -> e.printStackTrace() );
26-27/05/2016 Documentation
26-27/05/2016 Example public Observable<DealDivision> retrieveDivisions (List <UUID> divisions) { Locale
locale = locale(); return Observable.from(divisions) .flatMap(divisionId -> geoPlacesClient.getDivisionsById(divisionId)) .filter(resp -> resp.status == SUCCESS) .flatMapIterable(resp -> resp.data) .filter(div -> div.status == Status.ACTIVE) .map(div -> new DealDivision( div.uuid.toString(), div.getNameOrDefault(locale))); }
26-27/05/2016 Pattern doHttpCallForUUids() .buffer(50) .flatMap(listOfUuids -> doHttpCallForEntities(listOfUuids));
26-27/05/2016 Pattern doHttpCall().retry( (i, throwable) -> i < 5 &&
throwable instanceof Status503Exception );
26-27/05/2016 Pattern doHttpCall().retryWhen(errorObservable -> errorObservable .zipWith(Observable.range(1, numberOfRetries), Pair::of) .flatMap(pair ->
{ if(pair.getRight() == numberOfRetries) { return Observable.error(pair.getLeft()); } else { return Observable.timer(wait, TimeUnit.MILLISECONDS); } }));
26-27/05/2016 Pattern Observable.range(1, Integer.MAX_VALUE) .concatMap(page -> doHttpCall(id, page, DEFAULT_PER_PAGE_SIZE)) .map(response
-> response.getComments()) .takeWhile(comments -> comments.size() > 0)
26-27/05/2016 Adaptation Observable.defer(() -> Observable.just(completelySynchronousHttpCall())) .subscribeOn(Schedulers.io());
26-27/05/2016 Testing TestSubscriber<String> subscriber = new TestSubscriber<>(); Observable.interval(100, TimeUnit.MILLISECONDS, Schedulers.computation())
.take(5) .map(i -> i + " value") .subscribe(subscriber); subscriber.awaitTerminalEvent(); subscriber.assertNoErrors(); subscriber.assertValueCount(5);
26-27/05/2016 Retrofit
26-27/05/2016 Retrofit public interface InventoryUnitClient { @GET("/inventory/v2/{entity}/search/redemption") Observable<JsonHolder> getInventoryUnitRedemption( @Path("uuid")
UUID uuid); @POST("/inventory/v2/{entity}/search/redemption") Observable<JsonHolder> redeemUnit( @Path("uuid") UUID uuid, @Body JsonHolder redemption); }
26-27/05/2016 Hystrix
26-27/05/2016 Hystrix public class CommandHelloWorld extends HystrixCommand<String> { private final
String name; public CommandHelloWorld(String name) { super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup")); this.name = name; } @Override protected String run() { return "Hello " + name + "!"; } }
26-27/05/2016 Spring
26-27/05/2016 Spring @RequestMapping(value = PATH_ACCOUNT_MANAGERS, method = RequestMethod.GET) public DeferredResult<AccountManagersResponse>
getAccountManagers() { DeferredResult<AccountManagersResponse> result = new DeferredResult<>(); getAccountManagersObservable().subscribe( item -> result.setResult(item), exception -> result.setErrorResult(exception) ); return result; }
26-27/05/2016 Wow, is it really that cool !?
26-27/05/2016 That’s all folks !