SlideShare a Scribd company logo
Intro to Vert.x
What is Vert.x

Let’s be honest, it’s node.js for JVM.

It’s polygot since it supports a few JVM languages: Kotlin, Scala,
Groovy,Ruby ,Java (depending on version maybe a few more).
Basic concepts in Vert.x

Event loop

Verticle

Event bus

And Vertx instance

Most of Vert.x API is event driven. So when you what to know
something happened Vert.x will send you event.

“Don’t call us, we’ll call your handler”
Vertx

What is Vertx instance:

As documentation says: “In the beginning there was Vertx”

Vertx instance is more or less control center of Vert.x based
app.

Most often it’s one per application.

Used to create various servers, clients, timers and much
more.
Event loop

1 event loop -> reactor pattern

More event loops -> multi reactor pattern

Vert.x uses implementation of Multi-Reactor Pattern

One event loop is always running on the same thread.
BIG RULE: Never block event loop.
Verticle

What is Verticle:

It’s combination of Vertx instance and dedicated Context

OK, but what is Context?

Well that is a tough one. But I guess simplest is that context allows us to call the user defined
callback on the verticle event loop thread. Remember events can come from other event loops.
Event bus

Means for sending and receiving messages in an asynchronous fashion.

Event bus allows for decoupling between verticles.

But even more than that, since Vert.x is polyglot verticles written in different languages can communicate using event bus.

Three basic patterns of communication:
1) Point to point
2) Request-reply
3) Publish/subscribe

But is it a message broker? Well no

It’s intended more for verticle-to-verticle communication inside an application, and not as message bus for application-to-
application communication
Different ways to write async code

Vert.x provides different coding styles to create non
blocking code:

Callback

Future/Promises

Reactive extensions (RxJava)

Kotlin coroutines
Classical callbacks
Futures and promises

Promise is used to write an eventual value, and a future is used to read it when it is available.

Promise is created by a piece of code that wants to perform async operation. Once async operation is done we complete the
promise. And via the future we get from the promise object we react to completed async operation

But even more, we can also take advantage of some more interesting capability of Vertx Future’s class:
 Future<T> recover(Function<Throwable,Future<T>> mapper) - recover in case of error
 Future<U> flatMap(Function<T,Future<U>> mapper) - composes with another future
Futures and Completable Stage

Vertx futures can work together with java.util.concurent.CompletionStage

Let’s refresh, CompletionStage is step in async operation.One of the most important thing with CompletionStage is
that we can chain them in various ways.

While Vertx Future knows how to play with CompletionStage, they are not a subtype of CompletionStage interface.

To get CompletionStage object from the Vertx future we have to call vertx Future method:
 CompletionStage<T> toCompletionStage()
Reactive extensions (RxJava)

Some basic concepts from reactive extensions:
-
Observing event streams (Observable)
-
Operator composition to transform (Operators)
-
Subscribe to stream (Observer)

RxJava operators produce observables that are observers of the Observable they are called on
Type Description
Observable<T> A stream of events of type T
Flowable<T> A stream of event of type T.
Supports back-pressure
Single<T> Source that emits exactly one
event
Maybe<T> Source may emit one event,
or none
RxJava+Vert.x

Since working with RxJava results in entire different API for Vert.x to use this API new
dependency needs to be added.

Also most of the classes now used are in package io.vertx.reactivex.*

For example io.vertx.reactivex.core.AbstractVerticle as opposed to the one we used until
now io.vertx.core.AbstractVerticle

Most of the rxJava metods are prefixed with rx****()

Another thing to keep an eye on, rxJava often creates thread to handle some operation, and vertx
handles it’s own threading model in some situations it’s good to be aware of this fact.
ReadStream and WriteStream

In case of reading files, Http requests/responses, data from sockets we need something better than
some standard java InputStream or OutputStream since we are in non blocking environment.

To help with that Vert.x provides ReadStream and WriteStream across several type of resources

Core of both these abstractions is:
 Methods for reading/writing data
 Methods for back-pressure management
ReadStream and WriteStream

Example read file:
 How do we do it “classically”?
 What is the difference between vert.x approach and classical
 One pulls data, other pushes data
 Great,right?
ReadStream and WriteStream

So we need back-pressure

Different back-pressure strategies:
 Control
 Buffer
 Drop

Lucky for us ReadStream and WriteStream implement control strategy

Idea is following, for example when reading file to http response:
 While vert.x is pushing read buffers we are writing it to response stream
 Check if write buffer is full
 If it is full:

