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
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.4k
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
110
torikago - Ruby::Boxで照らすモジュラモノリスの実行境界
se4weed
1
340
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
580
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
170
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
460
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
670
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
140
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
750
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
420
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
260
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
270
Featured
See All Featured
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
520
First, design no harm
axbom
PRO
2
1.2k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Abbi's Birthday
coloredviolet
3
9.2k
How GitHub (no longer) Works
holman
316
150k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
170
Site-Speed That Sticks
csswizardry
13
1.4k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Deep Space Network (abreviated)
tonyrice
0
250
How to make the Groovebox
asonas
2
2.3k
Bash Introduction
62gerente
615
220k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
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 !