Nobody working in software development will have escaped the buzz around Microservices in the last 12 - 18 months. Various frameworks have appeared for Java, one of the most popular being Spring Boot.
Spring Boot takes an approach of enabling developers to pick and choose which components they need for their app via ‘starter’ dependencies, and then packaging everthing into a runnable ‘fat’ JAR (or WAR if need be). This is advantagous for build and deployment via CI / CD pipelines into containerised platforms.
So what tools exist to achieve similar things with JavaEE? Enter WildFly Swarm. WildFly Swarm builds on top of the WildFly container and lets you ‘rightsize’ your JavaEE apps by giving you the option to pick and choose what components of the app server you want to include. In a classic WildFly JavaEE app server installation you’ll have the some (or more) of following subsystems available:
In a Microservice, you may not need all of these services, so it makes little sense to include them within the packaged application. WildFly Swarm deals with this problem via fractions. So if I need Jolokia, I simply include the Jolokia fraction dependency. If I need to use REST via JAX-RS, then I include the Swarm JAX-RS fraction. WildFly broken down into small discrete functional pieces!
WildFly Swarm Camel applications
Recently, the WildFly Camel subsystem has been incorporated into WildFly Swarm via its own set of fractions. Thus far the following fractions are available:
camel-other is an unforntuately named ‘catch all’ bucket for components that are not featured in the above list. Over time the plan is to have individual fractions for each supported Camel component.
Example Camel WildFly Swarm application
This example demonstrates using the Camel CDI and Undertow compoments on WildFly Swarm.
WildFly Swarm generator
Let’s start by making life easy for ourselves and auto-generate a basic project structure. Head over to http://wildfly-swarm.io/generator/ and fill in your group / artifact IDs. Next, select the Camel fractions that you want to work with - for this demo choose Camel CDI and Camel Undertow. Click the ‘Generate Project’ button to generate and import the skeleton project into your IDE.
Next we add a camel RouteBuilder class:
Package and run
Now package the application:
Check the target directory and you should see a JAR file named with a ‘-swarm’ suffix. This is the runnable ‘fat’ JAR.
Now run the application:
Alternatively, you can use the WildFly Swarm Maven plugin:
Now you can open a web browser and navigate to http://127.0.0.1:8080/hello?name=James. You should see a response output as ‘Hello James’.
WildFly Swarm makes it easy to develop and run JavaEE Microservice applications. Camel is already well placed to take advantage of Microservice architectures via its comprehensive component library. This will get better and better over time.
I’ve only scratched the surface of what WildFly Swarm has to offer in this post. If you want to learn more, then check out the following links: