Over a million developers have joined DZone.

Dive Into Vert.X Microservices and Deploy in Production With Cloud 66

DZone's Guide to

Dive Into Vert.X Microservices and Deploy in Production With Cloud 66

Eclipse Vert.X proposes a very simple way to develop and deploy microservices in the language of your choice. Take a look at this tutorial on microservice deployment.

· Microservices Zone ·
Free Resource

Record growth in microservices is disrupting the operational landscape. Read the Global Microservices Trends report to learn more.

This blog post will explore the world of Vert.X and how you can use this awesome framework to design, build and deploy your microservices with Cloud 66.

Let get our hands dirty! The example code used in this blog post can be found on GitHub.

What Is Vert.x?

Eclipse Vert.x is event-driven and non-blocking. This means your app can handle a lot of concurrencies using a small number of kernel threads. Vert.x lets your app scale with minimal hardware.

Vert.x isn't opinionated and has a big list of components you can use in your Verticle, your service. All those cool components will speed up your development and make new microservices a breeze.

And on top of this, Vert.x support polyglot development. You can use Vert.x with multiple languages including Java, JavaScript, Groovy, Ruby, Ceylon, Scala and Kotlin.

Create Your First Microservice

A simple service called a Verticle in the Vert.x world, written in Java looks like this:


The same service using Ruby:

$vertx.create_http_server().request_handler() { |req|
    .put_header("content-type", "text/plain")
    .end("A ruby world full of gems!")

Time to run this guy.

Run It With Docker

Because we are going to focus on container-based Vert.x development using Docker, this is a Dockerfile to run the Ruby example. You can use the same Dockerfile for all the supporting programming languages. Easy.

# The base image
FROM vertx/vertx3

# Set the name of the verticle to deploy
ENV VERTICLE_NAME hello-verticle.rb

# Set the location of the vertices     
ENV VERTICLE_HOME /usr/verticles

# Run your Vertical on the default port

# Copy your verticle to the container  

# Launch the verticle                     
ENTRYPOINT ["sh", "-c"]  
CMD ["exec vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/*"]

Build the verticle:

docker build -t sample/vertx-ruby.

Run it:

docker run -t -i -p 8080:8080 sample/vertx-ruby

The port is mapped to port 8080, point your browser to http://localhost:8080 and you run your first Verticle.

Like magic!

Use the following for quick testing, no need for building a custom Docker image:

docker run -i -t -p 8080:8080 -v $PWD:/usr/verticles vertx/vertx3 vertx run main-verticle.rb -cp /usr/verticles/

If you don't want to use Docker at this stage and installed the vertxCLI tool. You also can run:

vertx run hello-verticle.rb

We are using the vertx/vertx3-exec base image ( 332MB), but you can also use the vertx/vertx3-alpine base image ( 160MB) for the same results:

docker run -i -t -p 8080:8080 -v $PWD:/usr/verticles vertx/vertx3-alpine vertx run main-verticle.rb -cp /usr/verticles/

The differences are alpine Linux is using musl libc and you need to check if the packages you are using are compatible with musl libc. Most packages are compatible.

Go small with alpine Linux.

Deploy to Production Using Cloud 66

With the Vert.X base image, it's easy to run your Verticle in production using Cloud 66.

The only thing you need is a Dockerfile in your Git repo and Cloud 66 will build your image and deploy it on any public cloud or on your own servers. The first step is to bring in your source-code and let SkyCap build your Verticle images.

Now the building is done, we can deploy it to production. Of course, we can build as manage microservices as we want and let Cloud 66 handle the builds and the deployments to any cloud (backed by Kubernetes).

We deploy our Kubernetes cluster to Digital Ocean and map our port (8080) to the outside world on port 80 and 443. Good to know, we support SSL certificates and SSL termination to secure your services.

Now we hit deploy and Cloud 66 will do all the heavy lifting and deploy your Verticle in production!

After Cloud 66 setup your infrastructure, your Verticle is running in production!

Now you can explore all the cool features Cloud 66 has to offer! And start scaling your application.

Going as Small as Possible Using Habitus

Of course, you want to reduce image size for security and fast deployment purposes. To achieve this, we need to cut out the middleman (Maven + Vert.x runtime) and go for the fat-jar deployment model.

To achieve this, we need a two-stage build pipeline, you can use Habitus. Habitus is a Build Flow Tool for Docker.

This is how our build.yml looks like:

  version: 2016-03-14 # version of the build schema.
      name: package
      dockerfile: Dockerfile.package
        - /src/target/cloud66-client-example-0.1-fat.jar
      name: cloud66-client
      dockerfile: Dockerfile.production
        - package

We have the package stage and the production stage. In the packaging stage, we use Maven to download our dependencies and pack everything in one Fat Jar. The Fat Jar artifact is copied into the smallest possible Java Runtime image to be executed in production.

This is the Dockerfile.package we use for packaging:

# our base maven image based on alpine and jdk 8
FROM maven:3.5-jdk-8-alpine

# create our src folder

# selectively add the POM file

# copy our Vertical sources 

# package the thing to generate a Fat Jar
RUN mvn package  

This is the Dockerfile.production we use for production:

# our java runtime based on alpine and jdk 8
FROM openjdk:8u92-jre-alpine

# create our app folder
WORKDIR /app  

# copy our packed Fat Jar 
COPY cloud66-client-example-0.1-fat.jar  /app/cloud66-client-example-0.1-fat.jardocker

# set the user as a non-root user
USER daemon  

# run our vertical
CMD java -jar cloud66-client-example-0.1-fat.jar  

Now we can run habitus to build our image:


After the build, you get an image named cloud66-client:latest and is ready to test locally or deploy it to production.

docker run -it cloud66-client:latest

Of course, you can use Habitus with Cloud 66. Just use the following entries in service.yml.

    git_url: http://github.com/your-nick/my-vertical.git
    git_branch: master
    use_habitus: true
    use_habitus_step: production


Vert.X is a great project to build (micro)services fast in the language of choice. Together with Docker and Cloud 66 Skycap and Cloud 66 Maestro you can deploy with speed on any cloud.

Have fun!

Learn why microservices are breaking traditional APM tools that were built for monoliths.

microservices ,deployment ,vert.x ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}