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
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
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
630
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
140
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
0
210
初めてのKubernetes 本番運用でハマった話
oku053
0
120
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
320
yield再入門 #phpcon
o0h
PRO
0
200
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
190
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
140
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
370
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.4k
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
690
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
240
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
190
Thoughts on Productivity
jonyablonski
76
5.2k
Un-Boring Meetings
codingconduct
0
340
What's in a price? How to price your products and services
michaelherold
247
13k
The Limits of Empathy - UXLibs8
cassininazir
1
480
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
340
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
300
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
390
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
190
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
220
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 !