{{announcement.body}}
{{announcement.title}}

Building Microservices With Wildfly Swarm

DZone 's Guide to

Building Microservices With Wildfly Swarm

See how easy it is to build and deploy microservices with lightweight Wildfly Swarm containers.

· Microservices Zone ·
Free Resource

Wildfly 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.

Plain Text
 




x
14


 
1
<build>
2
  <plugins>
3
    <plugin>
4
      <groupId>org.wildfly.swarm</groupId>
5
      <artifactId>wildfly-swarm-plugin</artifactId>
6
      <version>2018.3.3</version>
7
      <executions>
8
        <execution>
9
          <goals><goal>package</goal></goals>
10
        </execution>
11
      </executions>
12
    </plugin>
13
  </plugins>
14
</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.

Plain Text
 




xxxxxxxxxx
1


 
1
<dependency>
2
  <groupId>org.wildfly.swarm</groupId>
3
  <artifactId>jaxrs</artifactId>
4
  <version>2018.3.3</version>
5
</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.

Plain Text
 




xxxxxxxxxx
1


 
1
mvn wildfly-swarm:run



Custom — Add an Application class to programmatically invoke and deploy containers.

Plain Text
 




xxxxxxxxxx
1


 
1
Swarm swarm = new Swarm();
2
swarm.start();
3
 
          
4
JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
5
deployment.addClass(HelloWorldResource.class);
6
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

Monitoring Docker Swarm

Docker Tutorial: Play With Docker and Docker Swarm

Topics:
containers ,microservices ,tutorial ,wildfly swarm

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}