days
-1
-3
hours
0
-8
minutes
-3
-5
seconds
-3
0
search
Lightweight and reactive

Micronaut: The future of microservices in the JVM

Sergio del Amo and Ralf D. Müller
Micronaut
© Shutterstock / Remus Vox

Designed from the ground up for microservices, Micronaut is a framework for lightweight and reactive development on the JVM. In this article, Sergio del Amo and Ralf D. Müller explain how Micronaut’s minimal footprint can help speed up your microservices implementation.

In March, the 7th edition of Greach, a conference dedicated to Groovy and Grails ecosystem, took place in Madrid, Spain. And they had a surprise: Graeme Rocher, lead of the Grails framework team, unveiled the Micronaut framework.

Micronaut is a new JVM framework designed from the ground up to target microservices and serverless computing environments with the following goals in mind:

  • Blazing fast startup time
  • Low memory footprint
  • As small as possible JAR sizes
  • Zero dependency
  • 12 factor

With the current version of Micronaut, the smallest Hello World JAR is 8MB and can be run with as little as 10mb max heap. The resulting startup time is sub-second if used with Java.  Moreover, Micronaut’s start time and memory consumption do not grow linearly with the number of lines of code because all dependency injection, AOP and Proxy generation happens at compile time.

Micronaut is ultra-lightweight and Reactive – based on Netty – and offers both HTTP Client & Server. The next code in listing 1 shows an HTTP Server endpoint declared in Micronaut and a client whose implementation is generated at compile time.

@Controller 
class HelloController {
     @Get("/hello/{name}") 
     String hello(String name) { 
           return "Hello $name!" 
     } 
} 
// Client Generated at Compile Time 
@Client("/") 
interface HelloClient { 
     @Get("/hello/{name}") 
     String hello(String name)
} 

As you can see, the previous code listing offers a similar programming model as Spring Boot or, Grails do. Developers coming from those frameworks, looking for a framework to use in a distributed architecture, will enjoy a fast and familiar learning curve. This will enable you to easily transition from an already existing application to Micronaut.

SEE MORE: Micronaut: A lightweight framework that supports Java, Groovy and Kotlin

Moreover, Micronaut offers features specially targeted towards the Microservices / Cloud world:

  • Service Discovery
  • Circuit Breaker / Retry
  • Configuration Sharing
  • Client Side Load Balancing
  • Support for serverless computing. AWS Lambda

All those features are built in with zero additional dependency.

For example, the framework includes a @CircuitBreaker annotation which implements the Circuit Breaker pattern.

@CircuitBreaker(attempts = '5', delay = '5ms', reset = '300ms')
public List<Book> findBooks() {
    ...
} 

The previous code Listing ( Listing 2) configures 5 as the maximum number of retry attempts, with a 5 milliseconds delay between attempts and sets 300ms before resetting the circuit to half open.

The @CircuitBreaker plays well with another baked-in Micronaut’s annotation: @Fallback. An annotation which allows, you to define fallback beans and which can be used to provide an alternative for microservices experiencing downtime to override beans in a test environment.

Demo

During his talk at GreachConf, Graeme Rocher showed a demo of a “pet store” application, designed as multi-project Gradle application. The application illustrated that Micronaut microservices can be integrated easily with different persistence mechanisms such as Neo4j, Redis, Postgresql, MongoDB, talk effortlessly to third-party services such as SendGrid or AWS SES or even be deployed in server-less scenarios such as AWS Lambda. Consul was being used as a service discovery service. The microservices involved in the application could be started manually or with a single command using Docker.

The next diagram illustrates the demo application:

micronaut

Micronaut’s first milestone releases are expected for Q2 2018. The agenda for Gr8conf in Copenhagen already shows some sessions about Micronaut and it is scheduled for May 30th-June 1st. :-)

Author

Sergio del Amo and Ralf D. Müller

Sergio del Amo works in the Grails OCI team. He publishes Groovy Calamari, a weekly newsletter about the Groovy Ecosystem. He’s been developing Grails Applications for the past six years and likes how succinct and powerful Groovy is.

Ralf D. Müller works as solution architect and developer. He loves to make use of highly productive tools in order to deliver business value. He is also a great fan of AsciiDoc and Grails, committer at arc42 and founder of the docToolchain project.


Leave a Reply

Be the First to Comment!

avatar
400
  Subscribe  
Notify of