Spring Boot, Docker and Websockets Integration with Apache Camel

Posted: April 1st, 2015 | Author: | Filed under: Technology | Tags: , , , , | 1 Comment »

Take a deep breath as all of the requirements for the application are complete. Now lets discuss how it can be run. As previously mentioned, Spring Boot can run as a single standalone jar. However, since it is also desirable that it can be run in a web servlet container such as Tomcat, a simple modification can be made to make this possible. First, the packaging type of the Maven project must be set to war so a web archive is created as part of the project build. Next, the Application class is configured to extend the SpringBootServletInitializer class to be automatically bootstrapped by the container.

With the application now configured as a web archive, there are two ways it can be run:

  • Use the Spring Boot Maven Plugin
  • Deployment to a servlet container such as Tomcat

To use the Spring Boot Maven plugin to start the application, run the following command from the project directory:

mvn spring-boot:run

To deploy the application to Tomcat, first package the application into a web archive:

mvn clean package

Copy the resulting .war file from the target folder to the webapps folder within Tomcat

Whichever method is chosen, the application will be available at http://localhost:8080/spring-boot-docker-camel

Spring Boot Docker Camel Webpage

The top section will display events published to the websockets endpoint while the bottom section contains links to the statistics that can be invoked against Docker. Click any of the links on the bottom half of the screen and the JSON results will be returned in a new tab similar to the following.

{"ApiVersion":"1.17","Arch":"amd64","GitCommit":"a8a31ef","GoVersion":"go1.4.1","KernelVersion":"3.18.5-tinycore64","Os":"linux","Version":"1.5.0"}

To generate events in Docker which will populate the top half of the page, execute the following command:

docker run –rm busybox /bin/sh

As you can see from the output from Docker, the command created, started, stopped and finally destroyed the container.

Events produced by Docker

This application demonstrates several of the potential integration opportunities with Spring Boot, Docker, Websockets which can now be leveraged with Apache Camel.


One Comment on “Spring Boot, Docker and Websockets Integration with Apache Camel”

  1. 1 Claus Ibsen said at 11:02 am on April 3rd, 2015:

    Hi Andrew

    Really great blog. Loved reading it. And great to see your contributions to the Camel project put together into a nice microservice style app.

    Keep up the good work and see you around in the community.

    I put a link to your blog from our collection at: http://camel.apache.org/articles

    /Claus Ibsen


Leave a Reply