Skip to content

Latest commit

 

History

History
338 lines (220 loc) · 6.77 KB

devnexus-2019-grails-micronaut.md

File metadata and controls

338 lines (220 loc) · 6.77 KB

theme: OCI White slidenumbers: false [.hide-footer]

original

[FIT] GRAILS 4 AND MICRONAUT

Getting the best out of Grails 4 and Micronaut


original

About Me

  • Graeme Rocher
  • Creator of Grails and Micronaut
  • Principal Engineer at Object Computing
  • Oracle Groundbreaker Award Winner

original

Agenda

  • Introduction to Micronaut
  • Introduction to Grails 4
  • Grails vs Micronaut
  • Using Micronaut Features in Grails
  • Demos

original

Micronaut for Grails Developers

  • Micronaut a Foundational Library for building applications of any type
  • Focuses on Small Memory Footprint and Speed
  • Eliminates Reflection, Runtime Proxies and Runtime Analysis

right, 35%


original

Why Micronaut?

  • Micronaut is uses no reflection, no runtime proxies, no runtime byte code generation etc.
  • Eliminating these leads to reduced memory consumption and faster startup
  • Increasingly important for Microservices, Serverless, IoT, any low-memory footprint environment

right, 35%


original

Micronaut vs Grails

Micronaut Grails
Range of Runtimes Servlet Only
General Purpose Traditional Servlet Web Apps
DI, AOP etc. Spring for DI, AOP etc.
Java, Kotlin, Groovy, GraalVM Groovy Only
Client and Server Server Only

original

Grails 4 and Micronaut

right, 35%


original

What Can/Should You Do

  • Build Configurations (Instead of Plugins)
  • Use Declarative Clients
    • HTTP
    • Kafka
    • RabbitMQ

right, 35%


original

Configurations vs Plugins

  • Consider Building Configurations instead of Plugins
  • Work with Micronaut, Spring (with micronaut-spring) and Grails
  • Plugins only work with Grails
  • ... although some things only possible with Plugins (Views, taglibs etc.)

right, 35%


original

[FIT] DEMO

Micronaut Configurations with Grails


original

Micronaut Configurations

  • Configuration with @ConfigurationProperties
  • Beans with @Singleton, @Factory etc.
  • Conditional Behaviour with @Requires
  • Customization with @Replaces

right, 35%


original

@ConfigurationProperties

Type Safe Configuration

@ConfigurationProperties("example")
class ExampleConfiguration {
	String name
}


ApplicationContext context = ApplicationContext.run("example.name":"Demo")
FooConfiguration config = context.getBean(FooConfiguration)
assert config.name == 'Demo'

original

@Requires

Conditional Beans Made Easy

@Requires(property="example.enabled")
@Requires(beans=DataSource)
@Requires(missingBeans=Example)
@Singleton
class DefaultExampleBean implements Example {
	...
}

def context = ApplicationContext.run("example.enabled":"true")
Example example = context.getBean(Example)

original

@Replaces

Easily Replace Beans by Type

@Replaces(DefaultExample)
@Singleton
class AlternativeExample implements Example {
	...
}
  • Types match much
  • Beans annotated with @Infrastructure not replaceable

original

[FIT] DEMO

Micronaut HTTP Client


original

@Client

Declarative Compile Time HTTP Clients

@Client("https://api.github.com")
@Header(name="User-Agent", value="micronaut-client")
interface GithubClient {
	@Get("/repos/{+slug}")
	Info getInfo(String slug)
}
  • Blocking or Non-Blocking (RxJava, Reactor or Future)
  • Reflection / Runtime Proxy Free

original

@Client

  • Uses Micronaut's low-level HTTP client (RxHttpClient) under the hood
  • Built with Micronaut AOP (reflection/runtime proxy free)
  • Works on GraalVM nativeimage
  • Integrates with Tracing, Metrics, Service Discovery etc.

right, 35%


original

[FIT] DEMO

Micronaut Kafka Client


original

@KafkaClient

Declarative Compile Time Kafka Clients

@KafkaClient 
public interface ProductClient {
    @Topic("my-products") 
    void sendProduct(@KafkaKey String brand, String name); 
}
  • Blocking or Non-Blocking (RxJava, Reactor or Future)

https://github.com/micronaut-projects/micronaut-kafka


original

@RabbitClient

Declarative Compile Time Kafka Clients

@RabbitClient("animals") 
interface AnimalClient {
    void send(@Header String animalType, Animal animal) 
}
  • Blocking or Non-Blocking (RxJava, Reactor or Future)

https://github.com/micronaut-projects/micronaut-rabbitmq


original

Micronaut Message Consumers

original

  • Micronaut Supports Message-Drive Microservices
  • Can be run as standalone processes (No HTTP server)
  • Use @RabbitListener for Rabbit
  • Use @KafkaListener for Kafka

https://docs.micronaut.io/1.1.x/guide/index.html#messaging

right, 35%


original

Micronaut's Clients

original

  • Compile Time
  • Reflection and Runtime Proxy Free
  • Java, Groovy or Kotlin
  • Built with Micronaut AOP

https://docs.micronaut.io/1.1.x/guide/index.html#aop

right, 35%


Summary

  • Micronaut Provides an Awesome Foundation
  • Building Blocks to Create Libraries, Configurations and Clients
  • Most Micronaut Features Available in Grails
  • Build Micronaut Libraries not Plugins

original

[FIT] Q & A


original


original