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
220
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
36
Turmbau_zu_Babel.pdf
kkottke
0
110
Stream Processing with Apache Flink
kkottke
0
160
Graph Processing using Apache Flink
kkottke
0
110
Other Decks in Programming
See All in Programming
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
230
非同期jobをtransaction内で 呼ぶなよ!絶対に呼ぶなよ!
alstrocrack
0
840
アメ車でサンノゼを走ってきたよ!
s_shimotori
0
220
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
220
Django Ninja による API 開発効率化とリプレースの実践
kashewnuts
0
1.3k
理論と実務のギャップを超える
eycjur
0
130
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
240
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
200
Swift Concurrency - 状態監視の罠
objectiveaudio
2
520
TFLintカスタムプラグインで始める Terraformコード品質管理
bells17
2
160
[Kaigi on Rais 2025] 全問正解率3%: RubyKaigiで出題したやりがちな危険コード5選
power3812
0
130
デミカツ切り抜きで面倒くさいことはPythonにやらせよう
aokswork3
0
230
Featured
See All Featured
Thoughts on Productivity
jonyablonski
70
4.9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Building an army of robots
kneath
306
46k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
32
2.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.6k
Typedesign – Prime Four
hannesfritz
42
2.8k
Writing Fast Ruby
sferik
629
62k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
Building Applications with DynamoDB
mza
96
6.7k
What's in a price? How to price your products and services
michaelherold
246
12k
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.7k
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