Building Microservices With Wildfly Swarm
See how easy it is to build and deploy microservices with lightweight Wildfly Swarm containers.
Join the DZone community and get the full member experience.
Join For FreeWildfly Swarm is a lightweight container for deploying apps and services using various JEE specifications. It supports the full project lifecycle using its own Maven dependency management and builds plugin.
For initial development, we are leveraging a JAX-RS based microservice-starter application similar to implementation with[out] Spring Boot.
You may also like: Building Microservices Using Spring Boot and Docker — Part 1
More about the lifecycle is explained below.
Packaging
Wildfly Swarm provides its own Maven support to package the code and it's dependencies as an Uber jar, including the container itself. For this, you need to add the following build plugin.
<build>
<plugins>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>2018.3.3</version>
<executions>
<execution>
<goals><goal>package</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Deployment
Wildfly Swarm is an embeddable container that provides support for multiple deployment options. It can deploy web, JAXRS, and EJB containers. You can add a specific fraction for deploying only the required container.
xxxxxxxxxx
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>jaxrs</artifactId>
<version>2018.3.3</version>
</dependency>
Launcher
A Wildfly Swarm container can be launched using the standard as well as customer launchers.
Standard — Just run the following Maven goal on the project.
xxxxxxxxxx
mvn wildfly-swarm:run
Custom — Add an Application class to programmatically invoke and deploy containers.
xxxxxxxxxx
Swarm swarm = new Swarm();
swarm.start();
JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
deployment.addClass(HelloWorldResource.class);
swarm.deploy(deployment);
Here we are using the ShrinkWrap API to programmatically create a deployable archive at runtime.
The complete example can found here at microservice-starter-wildflyswarm.
Further Reading
Migrate Standalone HornetQ Configuration to ActiveMQ Cluster
Opinions expressed by DZone contributors are their own.
Trending
-
Hibernate Get vs. Load
-
Does the OCP Exam Still Make Sense?
-
RBAC With API Gateway and Open Policy Agent (OPA)
-
Multi-Stream Joins With SQL
Comments