Pause the read stream

Install drain handler that resumes the file read stream when called
Is this reactive?
●
Reactive programming
●
Reactive systems

More Related Content

What's hot

Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Alexander Lisachenko
 
Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
Anton Babenko
 
Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09
Ilya Grigorik
 
Webconf nodejs-production-architecture
Webconf nodejs-production-architectureWebconf nodejs-production-architecture
Webconf nodejs-production-architectureBen Lin
 
Hosting a Rails App
Hosting a Rails AppHosting a Rails App
Hosting a Rails App
Josh Schramm
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data binding
Alex Derkach
 
OSDC 2019 | Virtualisation in Docker, using KVM as Hypervisor by Kososochukwu...
OSDC 2019 | Virtualisation in Docker, using KVM as Hypervisor by Kososochukwu...OSDC 2019 | Virtualisation in Docker, using KVM as Hypervisor by Kososochukwu...
OSDC 2019 | Virtualisation in Docker, using KVM as Hypervisor by Kososochukwu...
NETWAYS
 
Kraken js at paypal
Kraken js at paypalKraken js at paypal
Kraken js at paypal
Lenny Markus
 
IaC and Immutable Infrastructure with Terraform, Сергей Марченко
IaC and Immutable Infrastructure with Terraform, Сергей МарченкоIaC and Immutable Infrastructure with Terraform, Сергей Марченко
IaC and Immutable Infrastructure with Terraform, Сергей Марченко
Sigma Software
 
WebSockets with Spring 4
WebSockets with Spring 4WebSockets with Spring 4
WebSockets with Spring 4
Sergi Almar i Graupera
 
The Mission Critical Cloud
The Mission Critical CloudThe Mission Critical Cloud
The Mission Critical Cloud
Remi Bergsma
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.js
Prabin Silwal
 
Managing Your Cisco Datacenter Network with Ansible
Managing Your Cisco Datacenter Network with AnsibleManaging Your Cisco Datacenter Network with Ansible
Managing Your Cisco Datacenter Network with Ansible
fmaccioni
 
Web sockets in Java
Web sockets in JavaWeb sockets in Java
Web sockets in Java
Pance Cavkovski
 
Mitchell Hashimoto, HashiCorp
Mitchell Hashimoto, HashiCorpMitchell Hashimoto, HashiCorp
Mitchell Hashimoto, HashiCorp
Ontico
 
Realtime Streaming using Autobahn Websockets
Realtime Streaming using Autobahn WebsocketsRealtime Streaming using Autobahn Websockets
Realtime Streaming using Autobahn Websockets
Tom Sheffler
 
What you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructureWhat you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructure
Anton Babenko
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.js
Sebastian Springer
 
Ruby 1.9 Fibers
Ruby 1.9 FibersRuby 1.9 Fibers
Ruby 1.9 Fibers
Kevin Ball
 

What's hot (20)

Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
 
Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
 
Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09
 
Webconf nodejs-production-architecture
Webconf nodejs-production-architectureWebconf nodejs-production-architecture
Webconf nodejs-production-architecture
 
Hosting a Rails App
Hosting a Rails AppHosting a Rails App
Hosting a Rails App
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data binding
 
OSDC 2019 | Virtualisation in Docker, using KVM as Hypervisor by Kososochukwu...
OSDC 2019 | Virtualisation in Docker, using KVM as Hypervisor by Kososochukwu...OSDC 2019 | Virtualisation in Docker, using KVM as Hypervisor by Kososochukwu...
OSDC 2019 | Virtualisation in Docker, using KVM as Hypervisor by Kososochukwu...
 
Kraken js at paypal
Kraken js at paypalKraken js at paypal
Kraken js at paypal
 
IaC and Immutable Infrastructure with Terraform, Сергей Марченко
IaC and Immutable Infrastructure with Terraform, Сергей МарченкоIaC and Immutable Infrastructure with Terraform, Сергей Марченко
IaC and Immutable Infrastructure with Terraform, Сергей Марченко
 
WebSockets with Spring 4
WebSockets with Spring 4WebSockets with Spring 4
WebSockets with Spring 4
 
The Mission Critical Cloud
The Mission Critical CloudThe Mission Critical Cloud
The Mission Critical Cloud
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.js
 
Managing Your Cisco Datacenter Network with Ansible
Managing Your Cisco Datacenter Network with AnsibleManaging Your Cisco Datacenter Network with Ansible
Managing Your Cisco Datacenter Network with Ansible
 
