Vert.x

from Wikipedia, the free encyclopedia
Vert.x

Vert.x logo
Basic data

developer Tim Fox
Current  version 3.9.2
( July 15, 2020 )
operating system cross-platform
programming language Java , JavaScript , Groovy , Ruby , Ceylon , Kotlin , Scala
category Framework for reactive programming
License Apache license
vertx.io

Vert.x is an event-oriented framework for simple concurrency that runs in the Java Virtual Machine and is available in the programming languages Java , JavaScript , Groovy , Ruby , Ceylon , Kotlin and Scala with an Apache license .

Vert.x offers the following functions:

  • Polyglot. Application components can be written in Java, JavaScript, Groovy, Ruby, Ceylon, Kotlin, and Scala.
  • Simple concurrency , reactive programming .
  • Simple, asynchronous programming model for scalable, non-blocking applications.
  • Distributed event bus that connects the client side and the server side.
  • Module system and public module repository.

Similar environments for other programming languages ​​are e.g. B. Node.js for JavaScript , Twisted for Python , Perl Object Environment for Perl , libevent for C and EventMachine for Ruby .

history

Work on Vert.x was started by Tim Fox in 2011 while he was a VMware employee . In December 2012, after he left VMware, VMware claimed the Vert.x Trade Mark, Domain, Blog, GitHub account and Google Group. After some discussions, in January 2013 everyone involved agreed to move the project to the Eclipse Foundation . The move to the Eclipse Foundation was completed in August 2013. In May 2014 Vert.x won the “Most Innovative Java Technology” award from the JAX Innovation Awards.

Examples

A web server that sends the text "Hello from Vert.x!" could be written in JavaScript like this:

vertx.createHttpServer()
  .requestHandler(function (req) {
    req.response()
      .putHeader("content-type", "text/plain")
      .end("Hello from Vert.x!");
}).listen(8080);

In Java:

import io.vertx.core.AbstractVerticle;
public class Server extends AbstractVerticle {
  public void start() {
    vertx.createHttpServer().requestHandler(req -> {
      req.response()
        .putHeader("content-type", "text/plain")
        .end("Hello from Vert.x!");
    }).listen(8080);
  }
}

In Ruby:

$vertx.create_http_server().request_handler() { |req|
  req.response()
    .put_header("content-type", "text/plain")
    .end("Hello from Vert.x!")
}.listen(8080)

In Groovy:

vertx.createHttpServer().requestHandler({ req ->
  req.response()
    .putHeader("content-type", "text/plain")
    .end("Hello from Vert.x!")
}).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))

In Ceylon:

import io.vertx.ceylon.core { ... }
import io.vertx.ceylon.core.http { ... }
shared class Server() extends Verticle() {
  start() => vertx.createHttpServer()
    .requestHandler((req) =>
      req.response()
        .putHeader("content-type", "text/plain")
        .end("Hello from Vert.x!")
    ).listen(8080);
}

It is important that with these versions no checks take place, for example whether the requested file is in the root directory.

Web links

Individual evidence

  1. Release 3.9.2 . July 15, 2020 (accessed July 16, 2020).
  2. Vert.x wins JAX innovation award . jax.de
  3. In a real production web-server you would want to do some checking of the path to ensure files aren't served from outside the webroot!