Vert.x
Original author(s) | Tim Fox |
---|---|
Developer(s) | Tim Fox, VMWare, Red Hat |
Stable release | 2.1.5 / November 13, 2014 |
Development status | Active |
Written in | Java, JavaScript, Groovy, Ruby, Python, Scala, Clojure |
Operating system | Cross-platform |
Platform | Java Virtual Machine |
Type | Event-driven networking |
License | Apache License version 2.0 |
Website |
vertx |
Vert.x is a polyglot event-driven application framework that runs on the Java Virtual Machine.[1][2]
Similar environments written in other programming languages include Node.js for JavaScript, Twisted for Python, Perl Object Environment for Perl, libevent for C and EventMachine for Ruby.
As of version 2.1.4, Vert.x exposes its API in Java, JavaScript, Groovy, Ruby, Python, Scala, Clojure and Ceylon.
History
Vert.x was started by Tim Fox in 2011 while he was employed by VMware. In December 2012, after he left their employment, VMware served legal papers on Tim Fox to assert control of the Vert.x trademark, domain name, blog, Github account, and Google Group.[3] [4]
After much discussion with other parties, in January 2013, VMware was persuaded that it would be in the best interests of the Vert.x community to move the project and associated IP to the Eclipse Foundation, a neutral legal entity.[5]
In August 2013, the core Vert.x project completed its move to the Eclipse Foundation.
In May 2014, Vert.x won the award for "Most Innovative Java Technology" at the JAX Innovation awards.[6]
Architecture
Vert.x uses low level IO library Netty.[7]
The application framework includes these features:
- Polyglot. Application components can be written in Java, JavaScript, Groovy, Ruby, Python, Scala or Clojure.
- Simple concurrency model. All code is single threaded, freeing from the hassle of multi-threaded programming.
- Simple, asynchronous programming model for writing truly scalable non-blocking applications.
- Distributed event bus that spans the client and server side. The event bus even penetrates into in-browser JavaScript allowing to create so-called real-time web applications.
- Module system and public module repository, to re-use and share components.
Example
A web server serving static files could be written in JavaScript like this:
load('vertx.js') vertx.createHttpServer().requestHandler(function(req) { var file = req.path === '/' ? 'index.html' : req.path; req.response.sendFile('webroot/' + file); }).listen(8080)
in Java:
import org.vertx.java.core.Handler; import org.vertx.java.core.http.HttpServerRequest; import org.vertx.java.deploy.Verticle; public class Server extends Verticle { public void start() { vertx.createHttpServer().requestHandler(req -> { String file = req.path.equals("/") ? "index.html" : req.path; req.response.sendFile("webroot/" + file); }).listen(8080); } }
In Ruby:
require "vertx" Vertx::HttpServer.new.request_handler do |req| file = req.uri == "/" ? "index.html" : req.uri req.response.send_file "webroot/#{file}" end.listen(8080)
In Groovy:
vertx.createHttpServer().requestHandler { req -> def file = req.uri == "/" ? "index.html" : req.uri req.response.sendFile "webroot/$file" }.listen(8080)
In Python:
import vertx server = vertx.create_http_server() @server.request_handler def handle(req): filename = "index.html" if req.uri == "/" else req.uri req.response.send_file("webroot/" + filename) server.listen(8080)
In Clojure:
(ns example.server (:require [vertx.http :as http])) (-> (http/server) (http/on-request (fn [req] (let [uri (.uri req)] (-> req (http/server-response) (http/send-file (str "webroot/" (if (= "/" uri) "index.html" uri))))))) (http/listen 8080))
All cases will result in a web server serving content in a highly scalable manner. Support for Scala is now implemented but examples not shown.
Note that these examples are not fit for production use, since the server is open to path traversal attacks, more complete examples for web servers are available in the vert.x examples repository.
References
- ↑ Wait, vert.x – JVM Polyglot Alternative to Node.js, By Dio Synodinos, May 04, 2012, infoq
- ↑ Vert.x – an asynchronous, event-driven Java web framework, By Eberhard Wolff, June 20, 2012, hDeveloper
- ↑ "VMware's dealings with Vert.x founder should serve as a warning."
- ↑ "Who controls Vert.x: Red Hat, VMware, or neither?"
- ↑ "Vert.x Joining Eclipse Foundation"
- ↑ "Vert.x wins JAX innovation award"
- ↑ vert.x – JVM Polyglot Alternative to Node.js, By Dio Synodinos, May 04, 2012, InfoQ