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
Reactive Microservices based on Vert.x
Search
Kristian Kottke
March 19, 2019
Programming
0
150
Reactive Microservices based on Vert.x
Kristian Kottke
March 19, 2019
Tweet
Share
More Decks by Kristian Kottke
See All by Kristian Kottke
Jeder wie er will, aber so nicht
kkottke
0
9
Turmbau_zu_Babel.pdf
kkottke
0
110
Stream Processing with Apache Flink
kkottke
0
130
Graph Processing using Apache Flink
kkottke
0
100
Other Decks in Programming
See All in Programming
Domain-Driven Transformation
hschwentner
2
1.5k
try! Swift Tokyo 2024 参加報告 / try! Swift Tokyo 2024 Report
hironytic
0
220
Node.js v22 で変わること
yosuke_furukawa
PRO
11
3.9k
if constexpr文はテンプレート世界のラムダ式である
faithandbrave
3
670
禅の心を手に入れよ
eltociear
1
280
AWS CDKコントリビュートTIPS / aws-cdk-contribution-tips
gotok365
4
320
#phpcon_odawara オープン・クローズドなテストフィクスチャを求めて / open closed test fixtures
77web
3
240
障害対応を起点としたもっといい開発と運用のサイクル作りのためにできること / Hatena Enginner Seminar #29
polamjag
0
340
Kotlin Multiplatform at Stable and Beyond (Android Makers 2024)
zsmb
0
430
Sheets API使ってみた
toshi0383
2
160
Goのエラースタックトレースの歴史と今後
sonatard
10
1.8k
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
1k
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
Gamification - CAS2011
davidbonilla
77
4.6k
The Cult of Friendly URLs
andyhume
74
5.7k
Building Your Own Lightsaber
phodgson
100
5.7k
Docker and Python
trallard
35
2.7k
Bootstrapping a Software Product
garrettdimon
PRO
302
110k
Ruby is Unlike a Banana
tanoku
96
10k
A Philosophy of Restraint
colly
197
16k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
14
1.5k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
242
1.2M
Transcript
JavaLand Kristian Kottke Going Reactive Reactive Microservices based on Vert.x
©iteratec Whoami Kristian Kottke › Lead Software Engineer -> iteratec
Interests › Software Architecture › Big Data Technologies
[email protected]
@_kkottke github.com/kkottke xing.to/kkottke speakerdeck.com/kkottke
©iteratec
©iteratec Photo by Markus Spiske on Unsplash
©iteratec Microservice cloud native fault tolerance highly responsive scalable resilient
high availability multi core asynchronous flexible loosely coupled elastic Reactive System
©iteratec Reactive Systems
©iteratec Reactive Manifesto Responsive Resilient Elastic Message Driven
©iteratec Reactive Programming != Reactive Systems
©iteratec
©iteratec ...a toolkit for building reactive, non-blocking, asynchronous applications on
the JVM (based on netty with additional modules)
©iteratec !=
©iteratec ==
©iteratec !=
©iteratec
©iteratec Event Bus Host JVM Vert.x Instance Verticle (Java) Verticle
(Java) Verticle (JS) Verticle (Kotlin) JVM Vert.x Instance Verticle (Java) Verticle (Java) Verticle (JS) Verticle (Kotlin)
©iteratec Event Bus Host JVM Vert.x Instance Verticle (Java) Verticle
(Java) Verticle (JS) Verticle (Kotlin) Host JVM Vert.x Instance Verticle (Java) Verticle (Java) Verticle (JS) Verticle (Kotlin)
©iteratec Event Bus Host JVM Vert.x Instance Verticle (Java) Verticle
(Java) Verticle (JS) Verticle (Kotlin) Event Bus Bridge
©iteratec Reactor Pattern Event Queue Event Loop Handler Handler Handler
©iteratec Multi-Reactor Pattern ...
©iteratec Code
©iteratec Message Traders Generator Service Portfolio Message Audit ElasticSearch Kibana
Message REST
©iteratec public static void main(String[] args) { Vertx vertx =
new Vertx(); vertx.deployVerticle(new RestApiVerticle()); } Verticle
©iteratec public void start(Future<Void> future) { HttpServer server = vertx.createHttpServer()
.requestHandler(req -> req.response().end(„hello“)); server.listen(8080, res -> { if (res.succeeded()) { future.complete(); } else { future.fail(res.cause()); }}); } RestApiVerticle
©iteratec Don’t call us, we’ll call you! ›Synchronous (blocking) compute(1,
2); ›Asynchronous (non-blocking) compute(1, 2, res -> {…}); ›Everything is an event → Handler → Callback Hell → RX
©iteratec Digression: ReactiveX ›API for async programming with observable streams
›Observable › Evolution of Callback, Promise, Future › Subscribe: next, error, complete › Completable, Single, Maybe, Flowable ›Reactive Operators Observable Observable Subcriber onNext Produce
©iteratec public Completable rxStart() { return vertx.createHttpServer() .requestHandler(req -> req.response().end(„hello“))
.rxListen(8080) .ignoreElement(); } RestApiVerticle (rxified)
©iteratec public Completable rxStart() { return OpenAPI3RouterFactory.rxCreate(vertx, „api.yml“) .map(factory ->
{ factory.addHandlerByOperationId(„op“, this:op); return factory.getRouter(); }) .flatMap(router -> vertx.createHttpServer() .requestHandler(router) .rxListen(8080)) .ignoreElement(); } Web API Contract
©iteratec public void publish(Message mes) { vertx.eventBus().publish(„addr“, Json.encode(mes)); vertx.eventBus().rxSend(„addr“, Json.encode(mes));
} public void handle() { vertx.eventBus().<String>consumer(„addr“, m -> { Message mes = Json.decodeValue(m.body(), Message.class); .... } } Event Bus
©iteratec Message Traders Generator Service Portfolio Message Audit ElasticSearch Kibana
Message REST
©iteratec @ProxyGen @VertxGen public interface TradingService { @Fluent TradingService buy(int
amount, JsonObject json, Handler<AsyncResult<Portfolio>> handler); } Service Proxy (RPC)
©iteratec public void publish() { ServiceDiscovery sd = ServiceDiscovery.create(vertx); Record
http = HttpEndpoint.createRecord(...); Record message = MessageSource.createRecord(...); Record service = EventBusService.createRecord(...); sd.rxPublish(http); } Service Discovery
©iteratec public void consume() { ServiceDiscovery sd = ServiceDiscovery.create(vertx); client
= HttpEndpoint.rxGetWebClient(sd, json); consumer = MessageSource.rxGetConsumer(sd, json); proxy = EventBusService.getServiceProxy(sd, ...); } Service Discovery
©iteratec Failure Handling ›Error Handler › subscribe(success, error) ›Error Operator
› doOnError, onErrorReturn, ... ›Timeout Operator › timeout ›Retry Operator › retry, retryWhen ›Circuit Breaker › breaker.execute(...)
©iteratec Are we reactive now? ›Reactive Programming › Asynchronous, non-blocking
› Event-Driven ›Reactive System › Responsive › Resilient › Elastic › Message-Driven
©iteratec
©iteratec Modules ›Config ›Health Check ›Web (SockJS) ›Unit / Junit
5 ›Web API Service ›gRPC ›Sync
©iteratec When/Why Vert.x? ›Small Services ›Reactive Application ›Scalability ›Cloud Environment
›Polyglot
©iteratec Demo
©iteratec Wrap Up ›Toolkit for building reactive, non-blocking applications ›Multi-Reactor
Pattern & Event Bus › Asynchronous › Event-Driven › Performance & Scalability
©iteratec
[email protected]
@_kkottke github.com/kkottke xing.to/kkottke speakerdeck.com/kkottke https://github.com/kkottke/stock-trading.git
www.iteratec.de Contact Kristian Kottke
[email protected]
@_kkottke github.com/kkottke xing.to/kkottke speakerdeck.com/kkottke