Web sockets in Java
Web sockets in JavaWeb sockets in Java
Web sockets in Java
 
Mitchell Hashimoto, HashiCorp
Mitchell Hashimoto, HashiCorpMitchell Hashimoto, HashiCorp
Mitchell Hashimoto, HashiCorp
 
About Node.js
About Node.jsAbout Node.js
About Node.js
 
Realtime Streaming using Autobahn Websockets
Realtime Streaming using Autobahn WebsocketsRealtime Streaming using Autobahn Websockets
Realtime Streaming using Autobahn Websockets
 
What you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructureWhat you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructure
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.js
 
Ruby 1.9 Fibers
Ruby 1.9 FibersRuby 1.9 Fibers
Ruby 1.9 Fibers
 

Similar to BASICS OF VERT.X - A toolkit for building asynchronous and reactive app

Rx Swift
Rx SwiftRx Swift
Rx Swift
Vincenzo Favara
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
Fwdays
 
Spring, Functions, Serverless and You
Spring, Functions, Serverless and YouSpring, Functions, Serverless and You
Spring, Functions, Serverless and You
VMware Tanzu
 
Start with swift
Start with swiftStart with swift
RxJava@DAUG
RxJava@DAUGRxJava@DAUG
RxJava@DAUG
Maxim Volgin
 
Vert.x devoxx london 2013
Vert.x devoxx london 2013Vert.x devoxx london 2013
Vert.x devoxx london 2013
Stuart (Pid) Williams
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and Scala
Max Alexejev
 
Vertx
VertxVertx
Vertx
VertxVertx
Best node js course
Best node js courseBest node js course
Best node js course
bestonlinecoursescoupon
 
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
HostedbyConfluent
 
Javascript internals
Javascript internalsJavascript internals
Javascript internals
Ayush Sharma
 
Is OSGi modularity always worth it?
Is OSGi modularity always worth it?Is OSGi modularity always worth it?
Is OSGi modularity always worth it?glynnormington
 
07 - Extending VQL and API in Velociraptor.pptx
07 - Extending VQL and API in Velociraptor.pptx07 - Extending VQL and API in Velociraptor.pptx
07 - Extending VQL and API in Velociraptor.pptx
matthewcybercentaurs
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
NexThoughts Technologies
 
Ruby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay ShanghaiRuby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay Shanghai
Jackson Tian
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async Library
Knoldus Inc.
 
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Rick Hightower
 
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Rick Hightower
 

Similar to BASICS OF VERT.X - A toolkit for building asynchronous and reactive app (20)

Rx Swift
Rx SwiftRx Swift
Rx Swift
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
 
Spring, Functions, Serverless and You
Spring, Functions, Serverless and YouSpring, Functions, Serverless and You
Spring, Functions, Serverless and You
 
Start with swift
Start with swiftStart with swift
Start with swift
 
RxJava@DAUG
RxJava@DAUGRxJava@DAUG
RxJava@DAUG
 
Vert.x devoxx london 2013
Vert.x devoxx london 2013Vert.x devoxx london 2013
Vert.x devoxx london 2013
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and Scala
 
Vertx
VertxVertx
Vertx
 
Vertx
VertxVertx
Vertx
 
DZone_RC_RxJS
DZone_RC_RxJSDZone_RC_RxJS
DZone_RC_RxJS
 
Best node js course
Best node js courseBest node js course
Best node js course
 
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
 
Javascript internals
Javascript internalsJavascript internals
Javascript internals
 
Is OSGi modularity always worth it?
Is OSGi modularity always worth it?Is OSGi modularity always worth it?
Is OSGi modularity always worth it?
 
07 - Extending VQL and API in Velociraptor.pptx
07 - Extending VQL and API in Velociraptor.pptx07 - Extending VQL and API in Velociraptor.pptx
07 - Extending VQL and API in Velociraptor.pptx
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
 
Ruby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay ShanghaiRuby vs Node ShiningRay Shanghai
Ruby vs Node ShiningRay Shanghai
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async Library
 
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
 
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
 

Recently uploaded

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 

Recently uploaded (20)

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 

