The purpose of this project is to keep the notes I take and code snippets I create while studying the Micronaut Framework.
Each directory is a sub project on it's own covering a specific use case.
Feel free to use whatever you might find useful.
Micronaut is "a modern, JVM-based, full-stack framework for building modular, easily testable microservice and serverless applications." micronaut.io. As a polyglot framework it can be used with Java, Groovy or Kotlin. Besides other IoC frameworks it features a Dependency Injection and Aspect-Oriented Programming runtime that uses no reflection. Because of it's nature it's start up time and memory consumption is not bound to the size of the codebase and gives it a monumental leap in startup time, a blazing fast throughput with a minimal memory footprint.
Micronaut apps startup in tens of milliseconds with GraalVM, a new universal virtual machine from Oracle that supports a polyglot runtime environment and the ability to compile Java applications down to native machine code.
Building reactive clients during compile-time to reduce memory consumption.
import io.micronaut.http.annotation.Get;
import io.micronaut.http.client.Client;
import io.reactivex.Single;
@Client("/hello")
public interface HelloClient {
@Get("/")
Single hello();
}
Easy to expose APIs that can be consumed by HTTP clients.
import io.micronaut.http.annotation.*;
@Controller("/hello")
public class HelloController {
@Get("/")
public String index() {
return "Hello World";
}
}
Allows to spin up servers and clients in unit test easily and run them instantaneously.
import io.micronaut.runtime.server.EmbeddedServer
import spock.lang.*
class HelloClientSpec extends Specification {
@Shared
@AutoCleanup
EmbeddedServer embeddedServer =
ApplicationContext.run(EmbeddedServer)
@Shared
HelloClient client = embeddedServer
.applicationContext
.getBean(HelloClient)
void "test hello world response"() {
expect:
client.hello().blockingGet() == "Hello World"
}
}
Provides a simple compile-time aspect-oriented programming API that does not use reflections.
@Scheduled(fixedRate = "5m")
@Retry(attempts='5')
void everyFiveMinutes() {
messageService.sendMessage("Hello World");
}
Supports any framework that implements Reactive Streams, including RxJava, and Reactor.
@Client( id = "person-service" )
public interface PersonClient {
public Single<Person>
save(@Body Single<Person>person)
}
Includes support for common discovery services, distributed tracing tools, and cloud runtimes.
With the low overhead compile-time DI and AOP it makes it perfect for writing functions for serverless environments like AWS Lambda.
@Field
@Inject
HelloService helloService
Message hello(Person person) {
helloService.hello(person)
}
import io.micronaut.retry.annotation.*
@CircuitBreaker(reset = "30s")
public List findBooks() {
...
..
}
Provides sensible defaults that automatically configure your favourite data access toolkit and APIs to make it easy to write your own integrations.
- Reactive programming
- Database access with GORM
- Service discovery
- Serverless applications
- Distributed tracing
- Cron jobs
- Circuit breaker