Start with the simplest Maven example to show you how setup a simple Vert.x project that uses
Maven. You need to have Java 8 installed and set the
JAVA_HOME environment variable to point to your Java 8
Use that as a template for setting up a Maven project with Vert.x.
Want to start right away, open the first example in Eclipse Che:
Neither Maven nor Gradle users
That’s fine too :)
You can run most of the examples at the command line using
vertx run if you have Vert.x installed (see below).
Some examples need examples-utils
You may find examples that need examples-utils. You need to build it from link:examples-utils:
git clone https://github.com/vert-x3/vertx-examples.git cd vertx-examples cd examples-utils mvn clean install
The examples demonstrate how to use all different bits of Vert.x including Vert.x core, Vert.x-Web and various other services and features.
Most of the examples have been written as verticles. For more information on verticles please consult the Vert.x core manual.
Using verticles allows you to scale and run your code from the command line more easily, but if you prefer to embed, the exact same code in the verticles can also be run embedded if you prefer. It’s really up to you. Verticles are entirely optional in Vert.x.
Most of the examples are available in all the languages that Vert.x supports.
You’ll find the examples for the relevant language in a directory
lang is an identifier for the
|All the non-Java examples are automatically generated from the Java examples using our magic code translator.|
Running the examples
Running in your IDE
Most of the Java examples can be run directly in your IDE (if you have one!).
We provide a
main() method in most of the example classes which allows you to conveniently run them directly in your IDE.
Just right click the main method or class in your IDE and run as… application (supported by all major IDEs).
Running at the command line
vertx is installed you can also run any verticle directly on the command line. This way of working may be of interest
to you if you don’t want to use Maven or Gradle or perhaps you don’t use an IDE.
Or perhaps you’re just a command line kind of person.
If you’re coming from using other platforms such as Node.js you might want to work this way. You can think of the
vertx command as a bit like the
node command in Node.js.
Instructions for installing Vert.x are in the next section.
Once Vert.x is installed, to run an example, just cd to the example directory and type
vertx run followed by the filename
of the verticle. For example
cd core-examples/src/main/java/io/vertx/example/core vertx run EchoServer.java cd core-examples/src/main/js/echo vertx run echo_server.js
Yes! You can run Java source files directly using Vert.x (no compilation required).
|This is only necessary if you want to run Vert.x at the command line. If you’d prefer to work with Maven or Gradle projects then you don’t need to pre-install Vert.x - you just let Maven/Gradle pull in the Vert.x dependencies into your project as you would with any dependency.|
Pre-requisites: You will need to have Java 8 JDK installed.
Download a Vert.x 3 distribution
Unzip it somewhere on your disk (e.g. in your home directory)
PATHenvironment variable to include the installation directory
Test the install by typing
On the download page, you will find several distributions. Each distribution has a different set of components:
Min: The min distribution contains only Vert.x Core, the support of the different languages, and the Hazelcast clustering.
Full: The full distribution contains all the components of the Vert.x stack. It includes Vert.x web and the different data access technologies.
Vert.x core examples
The Vert.x core examples contains a wide range of examples using just Vert.x Core.
Vert.x-Web is a toolkit for building web applications using Vert.x
The Vert.x-Web examples contains a wide range of examples using Vert.x-Web
Vertx unit examples
Vertx-unit is a toolkit for writing asynchronous tests. We include some examples of how to use this tool to test your Vert.x (or other asynchronous) applications.
The Vert.x Unit examples shows how to use Vert.x Unit.
The Vert.x Mail examples contains a few examples using Vert.x Mail
The mail examples show different ways to create the mail message and send it via
tls, ssl etc. The examples either use
localhost:25 to send a mail or use host
mail.example.com. To actually run the examples you will have to change the
mail server and the user credentials in the
Maven Service Factory examples
The Vert.x Maven service factory examples shows how to package a verticle that can be deployed using the Maven Service Factory. Such a deployment is also demonstrated using either the command line or the api.
Service Proxy Examples
The Vert.x Service Proxy examples contains an example of service proxy usage. It depicts how a service provider can be implemented and how the published service can be consumed.
The Vert.x OSGi examples contains a few examples using Vert.x in an OSGi context.
The Vert.x Docker examples shows how to deploy Vert.x application in Docker containers. It also contains an example of application that can be deployed on Fabric8.
Openshift & Kubernetes examples
The Vert.x OpenShift 2 example shows how to deploy Vert.x application to OpenShift 2 following the two proposed approaches: using the DIY cartridge or the vert.x 3 cartridge.
The Vert.x OpenShift 3 examples shows how to deploy Vert.x applications on Openshift 3 and Kubernetes. It also demonstrates clustering and service discovery.
The Vert.x Spring Examples shows how vert.x application can be integrated inside a Spring ecosystem.
The Vert.x Redis Example shows how you can interact with Redis using the vert.x redis client.
The Vert.x Mongo Example shows how you can interact with MongoDB using the vert.x mongo client.
The Vert.x JDBC Examples shows how you can interact JDBC Databases using the vert.x JDBC client.
AMQP Bridge examples
The Vert.x AMQP Bridge Examples show how you can interact with AMQP 1.0 servers using the Vert.x AMQP Bridge.
Camel Bridge examples
The Vert.x Camel Bridge Examples show how you can use Apache Camel routes from the event bus.
Vert.x fatjar examples
The Vert.x fatjar Examples show how you can build fatjar with Maven or Gradle.