SlideShare une entreprise Scribd logo
1  sur  94
Télécharger pour lire hors ligne
Micronaut
Deep Dive
About Me
• Graeme Rocher
• Creator of Grails and Micronaut
• Principal Engineer at Object Computing
• 2018 Oracle Groundbreaker Award Winner
• Java Champion
Agenda
Part 1 - 45 Minutes
• Introduction to Micronaut
• Why Micronaut
• Micronaut Fundamentals
• Micronaut Test
• Bean Introspection
• Dependency Injection
• Configuration Management
Agenda
Part 2 - 45 Minutes
• Micronaut AOP
• Bean Validation
• Bean Events and Listeners
• Followed by a 10 Minute Break
Agenda
Part 3 - 45 Minutes
• Micronaut HTTP Server
• Micronaut HTTP Client
• Swagger / OpenAPI
Agenda
Part 4 - 35 Minutes
• Introducing Micronaut Data
• Micronaut Data JPA
• Micronaut Data JDBC
• Micronaut & GraalVM Native Image
Part 1 - 45 Minutes
• Introduction to Micronaut
• Why Micronaut
• Micronaut Fundamentals
• Micronaut Test
• Bean Introspection
• Dependency Injection
• Configuration Management
Java's Problems for
Frameworks
• Limited Annotation API
• Type Erasure
• Slow Reflection
• Reflective Data Caches
• Classpath Scanning
• Slow Dynamic Class Loading
The Micro Reality
• Frameworks based on reflection
and annotations become fat
• But we love the programming
model and productivity so
we live with it
• Why can't we be
more efficient?
Java's Problems
• Greatly Exaggerated (Java has been
dead forever)
• Java can be Fast! (see Android and
Micronaut)
• However Most Existing Tools are
based around
• Reflection
• Runtime Proxies
• Runtime Byte Code Generation
(bytebuddy/cglib)
Why is Reflection a Problem?
• Today the JDK is OpenJDK!
• Just take a look...
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/
share/classes/java/lang/Class.java#l2471
• All Reflective data initialized on first access and held in soft
references (yes every field, method etc.)
• Won't be GC'ed until your application is low on memory!
Avoid Reflection!
• Reflection usage increases memory
usage
• Using reflection relatively slow
• Problem is most modern server-side
frameworks and specifications
are built on reflection
• Some of the Jarkarta specifications
even mandate reflection
Just Like The
Android World
• The Android Community already
solved the problem
• Ahead of Time Compilation used
extensively
• Google Dagger 2.x for DI
• Most Android Frameworks avoid
reflection to
avoid paying the memory /
performance cost
Micronaut
• A Microservices and Serverless
Focused framework (hence the
branding)
• Also a Complete Application
Framework for any type of
Application
• Dependency Injection, Aspect
Oriented Programming (AOP),
Configuration Management,
Bean Introspection and more..
With Micronaut You
Can Build
• Microservices
• Serverless Applications
• Message-Driven Applications with
Kafka/Rabbit
• CLI Applications
• Even Android Applications
• Anything with
static void main(String..args)
Micronaut History
• Development Started over 2 years
ago
• Open Sourced May 2018
• Creating waves ever since
• Inspired other frameworks to
improve
and new frameworks to be born
based on the same approach
Micronaut Current
Status
• Micronaut 1.2.5 current stable
release
• Built by the people that built Grails
• Nearly 3K Github Stars
• Used in production and delivering
real
savings in cloud spend to dozens of
organizations already
Micronaut's Solutions
Problem Solution
Limited Annotation API Precomputed AnnotationMetadata
Type Erasure Precomputed Argument Interface
Slow Reflection Eliminate Reflection
Reflective Data Caches Zero Data Caches
Classpath Scanning No Classpath Scanning
Slow Dynamic Class Loading No Dynamic Class Loaders
The Future Is
Intelligent Compilers
Smaller, Leaner Runtimes
DEMOMicronaut Project Setup
Project Setup
• The Quick Way with SDKMan! (https://sdkman.io/):
$ sdk install micronaut
## For Maven
$ mn create-app example --build maven
## For Gradle
$ mn create-app example --build gradle
• Can setup manually. CLI is just a handy helper
Micronaut Minimum Setup
• A Micronaut project is just a Java project with an additional
annotation processor
annotationProcessor "io.micronaut:micronaut-inject-java:1.2.5" // Gradle
<annotationProcessorPaths> <!-- Maven -->
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject-java</artifactId>
<version>1.2.5</version>
</path>
...
Micronaut Test
• Testing library with support for Spock and JUnit 5
https://github.com/micronaut-projects/micronaut-test
testCompile "io.micronaut.test:micronaut-test-junit5" // Gradle
<dependency> <!-- Maven -->
<groupId>io.micronaut.test</groupId>
<artifactId>micronaut-test-junit5</artifactId>
<scope>test</scope>
</dependency>
...
Micronaut Test
• Allows DI directly into your tests
• Spins up server if present
@MicronautTest
class MathServiceTest {
@Inject
MathService mathService;
@Test
void testCompute() {
final Integer result = mathService.compute(4);
Assertions.assertEquals(16,result);
}
}
DEMOMicronaut Bean Introspection
@Introspected
@Introspected
class MyBean {
private String name; //getter/setter omitted
}
• AOT Reflection-Free replacement for
java.beans.Introspector
• Set/get bean properties, create instances
• Includes AnnotationMetadata
@Introspected
BeanIntrospection<MyBean> bi =
BeanIntrospection.getIntrospection(MyBean.class);
MyBean bean = bi.instantiate();
bi.getRequiredProperty("name")
.set(bean, "Some Value");
• Read/Write bean properties without reflection
• Supports Jackson JSON marshalling without reflection
AnnotationMetadata
AnnotationMetadata metadata = BeanIntrospection.getIntrospection(MyBean.class)
.getAnnotationMetadata();
if (metadata.hasStereotype(SomeAnnotation.class)) {
// do stuff
}
• AOT Computed / Merged Annotation Replacement for
Reflection based API
• Includes knowledge of meta-annotations
AnnotationMapper
• Map the value of one annotation to another at compilation
time
class KotlinNullableMapper implements NamedAnnotationMapper {
public String getName() {
return "org.jetbrains.annotations.Nullable";
}
public List<AnnotationValue<?>> map(
AnnotationValue<Annotation> annotation,
VisitorContext visitorContext) {
return Collections.singletonList(
AnnotationValue.builder("javax.annotation.Nullable").build()
);
}
}
DEMOMicronaut Annotation Metadata
TypeElementVisitor
• Allows visiting and dynamically annotating code at
compilation time
class PathTypeElementVisitor
implements TypeElementVisitor<Path, Object> {
public void visitClass( ClassElement element,
VisitorContext context) {
element.annotate(Controller.class, builder -> {
element.stringValue(Path.class)
.ifPresent(builder::value);
});
}
}
AnnotationMetadata
Why?
• All the Nullable annotations!!!
• javax.annotation.Nullable (Java)
• org.jetbrains.annotations.
Nullable (Kotlin)
• edu.umd.cs.findbugs.
annotations.Nullable (Spotbugs)
• org.springframework.
lang.Nullable (Spring)
DEMOMicronaut Dependency Injection
Micronaut DI
@Inject MyBean myBean;
@Named("someOther") MyBean someOther;
• Supports and passes the javax.inject TCK
• Supports @PostContruct / @PreDestroy
• Completely reflection free and fast
• Constructor injection encouraged
ApplicationContext
try (ApplicationContext ctx = ApplicationContext.run()) {
MyBean myBean = ctx.getBean(MyBean.class);
}
• Entry point for running Micronaut applications
• Can be customized with ApplicationContext.build()
• Implements AutoCloseable for easy shutdown / running
bean destruction hooks
BeanDefinition
ApplicationContext ctx = ApplicationContext.run();
BeanDefinition<MyBean> definition
= ctx.getBeanDefinition(MyBean.class);
• Contains precomputed AnnotationMetadata and generic
type info
• Used by ApplicationContext to instantiate beans
BeanDefinition
• Bean definitions produced for any @Singleton
• Constructor injection used by default
• Use @Factory for beans you cannot annotate
• Compliant with javax.inject spec and TCK
@ConfigurationProperties
Type Safe Configuration
@ConfigurationProperties("example")
class ExampleConfiguration {
// getters/setters omitted
private String name;
}
ApplicationContext context = ApplicationContext.run("example.name":"Demo");
ExampleConfiguration config = context.getBean(ExampleConfiguration.class);
assert config.name == 'Demo'
@EachProperty & @EachBean
Type Safe Configuration
@EachProperty("example")
class ExampleConfiguration { ... }
ApplicationContext context = ApplicationContext.run(
"example.one.name":"Demo 1", // allows multiple grouped config
"example.two.name":"Demo 2",
);
ExampleConfiguration config = context.getBean(
ExampleConfiguration.class,
Qualifiers.byName("two") // lookup by name
);
assert config.name == 'Demo 2'
@Requires
Conditional Beans Made Easy
@Requires(property="example.enabled")
@Requires(beans=DataSource.class)
@Requires(missingBeans=Example.class)
@Singleton
class DefaultExampleBean implements Example {
...
}
ApplicationContext context = ApplicationContext.run("example.enabled":"true")
Example example = context.getBean(Example)
Part 2 - 45 Minutes
• Micronaut AOP
• Bean Validation
• Bean Events and Listeners
• 10 Minute Break
Micronaut AOP
• Designed to be reflection free
• No runtime generated proxies or
byte code generation
• Fast and efficient thanks to smaller
stack traces
• Allow for all the typical framework
use cases:
@Transactional, @Cacheable,
@Validated etc.
@Executable
@Executable
void someMethod() {
...
}
• Replacement for java.lang.reflect.Method
• Only generate method handles where needed
return beanDefinition.getRequiredMethod("someMethod")
.invoke(someBean);
@ExecutableMethodProcessor
public class ScheduledMethodProcessor
implements ExecutableMethodProcessor<Scheduled> {
public void process(BeanDefinition<?> beanDefinition,
ExecutableMethod<?, ?> method) {
// do stuff with the bean
}
}
• Processes only methods annotated by the given type
argument
• In the above case setting up a scheduled job
Micronaut AOP
Annotation Stereotypes
• @Around - Allows decorating a method by surrounding it
with new behaviour (caching, transactions etc.)
• @Introduction - Allows introducing new behaviour to
existing classes and interfaces
• @Adapter - Allows adapting a method to a Single Abstract
Method (SAM) type.
DEMOMicronaut Around Advice
@Around
@Retryable // @Retryable is annotated with @Around
void invokeMe() {
// do stuff
}
• Intercepts a method with a MethodInterceptor
• No runtime proxies (compile time proxies) or reflection
needed
• No FancyProxyFactoryBean or containers needed!
@Around
@Around
@Type(DefaultRetryInterceptor.class)
public @interface Retryable {
// annotation attributes
}
• Use @Type to specify the implementation
• At compilation Micronaut applies the AOP advise
DEMOMicronaut Introduction Advice
@Introduction
@Client("/hello") // @Client is annotated with @Introduction
public interface HelloClient {
@Get("/")
Single hello();
}
• Introduction AOP advise implements abstract behaviour
• Interfaces or abstract classes
@Introduction
@Introduction
@Type(HttpClientIntroductionAdvice.class)
@Recoverable
@Singleton
public @interface Client {
}
• @Type used again to specify implementation
• Can apply other annotations as meta annotations
DEMOMicronaut Adapter Advice
@Adapter
@Singleton
public class Application {
@EventListener
void init(StartupEvent event) {
// on startup do something
}
}
• @EventListener is a great example of adapter advice
@Adapter
@Target(ElementType.METHOD)
@Adapter(ApplicationEventListener.class)
public @interface EventListener {
}
• For every method annotated with @EventListener a new
bean that implements ApplicationEventListener is
created at compile time.
DEMOMicronaut Bean Validation
Micronaut
Validation
• Support for javax.vallidation
annotations
• Partial implementation of spec
without the parts that require
reflection
• Reuses Bean Introspections to save
memory
@Validated
import javax.validation.constraints.NotBlank;
@Singleton
public class PersonService {
public void sayHello(@NotBlank String name) {
System.out.println("Hello " + name);
}
}
• @Validated AOP advice implicitly added to any bean that
uses javax.validation.
Other Advice Types
• @Cacheable - cache operations (support for Redis, in-
memory etc.)
• @Transactional - use standard javax.transactional,
Spring's or which you want
• @Retryable - Built in retry support
• @CircuitBreaker - Circuit breaker pattern
• @Async - Makes events execute asynchronously
BREAK TIME
See you in 10 minutes
Part 3 - 45 Minutes
• Micronaut HTTP Server
• Micronaut HTTP Client
• HTTP Filters
• Swagger / OpenAPI
Micronaut Runtimes
Dependency Runtime
micronaut-http-server-netty Default Netty Server
micronaut-kafka Kafka Headless Server
micronaut-picocli PicoCLI command line app
micronaut-grpc GRPC Server
micronaut-graphql GraphQL Server
micronaut-ktor Kotlin KTOR Framework support
micronaut-function-aws-api-proxy AWS Lambda
Micronaut HTTP
Server
• Default Netty-based Reactive Server
• Support for both blocking and non-
blocking I/O
• Choose your reactive framework:
RxJava2, Reactor etc.
• Any annotation model: Micronaut,
Spring, JAX-RS (coming soon)
• Integrated Jackson with reflection-
free extensions
DEMOMicronaut HTTP Server
EmbeddedServer
try( EmbeddedServer embeddedServer
= ApplicationContext.run(EmbeddedServer.class) ) {
System.out.println(embeddedServer.getPort());
}
• The EmbeddedServer interface allows easily spinning up the
server
programmatically or in tests.
Controller Hello World
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
@Controller("/hello")
public class HelloController {
@Get(produces = MediaType.TEXT_PLAIN)
public String index() {
return "Hello World";
}
}
• Use annotations in the io.micronaut.http.annotation
package
DEMOMicronaut HTTP Client
Micronaut HTTP
Client
• Netty-Based HTTP Client
• Low-level API and declarative
compile-time client
• Uses @Introduction advice to
simplify writing clients
• Reactive, CompletableFuture and
blocking support
• Built in Service Discovery support
Client Hello World
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
@Client("/hello")
public interface HelloClient {
@Get(produces = MediaType.TEXT_PLAIN)
public String hello();
}
• Use annotations in the io.micronaut.http.annotation
package
Micronaut HTTP
Filters
• Filters can apply to server and/or
client
• Allow altering request/response
before proceeding
• Useful for adding headers,
authentication, tracing,
token propagation etc.
Micronaut Service
Discovery
• Support for Consul, Kubernetes and
Eureka
• Configuration Support for Consul,
Kubernetes, Vault,
Spring Cloud Config Server and
AWS ParameterStore
• Native Client Side Load Balancing
• Tracing with Zipkin or Jaeger
Micronaut Management
• Simply add micronaut-management
Endpoint Description
/info Basic information about the app
/health Health Check support
/loggers View and Mutate log config
/metrics Metrics with Micrometer
/env Resolved configuration
/refresh Refresh the app state
/routes View active routes
DEMOMicronaut OpenAPI
Micronaut OpenAPI Setup
• Just another annotation processor extension
annotationProcessor "io.micronaut.configuration:micronaut-openapi:1.2.2" // Gradle
<annotationProcessorPaths> <!-- Maven -->
<path>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-openapi</artifactId>
<version>1.2.2</version>
</path>
...
Micronaut OpenAPI
• Produces swagger.yml at
compilation time
• Easy to expose this static file to
Swagger UI.
• Doing the work at compilation time
== less memory consumption
• Uses Micronaut
TypeElementVisitor API
Part 4 - 35 Minutes
• Introducing Micronaut Data
• Micronaut Data JPA
• Micronaut Data JDBC
• Micronaut & GraalVM Native Image
Existing Data
Access Solutions
• Spring Data, GORM etc.
• Rely heavily on reflection and
runtime proxies
• Must compute queries at runtime
• Cost of computation grows as your
application grows
Micronaut Data
• Precomputes Queries at compilation
time
• Uses Micronaut's reflection-free AOP
• Zero runtime overhead database
access solution
• Compilation time checking
• Smaller stack traces
• JPA-QL and SQL currently supported
Hello Micronaut Data
• Each repository interface annotated with @JdbcRepository
• Can extend built in interfaces like CrudRepository
@JdbcRepository(dialect=Dialect.MYSQL)
interface PersonRepository
extends CrudRepository<Person,Long> {
Person findByName(String name);
}
CRUD Example
// Create
personRepository.save(new Person("Fred"));
// Read
Person person = personRepository.findByName("Fred");
// Update
person.updatePerson(person.getId(), "Bob");
// deleteById
person.deleteById(person.getId());
DEMOMicronaut Data
Micronaut and
GraalVM
• A New Universal Virtual Machine
from Oracle
• Features a native-image Tool
• Converts Java -> native machine
code using AOT
• Works well with Micronaut
• Startup time 20ms and Memory
Consumption 18MB!
http://www.graalvm.org
Micronaut and
GraalVM
• GraalVM is cool and a project to
keep an eye on
• Still in beta and experimental
• Micronaut optimizes for GraalVM,
but
also optimizes for regular Java (what
most people use today)
http://www.graalvm.org
DEMOMicronaut + GraalVM
Micronaut Startup and Memory
Runtime Memory Startup
JDK 11 75MB 1s
JDK 13 75MB 750ms
JDK 13 + CDS 75MB 400ms
GraalVM Substrate 15MB 21ms
The Future Is
Intelligent Compilers
Smaller, Leaner Runtimes
Summary
• Micronaut Provides an Awesome Set of Framework
Primitives
• Sacrifices Compilation Speed to Gain so Much More
• Solves Problems with Spring, Jakarta EE and Java in General
• Opens the Door to GraalVM Native
Q & A
Micronaut Deep Dive - Devoxx Belgium 2019
Micronaut Deep Dive - Devoxx Belgium 2019

Contenu connexe

Tendances

Effective cloud-ready apps with MicroProfile
Effective cloud-ready apps with MicroProfileEffective cloud-ready apps with MicroProfile
Effective cloud-ready apps with MicroProfilePayara
 
JavaEE Microservices platforms
JavaEE Microservices platformsJavaEE Microservices platforms
JavaEE Microservices platformsPayara
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entityToni Jara
 
Deploying Elastic Java EE Microservices in the Cloud with Docker
Deploying Elastic Java EE Microservices in the Cloud with DockerDeploying Elastic Java EE Microservices in the Cloud with Docker
Deploying Elastic Java EE Microservices in the Cloud with DockerPayara
 
Monitor Micro-service with MicroProfile metrics
Monitor Micro-service with MicroProfile metricsMonitor Micro-service with MicroProfile metrics
Monitor Micro-service with MicroProfile metricsRudy De Busscher
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudBen Wilcock
 
Secure JAX-RS
Secure JAX-RSSecure JAX-RS
Secure JAX-RSPayara
 
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012EJB 3.2 - Java EE 7 - Java One Hyderabad 2012
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012Jagadish Prasath
 
Writing Java EE microservices using WildFly Swarm
Writing Java EE microservices using WildFly SwarmWriting Java EE microservices using WildFly Swarm
Writing Java EE microservices using WildFly SwarmComsysto Reply GmbH
 
Gradual migration to MicroProfile
Gradual migration to MicroProfileGradual migration to MicroProfile
Gradual migration to MicroProfileRudy De Busscher
 
Intro to spring cloud &microservices by Eugene Hanikblum
Intro to spring cloud &microservices by Eugene HanikblumIntro to spring cloud &microservices by Eugene Hanikblum
Intro to spring cloud &microservices by Eugene HanikblumEugene Hanikblum
 
Gwt overview & getting started
Gwt overview & getting startedGwt overview & getting started
Gwt overview & getting startedBinh Bui
 
Bootstraping real world Jakarta EE/MicroProfile microservices with Maven Arch...
Bootstraping real world Jakarta EE/MicroProfile microservices with Maven Arch...Bootstraping real world Jakarta EE/MicroProfile microservices with Maven Arch...
Bootstraping real world Jakarta EE/MicroProfile microservices with Maven Arch...Víctor Leonel Orozco López
 
Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015Strannik_2013
 
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014Arun Gupta
 
Monitoring and Tuning GlassFish
Monitoring and Tuning GlassFishMonitoring and Tuning GlassFish
Monitoring and Tuning GlassFishC2B2 Consulting
 

Tendances (20)

Effective cloud-ready apps with MicroProfile
Effective cloud-ready apps with MicroProfileEffective cloud-ready apps with MicroProfile
Effective cloud-ready apps with MicroProfile
 
Javantura v4 - The power of cloud in professional services company - Ivan Krn...
Javantura v4 - The power of cloud in professional services company - Ivan Krn...Javantura v4 - The power of cloud in professional services company - Ivan Krn...
Javantura v4 - The power of cloud in professional services company - Ivan Krn...
 
Javantura v4 - Security architecture of the Java platform - Martin Toshev
Javantura v4 - Security architecture of the Java platform - Martin ToshevJavantura v4 - Security architecture of the Java platform - Martin Toshev
Javantura v4 - Security architecture of the Java platform - Martin Toshev
 
JavaEE Microservices platforms
JavaEE Microservices platformsJavaEE Microservices platforms
JavaEE Microservices platforms
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
 
Deploying Elastic Java EE Microservices in the Cloud with Docker
Deploying Elastic Java EE Microservices in the Cloud with DockerDeploying Elastic Java EE Microservices in the Cloud with Docker
Deploying Elastic Java EE Microservices in the Cloud with Docker
 
Monitor Micro-service with MicroProfile metrics
Monitor Micro-service with MicroProfile metricsMonitor Micro-service with MicroProfile metrics
Monitor Micro-service with MicroProfile metrics
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloud
 
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip KovačekJavantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
Javantura v4 - Spring Boot and JavaFX - can they play together - Josip Kovaček
 
Secure JAX-RS
Secure JAX-RSSecure JAX-RS
Secure JAX-RS
 
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012EJB 3.2 - Java EE 7 - Java One Hyderabad 2012
EJB 3.2 - Java EE 7 - Java One Hyderabad 2012
 
Writing Java EE microservices using WildFly Swarm
Writing Java EE microservices using WildFly SwarmWriting Java EE microservices using WildFly Swarm
Writing Java EE microservices using WildFly Swarm
 
Javantura v4 - FreeMarker in Spring web - Marin Kalapać
Javantura v4 - FreeMarker in Spring web - Marin KalapaćJavantura v4 - FreeMarker in Spring web - Marin Kalapać
Javantura v4 - FreeMarker in Spring web - Marin Kalapać
 
Gradual migration to MicroProfile
Gradual migration to MicroProfileGradual migration to MicroProfile
Gradual migration to MicroProfile
 
Intro to spring cloud &microservices by Eugene Hanikblum
Intro to spring cloud &microservices by Eugene HanikblumIntro to spring cloud &microservices by Eugene Hanikblum
Intro to spring cloud &microservices by Eugene Hanikblum
 
Gwt overview & getting started
Gwt overview & getting startedGwt overview & getting started
Gwt overview & getting started
 
Bootstraping real world Jakarta EE/MicroProfile microservices with Maven Arch...
Bootstraping real world Jakarta EE/MicroProfile microservices with Maven Arch...Bootstraping real world Jakarta EE/MicroProfile microservices with Maven Arch...
Bootstraping real world Jakarta EE/MicroProfile microservices with Maven Arch...
 
Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015
 
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
 
Monitoring and Tuning GlassFish
Monitoring and Tuning GlassFishMonitoring and Tuning GlassFish
Monitoring and Tuning GlassFish
 

Similaire à Micronaut Deep Dive - Devoxx Belgium 2019

GeeCon Prague 2023 - Unleash the power of your applications with Micronaut®, ...
GeeCon Prague 2023 - Unleash the power of your applications with Micronaut®, ...GeeCon Prague 2023 - Unleash the power of your applications with Micronaut®, ...
GeeCon Prague 2023 - Unleash the power of your applications with Micronaut®, ...Juarez Junior
 
SevillaJUG - Unleash the power of your applications with Micronaut® ,GraalVM...
SevillaJUG - Unleash the power of your applications with Micronaut®  ,GraalVM...SevillaJUG - Unleash the power of your applications with Micronaut®  ,GraalVM...
SevillaJUG - Unleash the power of your applications with Micronaut® ,GraalVM...Juarez Junior
 
Grails 4 and Micronaut at Devnexus 2019
Grails 4 and Micronaut at Devnexus 2019Grails 4 and Micronaut at Devnexus 2019
Grails 4 and Micronaut at Devnexus 2019graemerocher
 
Byte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in JavaByte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in JavaAlex Moskvin
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=HibernateJay Shah
 
Overview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUGOverview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUGMarakana Inc.
 
JBCN_Testing_With_Containers
JBCN_Testing_With_ContainersJBCN_Testing_With_Containers
JBCN_Testing_With_ContainersGrace Jansen
 
JLove - Replicating production on your laptop using the magic of containers
JLove - Replicating production on your laptop using the magic of containersJLove - Replicating production on your laptop using the magic of containers
JLove - Replicating production on your laptop using the magic of containersGrace Jansen
 
Grails 3.0 Preview
Grails 3.0 PreviewGrails 3.0 Preview
Grails 3.0 Previewgraemerocher
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction Hitesh-Java
 
JDK Tools For Performance Diagnostics
JDK Tools For Performance DiagnosticsJDK Tools For Performance Diagnostics
JDK Tools For Performance DiagnosticsBaruch Sadogursky
 
JakartaOne Livestream CN4J: Eclipse MicroProfile - Your Cloud-Native Companion
JakartaOne Livestream CN4J: Eclipse MicroProfile - Your Cloud-Native CompanionJakartaOne Livestream CN4J: Eclipse MicroProfile - Your Cloud-Native Companion
JakartaOne Livestream CN4J: Eclipse MicroProfile - Your Cloud-Native CompanionJakarta_EE
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionPawanMM
 
How to push to production a project with 100+ plugins in less than 10 minutes
How to push to production a project with 100+ plugins in less than 10 minutes How to push to production a project with 100+ plugins in less than 10 minutes
How to push to production a project with 100+ plugins in less than 10 minutes Thiago Leão Moreira
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 
ADDRESSING TOMORROW'S SECURITY REQUIREMENTS IN ENTERPRISE APPLICATIONS
ADDRESSING TOMORROW'S SECURITY REQUIREMENTS IN ENTERPRISE APPLICATIONSADDRESSING TOMORROW'S SECURITY REQUIREMENTS IN ENTERPRISE APPLICATIONS
ADDRESSING TOMORROW'S SECURITY REQUIREMENTS IN ENTERPRISE APPLICATIONSelliando dias
 
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-JupiterToolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-JupiterBoni García
 

Similaire à Micronaut Deep Dive - Devoxx Belgium 2019 (20)

GeeCon Prague 2023 - Unleash the power of your applications with Micronaut®, ...
GeeCon Prague 2023 - Unleash the power of your applications with Micronaut®, ...GeeCon Prague 2023 - Unleash the power of your applications with Micronaut®, ...
GeeCon Prague 2023 - Unleash the power of your applications with Micronaut®, ...
 
SevillaJUG - Unleash the power of your applications with Micronaut® ,GraalVM...
SevillaJUG - Unleash the power of your applications with Micronaut®  ,GraalVM...SevillaJUG - Unleash the power of your applications with Micronaut®  ,GraalVM...
SevillaJUG - Unleash the power of your applications with Micronaut® ,GraalVM...
 
Grails 4 and Micronaut at Devnexus 2019
Grails 4 and Micronaut at Devnexus 2019Grails 4 and Micronaut at Devnexus 2019
Grails 4 and Micronaut at Devnexus 2019
 
Byte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in JavaByte code manipulation and instrumentalization in Java
Byte code manipulation and instrumentalization in Java
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=Hibernate
 
Protractor survival guide
Protractor survival guideProtractor survival guide
Protractor survival guide
 
Overview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUGOverview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUG
 
JBCN_Testing_With_Containers
JBCN_Testing_With_ContainersJBCN_Testing_With_Containers
JBCN_Testing_With_Containers
 
JLove - Replicating production on your laptop using the magic of containers
JLove - Replicating production on your laptop using the magic of containersJLove - Replicating production on your laptop using the magic of containers
JLove - Replicating production on your laptop using the magic of containers
 
Grails 3.0 Preview
Grails 3.0 PreviewGrails 3.0 Preview
Grails 3.0 Preview
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 
JDK Tools For Performance Diagnostics
JDK Tools For Performance DiagnosticsJDK Tools For Performance Diagnostics
JDK Tools For Performance Diagnostics
 
JakartaOne Livestream CN4J: Eclipse MicroProfile - Your Cloud-Native Companion
JakartaOne Livestream CN4J: Eclipse MicroProfile - Your Cloud-Native CompanionJakartaOne Livestream CN4J: Eclipse MicroProfile - Your Cloud-Native Companion
JakartaOne Livestream CN4J: Eclipse MicroProfile - Your Cloud-Native Companion
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 Introduction
 
How to push to production a project with 100+ plugins in less than 10 minutes
How to push to production a project with 100+ plugins in less than 10 minutes How to push to production a project with 100+ plugins in less than 10 minutes
How to push to production a project with 100+ plugins in less than 10 minutes
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
JSF2
JSF2JSF2
JSF2
 
ADDRESSING TOMORROW'S SECURITY REQUIREMENTS IN ENTERPRISE APPLICATIONS
ADDRESSING TOMORROW'S SECURITY REQUIREMENTS IN ENTERPRISE APPLICATIONSADDRESSING TOMORROW'S SECURITY REQUIREMENTS IN ENTERPRISE APPLICATIONS
ADDRESSING TOMORROW'S SECURITY REQUIREMENTS IN ENTERPRISE APPLICATIONS
 
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-JupiterToolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
 
Story ofcorespring infodeck
Story ofcorespring infodeckStory ofcorespring infodeck
Story ofcorespring infodeck
 

Dernier

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Dernier (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Micronaut Deep Dive - Devoxx Belgium 2019

  • 2. About Me • Graeme Rocher • Creator of Grails and Micronaut • Principal Engineer at Object Computing • 2018 Oracle Groundbreaker Award Winner • Java Champion
  • 3. Agenda Part 1 - 45 Minutes • Introduction to Micronaut • Why Micronaut • Micronaut Fundamentals • Micronaut Test • Bean Introspection • Dependency Injection • Configuration Management
  • 4. Agenda Part 2 - 45 Minutes • Micronaut AOP • Bean Validation • Bean Events and Listeners • Followed by a 10 Minute Break
  • 5. Agenda Part 3 - 45 Minutes • Micronaut HTTP Server • Micronaut HTTP Client • Swagger / OpenAPI
  • 6. Agenda Part 4 - 35 Minutes • Introducing Micronaut Data • Micronaut Data JPA • Micronaut Data JDBC • Micronaut & GraalVM Native Image
  • 7. Part 1 - 45 Minutes • Introduction to Micronaut • Why Micronaut • Micronaut Fundamentals • Micronaut Test • Bean Introspection • Dependency Injection • Configuration Management
  • 8. Java's Problems for Frameworks • Limited Annotation API • Type Erasure • Slow Reflection • Reflective Data Caches • Classpath Scanning • Slow Dynamic Class Loading
  • 9.
  • 10.
  • 11. The Micro Reality • Frameworks based on reflection and annotations become fat • But we love the programming model and productivity so we live with it • Why can't we be more efficient?
  • 12. Java's Problems • Greatly Exaggerated (Java has been dead forever) • Java can be Fast! (see Android and Micronaut) • However Most Existing Tools are based around • Reflection • Runtime Proxies • Runtime Byte Code Generation (bytebuddy/cglib)
  • 13. Why is Reflection a Problem? • Today the JDK is OpenJDK! • Just take a look... http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/ share/classes/java/lang/Class.java#l2471 • All Reflective data initialized on first access and held in soft references (yes every field, method etc.) • Won't be GC'ed until your application is low on memory!
  • 14. Avoid Reflection! • Reflection usage increases memory usage • Using reflection relatively slow • Problem is most modern server-side frameworks and specifications are built on reflection • Some of the Jarkarta specifications even mandate reflection
  • 15. Just Like The Android World • The Android Community already solved the problem • Ahead of Time Compilation used extensively • Google Dagger 2.x for DI • Most Android Frameworks avoid reflection to avoid paying the memory / performance cost
  • 16.
  • 17. Micronaut • A Microservices and Serverless Focused framework (hence the branding) • Also a Complete Application Framework for any type of Application • Dependency Injection, Aspect Oriented Programming (AOP), Configuration Management, Bean Introspection and more..
  • 18. With Micronaut You Can Build • Microservices • Serverless Applications • Message-Driven Applications with Kafka/Rabbit • CLI Applications • Even Android Applications • Anything with static void main(String..args)
  • 19. Micronaut History • Development Started over 2 years ago • Open Sourced May 2018 • Creating waves ever since • Inspired other frameworks to improve and new frameworks to be born based on the same approach
  • 20. Micronaut Current Status • Micronaut 1.2.5 current stable release • Built by the people that built Grails • Nearly 3K Github Stars • Used in production and delivering real savings in cloud spend to dozens of organizations already
  • 21.
  • 22. Micronaut's Solutions Problem Solution Limited Annotation API Precomputed AnnotationMetadata Type Erasure Precomputed Argument Interface Slow Reflection Eliminate Reflection Reflective Data Caches Zero Data Caches Classpath Scanning No Classpath Scanning Slow Dynamic Class Loading No Dynamic Class Loaders
  • 23. The Future Is Intelligent Compilers Smaller, Leaner Runtimes
  • 25. Project Setup • The Quick Way with SDKMan! (https://sdkman.io/): $ sdk install micronaut ## For Maven $ mn create-app example --build maven ## For Gradle $ mn create-app example --build gradle • Can setup manually. CLI is just a handy helper
  • 26. Micronaut Minimum Setup • A Micronaut project is just a Java project with an additional annotation processor annotationProcessor "io.micronaut:micronaut-inject-java:1.2.5" // Gradle <annotationProcessorPaths> <!-- Maven --> <path> <groupId>io.micronaut</groupId> <artifactId>micronaut-inject-java</artifactId> <version>1.2.5</version> </path> ...
  • 27.
  • 28. Micronaut Test • Testing library with support for Spock and JUnit 5 https://github.com/micronaut-projects/micronaut-test testCompile "io.micronaut.test:micronaut-test-junit5" // Gradle <dependency> <!-- Maven --> <groupId>io.micronaut.test</groupId> <artifactId>micronaut-test-junit5</artifactId> <scope>test</scope> </dependency> ...
  • 29. Micronaut Test • Allows DI directly into your tests • Spins up server if present @MicronautTest class MathServiceTest { @Inject MathService mathService; @Test void testCompute() { final Integer result = mathService.compute(4); Assertions.assertEquals(16,result); } }
  • 31. @Introspected @Introspected class MyBean { private String name; //getter/setter omitted } • AOT Reflection-Free replacement for java.beans.Introspector • Set/get bean properties, create instances • Includes AnnotationMetadata
  • 32. @Introspected BeanIntrospection<MyBean> bi = BeanIntrospection.getIntrospection(MyBean.class); MyBean bean = bi.instantiate(); bi.getRequiredProperty("name") .set(bean, "Some Value"); • Read/Write bean properties without reflection • Supports Jackson JSON marshalling without reflection
  • 33. AnnotationMetadata AnnotationMetadata metadata = BeanIntrospection.getIntrospection(MyBean.class) .getAnnotationMetadata(); if (metadata.hasStereotype(SomeAnnotation.class)) { // do stuff } • AOT Computed / Merged Annotation Replacement for Reflection based API • Includes knowledge of meta-annotations
  • 34. AnnotationMapper • Map the value of one annotation to another at compilation time class KotlinNullableMapper implements NamedAnnotationMapper { public String getName() { return "org.jetbrains.annotations.Nullable"; } public List<AnnotationValue<?>> map( AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { return Collections.singletonList( AnnotationValue.builder("javax.annotation.Nullable").build() ); } }
  • 36. TypeElementVisitor • Allows visiting and dynamically annotating code at compilation time class PathTypeElementVisitor implements TypeElementVisitor<Path, Object> { public void visitClass( ClassElement element, VisitorContext context) { element.annotate(Controller.class, builder -> { element.stringValue(Path.class) .ifPresent(builder::value); }); } }
  • 37. AnnotationMetadata Why? • All the Nullable annotations!!! • javax.annotation.Nullable (Java) • org.jetbrains.annotations. Nullable (Kotlin) • edu.umd.cs.findbugs. annotations.Nullable (Spotbugs) • org.springframework. lang.Nullable (Spring)
  • 39. Micronaut DI @Inject MyBean myBean; @Named("someOther") MyBean someOther; • Supports and passes the javax.inject TCK • Supports @PostContruct / @PreDestroy • Completely reflection free and fast • Constructor injection encouraged
  • 40. ApplicationContext try (ApplicationContext ctx = ApplicationContext.run()) { MyBean myBean = ctx.getBean(MyBean.class); } • Entry point for running Micronaut applications • Can be customized with ApplicationContext.build() • Implements AutoCloseable for easy shutdown / running bean destruction hooks
  • 41. BeanDefinition ApplicationContext ctx = ApplicationContext.run(); BeanDefinition<MyBean> definition = ctx.getBeanDefinition(MyBean.class); • Contains precomputed AnnotationMetadata and generic type info • Used by ApplicationContext to instantiate beans
  • 42. BeanDefinition • Bean definitions produced for any @Singleton • Constructor injection used by default • Use @Factory for beans you cannot annotate • Compliant with javax.inject spec and TCK
  • 43. @ConfigurationProperties Type Safe Configuration @ConfigurationProperties("example") class ExampleConfiguration { // getters/setters omitted private String name; } ApplicationContext context = ApplicationContext.run("example.name":"Demo"); ExampleConfiguration config = context.getBean(ExampleConfiguration.class); assert config.name == 'Demo'
  • 44. @EachProperty & @EachBean Type Safe Configuration @EachProperty("example") class ExampleConfiguration { ... } ApplicationContext context = ApplicationContext.run( "example.one.name":"Demo 1", // allows multiple grouped config "example.two.name":"Demo 2", ); ExampleConfiguration config = context.getBean( ExampleConfiguration.class, Qualifiers.byName("two") // lookup by name ); assert config.name == 'Demo 2'
  • 45. @Requires Conditional Beans Made Easy @Requires(property="example.enabled") @Requires(beans=DataSource.class) @Requires(missingBeans=Example.class) @Singleton class DefaultExampleBean implements Example { ... } ApplicationContext context = ApplicationContext.run("example.enabled":"true") Example example = context.getBean(Example)
  • 46. Part 2 - 45 Minutes • Micronaut AOP • Bean Validation • Bean Events and Listeners • 10 Minute Break
  • 47. Micronaut AOP • Designed to be reflection free • No runtime generated proxies or byte code generation • Fast and efficient thanks to smaller stack traces • Allow for all the typical framework use cases: @Transactional, @Cacheable, @Validated etc.
  • 48. @Executable @Executable void someMethod() { ... } • Replacement for java.lang.reflect.Method • Only generate method handles where needed return beanDefinition.getRequiredMethod("someMethod") .invoke(someBean);
  • 49. @ExecutableMethodProcessor public class ScheduledMethodProcessor implements ExecutableMethodProcessor<Scheduled> { public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) { // do stuff with the bean } } • Processes only methods annotated by the given type argument • In the above case setting up a scheduled job
  • 50. Micronaut AOP Annotation Stereotypes • @Around - Allows decorating a method by surrounding it with new behaviour (caching, transactions etc.) • @Introduction - Allows introducing new behaviour to existing classes and interfaces • @Adapter - Allows adapting a method to a Single Abstract Method (SAM) type.
  • 52. @Around @Retryable // @Retryable is annotated with @Around void invokeMe() { // do stuff } • Intercepts a method with a MethodInterceptor • No runtime proxies (compile time proxies) or reflection needed • No FancyProxyFactoryBean or containers needed!
  • 53. @Around @Around @Type(DefaultRetryInterceptor.class) public @interface Retryable { // annotation attributes } • Use @Type to specify the implementation • At compilation Micronaut applies the AOP advise
  • 55. @Introduction @Client("/hello") // @Client is annotated with @Introduction public interface HelloClient { @Get("/") Single hello(); } • Introduction AOP advise implements abstract behaviour • Interfaces or abstract classes
  • 56. @Introduction @Introduction @Type(HttpClientIntroductionAdvice.class) @Recoverable @Singleton public @interface Client { } • @Type used again to specify implementation • Can apply other annotations as meta annotations
  • 58. @Adapter @Singleton public class Application { @EventListener void init(StartupEvent event) { // on startup do something } } • @EventListener is a great example of adapter advice
  • 59. @Adapter @Target(ElementType.METHOD) @Adapter(ApplicationEventListener.class) public @interface EventListener { } • For every method annotated with @EventListener a new bean that implements ApplicationEventListener is created at compile time.
  • 61. Micronaut Validation • Support for javax.vallidation annotations • Partial implementation of spec without the parts that require reflection • Reuses Bean Introspections to save memory
  • 62. @Validated import javax.validation.constraints.NotBlank; @Singleton public class PersonService { public void sayHello(@NotBlank String name) { System.out.println("Hello " + name); } } • @Validated AOP advice implicitly added to any bean that uses javax.validation.
  • 63. Other Advice Types • @Cacheable - cache operations (support for Redis, in- memory etc.) • @Transactional - use standard javax.transactional, Spring's or which you want • @Retryable - Built in retry support • @CircuitBreaker - Circuit breaker pattern • @Async - Makes events execute asynchronously
  • 64. BREAK TIME See you in 10 minutes
  • 65. Part 3 - 45 Minutes • Micronaut HTTP Server • Micronaut HTTP Client • HTTP Filters • Swagger / OpenAPI
  • 66. Micronaut Runtimes Dependency Runtime micronaut-http-server-netty Default Netty Server micronaut-kafka Kafka Headless Server micronaut-picocli PicoCLI command line app micronaut-grpc GRPC Server micronaut-graphql GraphQL Server micronaut-ktor Kotlin KTOR Framework support micronaut-function-aws-api-proxy AWS Lambda
  • 67. Micronaut HTTP Server • Default Netty-based Reactive Server • Support for both blocking and non- blocking I/O • Choose your reactive framework: RxJava2, Reactor etc. • Any annotation model: Micronaut, Spring, JAX-RS (coming soon) • Integrated Jackson with reflection- free extensions
  • 69. EmbeddedServer try( EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class) ) { System.out.println(embeddedServer.getPort()); } • The EmbeddedServer interface allows easily spinning up the server programmatically or in tests.
  • 70. Controller Hello World import io.micronaut.http.MediaType; import io.micronaut.http.annotation.*; @Controller("/hello") public class HelloController { @Get(produces = MediaType.TEXT_PLAIN) public String index() { return "Hello World"; } } • Use annotations in the io.micronaut.http.annotation package
  • 72. Micronaut HTTP Client • Netty-Based HTTP Client • Low-level API and declarative compile-time client • Uses @Introduction advice to simplify writing clients • Reactive, CompletableFuture and blocking support • Built in Service Discovery support
  • 73. Client Hello World import io.micronaut.http.MediaType; import io.micronaut.http.annotation.*; @Client("/hello") public interface HelloClient { @Get(produces = MediaType.TEXT_PLAIN) public String hello(); } • Use annotations in the io.micronaut.http.annotation package
  • 74. Micronaut HTTP Filters • Filters can apply to server and/or client • Allow altering request/response before proceeding • Useful for adding headers, authentication, tracing, token propagation etc.
  • 75. Micronaut Service Discovery • Support for Consul, Kubernetes and Eureka • Configuration Support for Consul, Kubernetes, Vault, Spring Cloud Config Server and AWS ParameterStore • Native Client Side Load Balancing • Tracing with Zipkin or Jaeger
  • 76. Micronaut Management • Simply add micronaut-management Endpoint Description /info Basic information about the app /health Health Check support /loggers View and Mutate log config /metrics Metrics with Micrometer /env Resolved configuration /refresh Refresh the app state /routes View active routes
  • 78. Micronaut OpenAPI Setup • Just another annotation processor extension annotationProcessor "io.micronaut.configuration:micronaut-openapi:1.2.2" // Gradle <annotationProcessorPaths> <!-- Maven --> <path> <groupId>io.micronaut.configuration</groupId> <artifactId>micronaut-openapi</artifactId> <version>1.2.2</version> </path> ...
  • 79. Micronaut OpenAPI • Produces swagger.yml at compilation time • Easy to expose this static file to Swagger UI. • Doing the work at compilation time == less memory consumption • Uses Micronaut TypeElementVisitor API
  • 80. Part 4 - 35 Minutes • Introducing Micronaut Data • Micronaut Data JPA • Micronaut Data JDBC • Micronaut & GraalVM Native Image
  • 81. Existing Data Access Solutions • Spring Data, GORM etc. • Rely heavily on reflection and runtime proxies • Must compute queries at runtime • Cost of computation grows as your application grows
  • 82. Micronaut Data • Precomputes Queries at compilation time • Uses Micronaut's reflection-free AOP • Zero runtime overhead database access solution • Compilation time checking • Smaller stack traces • JPA-QL and SQL currently supported
  • 83. Hello Micronaut Data • Each repository interface annotated with @JdbcRepository • Can extend built in interfaces like CrudRepository @JdbcRepository(dialect=Dialect.MYSQL) interface PersonRepository extends CrudRepository<Person,Long> { Person findByName(String name); }
  • 84. CRUD Example // Create personRepository.save(new Person("Fred")); // Read Person person = personRepository.findByName("Fred"); // Update person.updatePerson(person.getId(), "Bob"); // deleteById person.deleteById(person.getId());
  • 86. Micronaut and GraalVM • A New Universal Virtual Machine from Oracle • Features a native-image Tool • Converts Java -> native machine code using AOT • Works well with Micronaut • Startup time 20ms and Memory Consumption 18MB! http://www.graalvm.org
  • 87. Micronaut and GraalVM • GraalVM is cool and a project to keep an eye on • Still in beta and experimental • Micronaut optimizes for GraalVM, but also optimizes for regular Java (what most people use today) http://www.graalvm.org
  • 89. Micronaut Startup and Memory Runtime Memory Startup JDK 11 75MB 1s JDK 13 75MB 750ms JDK 13 + CDS 75MB 400ms GraalVM Substrate 15MB 21ms
  • 90. The Future Is Intelligent Compilers Smaller, Leaner Runtimes
  • 91. Summary • Micronaut Provides an Awesome Set of Framework Primitives • Sacrifices Compilation Speed to Gain so Much More • Solves Problems with Spring, Jakarta EE and Java in General • Opens the Door to GraalVM Native
  • 92. Q & A