BASICS OF VERT.X - A toolkit for building asynchronous and reactive app

  • 2. What is Vert.x  Let’s be honest, it’s node.js for JVM.  It’s polygot since it supports a few JVM languages: Kotlin, Scala, Groovy,Ruby ,Java (depending on version maybe a few more).
  • 3. Basic concepts in Vert.x  Event loop  Verticle  Event bus  And Vertx instance  Most of Vert.x API is event driven. So when you what to know something happened Vert.x will send you event.  “Don’t call us, we’ll call your handler”
  • 4. Vertx  What is Vertx instance:  As documentation says: “In the beginning there was Vertx”  Vertx instance is more or less control center of Vert.x based app.  Most often it’s one per application.  Used to create various servers, clients, timers and much more.
  • 5. Event loop  1 event loop -> reactor pattern  More event loops -> multi reactor pattern  Vert.x uses implementation of Multi-Reactor Pattern  One event loop is always running on the same thread. BIG RULE: Never block event loop.
  • 6. Verticle  What is Verticle:  It’s combination of Vertx instance and dedicated Context  OK, but what is Context?  Well that is a tough one. But I guess simplest is that context allows us to call the user defined callback on the verticle event loop thread. Remember events can come from other event loops.
  • 7. Event bus  Means for sending and receiving messages in an asynchronous fashion.  Event bus allows for decoupling between verticles.  But even more than that, since Vert.x is polyglot verticles written in different languages can communicate using event bus.  Three basic patterns of communication: 1) Point to point 2) Request-reply 3) Publish/subscribe  But is it a message broker? Well no  It’s intended more for verticle-to-verticle communication inside an application, and not as message bus for application-to- application communication
  • 8. Different ways to write async code  Vert.x provides different coding styles to create non blocking code:  Callback  Future/Promises  Reactive extensions (RxJava)  Kotlin coroutines
  • 10. Futures and promises  Promise is used to write an eventual value, and a future is used to read it when it is available.  Promise is created by a piece of code that wants to perform async operation. Once async operation is done we complete the promise. And via the future we get from the promise object we react to completed async operation  But even more, we can also take advantage of some more interesting capability of Vertx Future’s class:  Future<T> recover(Function<Throwable,Future<T>> mapper) - recover in case of error  Future<U> flatMap(Function<T,Future<U>> mapper) - composes with another future
  • 11. Futures and Completable Stage  Vertx futures can work together with java.util.concurent.CompletionStage  Let’s refresh, CompletionStage is step in async operation.One of the most important thing with CompletionStage is that we can chain them in various ways.  While Vertx Future knows how to play with CompletionStage, they are not a subtype of CompletionStage interface.  To get CompletionStage object from the Vertx future we have to call vertx Future method:  CompletionStage<T> toCompletionStage()
  • 12. Reactive extensions (RxJava)  Some basic concepts from reactive extensions: - Observing event streams (Observable) - Operator composition to transform (Operators) - Subscribe to stream (Observer)  RxJava operators produce observables that are observers of the Observable they are called on Type Description Observable<T> A stream of events of type T Flowable<T> A stream of event of type T. Supports back-pressure Single<T> Source that emits exactly one event Maybe<T> Source may emit one event, or none
  • 13. RxJava+Vert.x  Since working with RxJava results in entire different API for Vert.x to use this API new dependency needs to be added.  Also most of the classes now used are in package io.vertx.reactivex.*  For example io.vertx.reactivex.core.AbstractVerticle as opposed to the one we used until now io.vertx.core.AbstractVerticle  Most of the rxJava metods are prefixed with rx****()  Another thing to keep an eye on, rxJava often creates thread to handle some operation, and vertx handles it’s own threading model in some situations it’s good to be aware of this fact.
  • 14. ReadStream and WriteStream  In case of reading files, Http requests/responses, data from sockets we need something better than some standard java InputStream or OutputStream since we are in non blocking environment.  To help with that Vert.x provides ReadStream and WriteStream across several type of resources  Core of both these abstractions is:  Methods for reading/writing data  Methods for back-pressure management
  • 15. ReadStream and WriteStream  Example read file:  How do we do it “classically”?  What is the difference between vert.x approach and classical  One pulls data, other pushes data  Great,right?
  • 16. ReadStream and WriteStream  So we need back-pressure  Different back-pressure strategies:  Control  Buffer  Drop  Lucky for us ReadStream and WriteStream implement control strategy  Idea is following, for example when reading file to http response:  While vert.x is pushing read buffers we are writing it to response stream  Check if write buffer is full  If it is full:  Pause the read stream  Install drain handler that resumes the file read stream when called
  • 17. Is this reactive? ● Reactive programming ● Reactive systems