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
570
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
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
3
2.1k
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
130
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
220
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
730
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.8k
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
1.2k
源内ハンズオン概要編
hideg
0
220
ALB ログから Trace を気合で繋げる技術
fohte
6
730
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
520
Loosening the Reins: Go Generics Get More Flexible
kuro_kurorrr
0
340
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
450
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
230
Featured
See All Featured
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Deep Space Network (abreviated)
tonyrice
0
270
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
900
Rails Girls Zürich Keynote
gr2m
96
14k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
490
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Evolving SEO for Evolving Search Engines
ryanjones
0
260
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
260
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
500
Unsuck your backbone
ammeep
672
58k
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 !