Fractions

As we explained earlier, you can consider Thorntail as a runtime environment that you can build in a pluggable way. The core unit that represents the compositional aspect in Thorntail is the fraction. It's a well-defined runtime capability to add to your environment. In some cases, a fraction maps directly to a subsystem from WildFly, but in other cases, it may involve a different functionality that's described in the MicroProfile.io specifications or is needed in the cloud environment.

A fraction can do the following things:

  • Directly enable a WildFly subsystem as Infinispan, which is needed to implement a data caching layer
  • Integrate additional frameworks or services (for example, topology using Consul, JGroups, and OpenShift)
  • Provide deployments of features like API documentation (for example, Swagger) or JMX metrics access (for example, Jolokia)
  • Add API dependencies as Jakarta EE (for example, JAX-RS) or MicroProfile.io (for example, config, and health check)
  • Alter deployment, introducing features as single-sign on for the authentication and authorization settings of your application (for example, Keycloak).

At the time of writing, there are about 184 fractions available that are stable and experimental, and there are more in the pipeline. About 80% wrap WildFly, related components, so you are able to use some Jakarta EE specifications, and you can easily evolve your application from a monolithic to a microservice architecture.

Fractions support explicit and implicit configuration; in many cases, you won't need to configure anything. The default values will let you successfully run your application.

Fractions can be detected or explicitly declared. The simplest case is a WAR project, with just the Maven plugin. After enabling the thorntail-maven-plugin inside your application, Thorntail will detect which APIs you use, and will include the fractions that implement them at build time. The default behavior of thorntail-maven-plugin is to auto detect fractions only if you do not specify anything explicitly. You can change this setting through the fractionDetectMode property.

To implement the auto detection mode, you should implement the following steps:

  1. Add the thorntail-maven-plugin to your pom.xml in a <plugin> block, with an <execution> specifying the package goal:
<plugins>
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>${version.thorntail}</version>
<executions>
<execution>
<id>package</id>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

  1. Specify the API that you want to use in your pom.xml file; for example, JAX-RS, to implement a RESTful web service, as follows:
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${version.jaxrs-api}</version>
<scope>provided</scope>
</dependency>
</dependencies>
  1. Build your project using the following command:
$ mvn package   
  1. Run the final, atomic Uber JARusing the following command:
$ java -jar ./target/myapp-thorntail.jar   

To use the explicit fractions, setting a specific version, you should implement the following steps:

  1. Set the correct Bill Of Material (BOM) of the Thorntail version, as follows:
# Set the property relate to the Thorntail version
<properties>
<version.thorntail>2.0.0.Final</version.thorntail>
</properties>
...
  1. Set the BOM dependency in order to have the correct version of the fraction:
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>bom</artifactId>
<version>${version.thorntail}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
  1. Add the thorntail-maven-plugin to your pom.xml in a <plugin> block, with an <execution> specifying the package goal:
<plugins>
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>${version.thorntail}</version>
<executions>
<execution>
<id>package</id>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
  1. Add the dependency on the Thorntail fraction, for example, JAX-RS, to implement a RESTful web service, to the pom.xml file:
<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jaxrs</artifactId>
</dependency>
</dependencies>
  1. Build your project, using the following command:
$ mvn package  
  1. Run the final, atomic Uber JARusing the following command:
$ java -jar   ./target/myapp-thorntail.jar  
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset