Vert.X is...
- Event-Driven aka asynchronous
- NIO (Non-Blocking I/O) based
- Light-weight
- Reactive (See Reactor Pattern - http://en.wikipedia.org/wiki/Reactor_pattern)
- Distributed
- Scalable
- Resilient
- Node like but, not a clone :)
- Isomorphic
- Polygot!
- Extensible...
Verticles
The smallest unit of code that runs inside a Vert.x instance. Strictly single-threaded.
Many of them can be executed concurrently in different nodes/instances.
Composable units forming pipeline or network of code execution.
Written in a supported programming language of your choice...
var vertx = require('vertx');
vertx.createHttpServer().requestHandler(function(req) {
req.response.end("Hi there STLJS!");
}).listen(8080, 'localhost');
Modules
Functional encapsulation of verticles.
Typical Vert.x application is composed of one more more modules.
Uses mod.json as module descriptor
Module registry is available at - http://modulereg.vertx.io/
vertx install io.vertx~mod-redis-client~1.1.4
Worker Verticles
Verticles where you can run blocking calls. Remember JDBC ?
Multi-threaded, where you can perform computationally intensive/blocking operations.
Be careful using this, it won't scale!
Async huh?
-
JavaScript developers are comfortable with asynchrous style programming due to DOM event handlers, callbacks etc.
- Java & other languages are catching up on this style
- No more single thread for every single request
- Obviously, its easier said than done.
- So, seek help from promise libraries & modules like mod-rx-vertx which uses RxJava library (inspired by .Net's Reactive extensions)
Vert.x instances
- Where the verticles are run...
- A single instance runs inside its own JVM instance
- Instances are clustered within the same host or on different hosts across the network forming a distributed event bus
- Guaranteed that a single instance will not be executed by more than one thread concurrently
Distributed Event Bus
- Nervous system of Vert.x!
- Verticles communicate with each other over the distributed event bus.
- Messaging Models
- Point-to-Point
- Request/Response
- Publish/Subscribe
- Layer transparent!
- Also available at the browser.Think Firebase, Meteor!
- Demo will be coming shortly.
Message Types
- number
- string
- boolean
- JSON object
- Vert.x Buffer
Shared Data (Maps & Sets)
Data structure to share across verticles & modules.
Meant to be immutable!
var map = vertx.getMap('myMap');
map.put('myKey', 'myValue');
var set = vertx.getSet('mySet');
set.add('myValue');
Clusters
Out-of-box clustering support.
Pluggable clustering manager, default is based on Hazelcast
High Availability (HA) mode
Automatic failover support!
Faul tolerant eh...
When a module fails in one node, it will automatically start on another node on the cluster.
vertx -ha
Demo please...
APIs
- vertx
- vertx/container
- vertx/buffer
- vertx/console
- vertx/datagram
- vertx/dns
- vertx/event_bus
- vertx/file_system
- vertx/http
- vertx/net
- vertx/shared_data
- vertx/sockjs
- vertx/timer
- etc.
Container APIs
- Used for dynamically deploying & un-deploying verticles and modules
/*Deploy 4 instance of verticle.js*/
container.deployVerticle("verticle.js", 4);
Serve what?
- HTTP/HTTPS client & server
- HTTP methods (GET, PUT, POST etc.)
- Supports HTTP chunked transfer encoding
- Multipart
- WebSockets
- SockJS server
- etc.
References
- http://www.infoq.com/presentations/performance-reactive-vertx/
- http://vertx.io/manual.html
- http://vertx.io/core_manual_js.html
- https://github.com/vert-x
- https://github.com/vert-x