Over a million developers have joined DZone.
{{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

The new Gartner Critical Capabilities report explains how APIs and microservices enable digital leaders to deliver better B2B, open banking and mobile projects.

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 build plugin.

For initial development, we are leveraging a JAX-RS based microservice-starter application. 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.

<dependency>
  <groupId>org.wildfly.swarm</groupId>
  <artifactId>jaxrs</artifactId>
  <version>2018.3.3</version>
</dependency>

Launcher

A Wildfly Swarm container can be launched using standard as well as customer launchers.

  • Standard - Just run the following Maven goal on the project.
mvn wildfly-swarm:run
  • Custom - Add an Application class to programmatically invoke and deploy containers.
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.

The new Gartner Critical Capabilities for Full Lifecycle API Management report shows how CA Technologies helps digital leaders with their B2B, open banking, and mobile initiatives. Get your copy from CA Technologies.

Topics:
wildfly swarm ,microservices ,containers ,tutorial

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}