Building Microservices With Micronaut
For initial development, we are leveraging a JAX-RS based microservice-starter application similar to implementation using Oracle Helidon.
Join the DZone community and get the full member experience.
Join For FreeMicronaut is a modern, JVM-based, full-stack framework for building modular, easily testable microservice and serverless applications.
For initial development, we are leveraging a JAX-RS based microservice-starter application similar to implementation using Oracle Helidon.
More about the lifecycle is explained below.
You may also like: A Quick Guide to Microservices With the Micronaut Framework
Packaging
Micronaut uses a maven shade plugin for packaging the application which put all the runtime dependencies an uber jar.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
Deployment
Micronaut supports HTTP deployment based on netty server and partial/compatible support for JAX-RS resources.
xxxxxxxxxx
<dependencies>
<dependency>
<groupId>io.micronaut.jaxrs</groupId>
<artifactId>micronaut-jaxrs-server</artifactId>
<version>1.0.0.M1</version>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-runtime</artifactId>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-server-netty</artifactId>
</dependency>
</dependencies>
In addition to these, it required additional plugins/dependencies at the compile phase to process its annotations.
xxxxxxxxxx
<annotationProcessorPaths>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject-java</artifactId>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
</path>
<path>
<groupId>io.micronaut.jaxrs</groupId>
<artifactId>micronaut-jaxrs-processor</artifactId>
</path>
</annotationProcessorPaths>
Launcher
Micronaut provides a build-in runner class that can be invoked through the main class.
xxxxxxxxxx
public class Application {
public static void main(String[] args) {
Micronaut.run(Application.class);
}
}
Which can be a trigger in multiple ways.
Dev
mvn exec:java
Prod
java - jar target/microservice-starter-micronaut.jar
The complete example can found here at microservice-starter-microanaut.
Further Reading
Opinions expressed by DZone contributors are their own.
Comments