Over a million developers have joined DZone.

Implementing Microservices Using KumuluzEE

Here's a great guide to getting started with microservices on Kumuluz EE.

· Integration Zone

Learn how API management supports better integration in Achieving Enterprise Agility with Microservices and API Management, brought to you in partnership with 3scale

A lot of people in the Java ecosphere know about writing embedded microservices (without a separate container) using either Spring Boot or Dropwizard. Both have their merits but neither is completely Java EE oriented. Both reuse some Java EE component, for example Dropwizard uses JAX-RS for REST APIs and both support JPA for persistence. But if you want to use pure Java EE this becomes quite hard (although Spring Boot can be used completely in a Java EE-style).

Recently some new tools have popped up to support Java EE microservices with embedded containers, such as JBoss Swarm, Payara Micro and KumuluzEE. Today, I’ll show how to set up a simple KumuluzEE project. Bear in mind that KumuluzEE is not final and does not support all the Java EE specifications, but for most microservices it does the job.

We’re going to start off adding the necessary dependencies to our build file (Gradle).

compile 'com.kumuluz.ee:kumuluzee-core:1.0.0'      
compile 'com.kumuluz.ee:kumuluzee-servlet-jetty:1.0.0'      
compile 'com.kumuluz.ee:kumuluzee-cdi:1.0.0'      
compile 'com.kumuluz.ee:kumuluzee-jax-rs:1.0.0'      
compile 'com.kumuluz.ee:kumuluzee-bean-validation:1.0.0'    

This adds the necessary dependencies to build a basic REST based microservice.

Next, we’re adding the basic Application class needed for JAX-RS deployments.

public class TestApplication extends Application {      

This will set the root path for all the REST endpoints you’ll add. Next, we’re going to add a basic REST endpoint.

public class TestResource {                 
  public int getInt() {              
    return 42;          

To run the application, you can start it in your IDE using the EeApplication class from KumuluzEE. This class has a main method and will start up the embedded Jetty container and deploy all the EE classes. Nothing more is needed. Alternatively, you can create an uberjar or use Capsule to create a self-running JAR, using the EeApplication as the main class.

That’s all there is to it. KumuluzEE supports the CDI standard, so you can easily add any of the Deltaspike integrations. It also supports JPA out of the box. It does not support JSF or WebSockets yet, but this is to be included in the next version. However, nothing prohibit you to include for example Atmosphere to add support for WebSockets already.

While not as feature-complete as the other players out there (Dropwizard and Spring Boot), KumuluzEE is a welcome addition to the microservices platforms. Check it out here

Unleash the power of your APIs with future-proof API management - Create your account and start your free trial today, brought to you in partnership with 3scale.

java ee ,microservices ,kumuluzee

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}