“Vert.x is a lightweight, high performance application platform for the JVM that's designed for modern mobile, web, and enterprise applications.”http://vertx.io
Small
Fast
Buzzwordy
“Vert.x is a lightweight, high performance application platform for the JVM...”
< 5MB Download Size
Embeddable
Modular
“Vert.x is a lightweight, high performance application platform for the JVM...”
Hundreds of thousands of responses per second
Built on Netty | netty.io
~ 500k requests/second
“Vert.x is a lightweight, high performance application platform for the JVM...”
There was a time when every new train engine was accompanied by its own rail gauge.
Eventually, having all trains able to run on all track was more important.
-- Robb Greathouse, Red Hat“Vert.x is a lightweight, high performance application platform for the JVM...”
Java, JRuby, Jython, Javascript, Groovy, Scala, Clojure
Polygasm
“Vert.x is a lightweight, high performance application platform for the JVM...”
Each language has an API similar to the core Java API, but exposed with language-specific semantics
“Vert.x is a lightweight, high performance application platform for the JVM...”
Language APIs are Vert.x modules just like anything else outside of the core Java API
Ada, AWK, BASIC, BBx, Boo, C, COBOL, ColdFusion, Common Lisp, Component Pascal, Erlang, Forth, Go, Haxe, JavaScript, Logo, Lua, Yeti ML, Oberon-2, OCaml, Object Pascal, Pascal, PHP, Prolog, Python, R, REXX, Ruby, Scheme, Tcl
...for modern mobile, web, and enterprise applications
Concurrency With Thread Safety
Asynchronous/Reactive
Client Push
Node.js
Flying Rainbow Unicorns
// You can require API modules piecemeal
var container = require('vertx/container');
// Or you can pull everything in at once
// var vertx = require('vertx');
// var container = vertx.container;
var config = {
"web_root": ".",
"port": 8080
};
// With vertx-platform you can deploy modules programatically and
// Vert.x will find, find, download and install them for you at
// runtime. This is the source code for the presentation I'm giving
// right now.
container.deployModule("io.vertx~mod-web-server~2.0.0-final", config);
This is the Verticle that is serving up this presentation.
// The vertx object is inherited from our superclass
HttpServer server = vertx.createHttpServer();
server.requestHandler(new Handler< HttpServerRequest >() {
public void handle(HttpServerRequest request) {
request.response().setStatusCode(779);
request.response().setStatusMessage("Too many gerbils");
request.response().write("Off by too many to count error").end();
}
});
server.listen(8080, "localhost");
// Requiring 'vertx' pulls in everything
var vertx = require('vertx');
// And hangs most of it off of a global 'vertx' object
var server = vertx.createHttpServer();
// Handle incoming HTTP requests
server.requestHandler(function(request) {
request.response.statusCode(779)
request.response.statusMessage("Too many gerbils")
request.response.write("Off by too many to count error").end();
});
// Start the server
server.listen(8080, "localhost");
(ns demo.verticle
(:require [vertx.http :as http]
[vertx.stream :as stream]))
(defn req-handler [req]
(-> (http/server-response req {:status-code 779, :status-message "Too many gerbils"})
(stream/write "Off by too many to count error")
(http/end)))
(-> (http/server)
(http/on-request req-handler)
(http/listen 8080))
require "vertx"
server = Vertx::HttpServer.new
// Handle incoming HTTP requests
server.request_handler do |request|
request.response.status_code = 779
request.response.status_message = "Too many gerbils"
request.response.write("Off by too many to count error").end;
end
// Start the server
server.listen(8080, "localhost")
A Verticle is the unit of code that Vert.x runs.
$ vertx run app.js -conf config.json -instances 3
Verticles can be deployed programmatically too.
# Deploying a Clojure verticle from JRuby!
vertx.deploy_verticle('broker.clj') do |err, deployment_id|
puts 'deploy successful!' unless err
end
Verticles are assigned to an event loop
Event loops are assigned to a thread
Threads are assigned to a processor core
Thread safety without compromising cores
Thread.sleep() Object.wait() CountdownLatch.await() etc..
while(true) {console.log("Super Awesome");}
SELECT DISTINCT t1.*, t2.*, t3.* FROM products t1, prices t2, sizes t3 WHERE t1.name LIKE '%bacon%'
var fs = require('vertx/file_system');
fs.open('/etc/passwd', function(buffer) {
// commit evil
// It's OK, as long as you DON'T BLOCK THE EVENT LOOP!
});
The unit of deployment in Vert.x. Modules can contain multiple verticles, potentially written in different languages.
var container = require('vertx/container');
container.deployModule("io.vertx~mod-web-server~2.0.0-final", config);
container.deployWorkerVerticle("databaseCruncher.rb", config);
container.deployVerticle("app.clj", config);
var fs = require('vertx/file_system');
fs.open('/etc/passwd', function(buffer) {
// commit evil
// It's OK, as long as you DON'T BLOCK THE EVENT LOOP!
});
var http = require('vertx/http');
var net = require('vertx/net');
var server = http.createHttpServer();
server.requestHandler(function(request) {
request.response.write("Hello from Vert.x!").end();
}).listen(8080, "localhost");
var client = http.createNetClient().connect(8080, function(socket) {
socket.write("GET / HTTP/1.1\n");
// etc..
});
var timer = require('vertx/timer');
var console = require('vertx/console');
var id = timer.setTimer(5000, function() {
console.log("I'm 5 seconds in the future!");
});
timer.setPeriodic(2000, function() {
console.log("I SHOUT EVERY 2 SECONDS!");
});
console.log("Attention, here comes the loudmouth");
timer.cancelTimer(id);
var bus = require('vertx/event_bus');
var console = require('vertx/console');
bus.registerHandler('app.messages', function(msg, reply) {
console.log("Handler got: " + msg);
reply("Echoing: " + msg);
});
// send a message to everyone!
bus.publish('app.messages', 'Hey Everybody!');
// send a message to a single recipient and get a response
bus.send('app.messages', 'Hey You!', function(reply) {
console.log('Got echo: ' + reply);
});
var eb = new vertx.EventBus('http://localhost:8080/eventbus');
eb.onopen = function() {
eb.registerHandler('app.messages', function(message) {
console.log('Got a message in the browser! '
+ JSON.stringify(message);
});
eb.send('app.messages',
{type: 'corn chip', flavor: 'nacho cheese', count: 31417});
}
Browsers are peers on the Vert.x event bus!
Security of the mongo data
Minimize duplicate messages (e.g. mongo msg vs. browser msg)
Prevent malicious users from doing bad things
Allow each user to only vote once
http://github.com/eclipse/vert.x
http://github.com/lance/dataIO2013
Google vertx group
#vertx on irc.freenode.net
@vertx_project on Twitter