SlideShare a Scribd company logo
© Copyright 2019 Pivotal Software, Inc. All rights Reserved.
Sébastien Deleuze
@sdeleuze
4 Juillet 2019
Spring Boot with Kotlin,
Kofu and Coroutines
Safe Harbor Statement
The following is intended to outline the general direction of Pivotal's offerings. It is intended for
information purposes only and may not be incorporated into any contract. Any information
regarding pre-release of Pivotal offerings, future updates or other planned modifications is subject
to ongoing evaluation by Pivotal and is subject to change. This information is provided without
warranty or any kind, express or implied, and is not a commitment to deliver any material, code, or
functionality, and should not be relied upon in making purchasing decisions regarding Pivotal's
offerings. These purchasing decisions should only be based on features currently available. The
development, release, and timing of any features or functionality described for Pivotal's offerings in
this presentation remain at the sole discretion of Pivotal. Pivotal has no obligation to update forward
looking information in this presentation.
2
2018
Coroutines
2019
Android is Kotlin first
2016
Kotlin 1.0
Kotlin on start.spring.io
Gradle Kotlin DSL
2017
Spring official Kotlin support
Android official Kotlin support
A little bit of history
The Kotlin rise continues
Why Kotlin?
Pragmatic
and elegant
(null) safety
Better signal-to-noise ratio
Make reactive easier
via Coroutines
steps to go from a typical Spring Boot
application in Java to an idiomatic Kotlin one3
Step 1 Java to Kotlin
Code
Step 2 Spring MVC
to WebFlux with Coroutines
WebFlux provides Spring MVC
programming model built on top a
reactive engine instead of Servlet
CompletableFuture
Flow.Publisher
Mono
Flux
Single / Maybe
Flowable
Spring WebFlux/Data with
Reactive Streams APIs
Application
...
Scalability
No more 1 request per thread
Neutral to latency
Streaming
Backpressure
Also outside the JVM via
R2DBC and RSocket
R2DBC
R2DBC is a reactive SPI*
for SQL drivers
* Service Provider Interface
Only depends on Reactive Streams
R2DBC SPI
Spring Data
R2DBC
PostgreSQL SQL Server H2 MySQL
...
Coroutines
Coroutines are Kotlin lightweight threads
allowing to write non-blocking code in an
imperative way
2
7
CompletableFuture
Flow.Publisher
Mono
Flux
Single / Maybe
Flowable
suspend fun
Flow
Spring WebFlux/Data with
Reactive Streams APIs
Application
How ReactiveX APIs translate to Coroutines
fun handler(): Mono<Void> suspend fun handler()
fun handler(): Mono<T> suspend fun handler(): T?
fun handler(): Flux<T> fun handler(): Flow<T>
interface WeatherService {
fun fetchWeather(location: String): Mono<Weather>
}
val location = "Lyon, France"
mainService.fetchWeather(location)
.timeout(Duration.ofSeconds(2))
.doOnError { logger.error(it.message) }
.onErrorResume { backupService.fetchWeather(location) }
.map { String.format("Weather in %s is %s", it.location, it.description) }
.subscribe { logger.info(it) }
interface WeatherService {
suspend fun fetchWeather(location: String): Weather
}
val location = "Lyon, France"
val weather = try {
withTimeout(2000L) {
mainService.fetchWeather(location)
}
} catch (ex: CancellationException) {
logger.error(ex.message)
backupService.fetchWeather(location)
}
String.format("Weather in %s is %s", weather.location, weather.description)
Reactor
declarative API
Coroutines
imperative API
Flow type introduced in Coroutines 1.2
Finite or infinite number of elements
Backpressure via suspending
functions
Operators are extension functions and
easy to implement
Code
Step 3 Annotations and
Spring Boot auto configuration to
explicit configuration via Kofu DSL
Spring Framework 5
introduced 2 Kotlin DSLs
Router DSL
router {
(accept(APPLICATION_JSON) and "/api").nest {
"/admin".nest {
GET("/ticket", ticketingHandler::findAll)
GET("/ticket/random", ticketingHandler::randomDraw)
GET("/favorite", favoriteHandler::findAll)
GET("/{year}/talk", talkHandler::findAdminByEventId)
}
GET("/talk/{login}", talkHandler::findOne)
GET("/{year}/talk", talkHandler::findByEventId)
"/user".nest {
GET("/", userHandler::findAll)
POST("/", userHandler::create)
GET("/{login}", userHandler::findOne)
}
}
}
Beans DSL
val myBeans = beans {
bean<Foo>()
bean<Bar>()
bean("bazBean") {
Baz().apply {
message = "Hello world"
}
}
profile("foobar") {
bean { FooBar(ref("bazBean")) }
}
bean(::myRouter)
}
class Foo
class Bar(private val foo: Foo)
class Baz(var message: String = "")
class FooBar(private val baz: Baz)
fun myRouter(foo: Foo, bar: Bar, baz: Baz) = router { ... }
Spring Fu is an incubator intended to mature
experimental features before inclusion in top-level
Spring projects (Framework, Boot, Data, etc.)
4
0
Spring Fu introduce a third DSL
Kofu
Kofu is a minimalist, efficient and explicit configuration
model for Spring Boot using a Kotlin DSL
4
3
Kofu configuration for Spring Boot
application(WebApplicationType.SERVLET) {
logging {
level = LogLevel.DEBUG
}
beans {
bean<SampleService>()
bean<SampleHandler>()
}
webMvc {
port = if (profiles.contains("test")) 8181 else 8080
router {
val handler = ref<SampleHandler>()
GET("/", handler::hello)
POST("/api", handler::json)
}
converters {
string()
jackson {
indentOutput = true
}
}
}
}
Experim
ental
Code
Kofu 0.2 is work in progress
● Spring Security DSL
● Spring Data JDBC, Redis, Cassandra, JOOQ
● Type safe configuration
Spring Framework 5.2 / Spring Boot 2.2 (September 2019)
● Official Coroutines support
● Significant throughput improvements
● Significantly faster startup
● Less memory consumption
● Data classes for configuration properties
Spring Framework 5.3 (2020)
● Out of the box GraalVM native image setup 4
6
Thanks
@sdeleuze
https://github.com/spring-projects/spring-fu

More Related Content

Similar to Spring Boot with Kotlin, Kofu and Coroutines

Marcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL WorkbenchMarcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL Workbench
Women in Technology Poland
 
Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)
Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)
Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)
jaxLondonConference
 
Pathway,I Ts Web Client Programming Manual
Pathway,I Ts Web Client Programming ManualPathway,I Ts Web Client Programming Manual
Pathway,I Ts Web Client Programming Manual
guest2dfc87
 
Odo improving the developer experience on OpenShift - hack &amp; sangria
Odo   improving the developer experience on OpenShift - hack &amp; sangriaOdo   improving the developer experience on OpenShift - hack &amp; sangria
Odo improving the developer experience on OpenShift - hack &amp; sangria
Jorge Morales
 
DevCon5 (July 2014) - Acision SDK
DevCon5 (July 2014) - Acision SDKDevCon5 (July 2014) - Acision SDK
DevCon5 (July 2014) - Acision SDK
Crocodile WebRTC SDK and Cloud Signalling Network
 
Apic dc api deep dive
Apic dc api deep dive Apic dc api deep dive
Apic dc api deep dive
Cisco DevNet
 
Integrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere PortalIntegrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere Portal
Himanshu Mendiratta
 
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby AnandanPivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
PivotalOpenSourceHub
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js Workshop
Jimmy Guerrero
 
Kotlin server side frameworks
Kotlin server side frameworksKotlin server side frameworks
Kotlin server side frameworks
Ken Yee
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowHow to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
Daniel Zivkovic
 
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and NoteworthyJava EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Peter Pilgrim
 
JavaEE & GlassFish UG - Digital JavaEE 7 New & Noteworthy by P.Pilgrim
JavaEE & GlassFish UG - Digital JavaEE 7 New & Noteworthy by P.PilgrimJavaEE & GlassFish UG - Digital JavaEE 7 New & Noteworthy by P.Pilgrim
JavaEE & GlassFish UG - Digital JavaEE 7 New & Noteworthy by P.Pilgrim
Payara
 
Mobile Development integration tests
Mobile Development integration testsMobile Development integration tests
Mobile Development integration tests
Kenneth Poon
 
Don't screw it up! How to build durable API
Don't screw it up! How to build durable API Don't screw it up! How to build durable API
Don't screw it up! How to build durable API
Alessandro Cinelli (cirpo)
 
EF Core (RC2)
EF Core (RC2)EF Core (RC2)
EF Core (RC2)
Ido Flatow
 
Spring framework 5: New Core and Reactive features
Spring framework 5: New Core and Reactive featuresSpring framework 5: New Core and Reactive features
Spring framework 5: New Core and Reactive features
Aliaksei Zhynhiarouski
 
IBM Connect 2014 - AD205: Creating State-of-the-Art Web Applications with Dom...
IBM Connect 2014 - AD205: Creating State-of-the-Art Web Applications with Dom...IBM Connect 2014 - AD205: Creating State-of-the-Art Web Applications with Dom...
IBM Connect 2014 - AD205: Creating State-of-the-Art Web Applications with Dom...
Dave Delay
 
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsugFrom Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
Toshiaki Maki
 
Preparing for Growth - Architecting Giant Apps for Scalability and Build Speed
Preparing for Growth - Architecting Giant Apps for Scalability and Build SpeedPreparing for Growth - Architecting Giant Apps for Scalability and Build Speed
Preparing for Growth - Architecting Giant Apps for Scalability and Build Speed
Bruno Rocha
 

Similar to Spring Boot with Kotlin, Kofu and Coroutines (20)

Marcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL WorkbenchMarcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL Workbench
 
Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)
Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)
Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)
 
Pathway,I Ts Web Client Programming Manual
Pathway,I Ts Web Client Programming ManualPathway,I Ts Web Client Programming Manual
Pathway,I Ts Web Client Programming Manual
 
Odo improving the developer experience on OpenShift - hack &amp; sangria
Odo   improving the developer experience on OpenShift - hack &amp; sangriaOdo   improving the developer experience on OpenShift - hack &amp; sangria
Odo improving the developer experience on OpenShift - hack &amp; sangria
 
DevCon5 (July 2014) - Acision SDK
DevCon5 (July 2014) - Acision SDKDevCon5 (July 2014) - Acision SDK
DevCon5 (July 2014) - Acision SDK
 
Apic dc api deep dive
Apic dc api deep dive Apic dc api deep dive
Apic dc api deep dive
 
Integrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere PortalIntegrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere Portal
 
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby AnandanPivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js Workshop
 
Kotlin server side frameworks
Kotlin server side frameworksKotlin server side frameworks
Kotlin server side frameworks
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowHow to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
 
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and NoteworthyJava EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
 
JavaEE & GlassFish UG - Digital JavaEE 7 New & Noteworthy by P.Pilgrim
JavaEE & GlassFish UG - Digital JavaEE 7 New & Noteworthy by P.PilgrimJavaEE & GlassFish UG - Digital JavaEE 7 New & Noteworthy by P.Pilgrim
JavaEE & GlassFish UG - Digital JavaEE 7 New & Noteworthy by P.Pilgrim
 
Mobile Development integration tests
Mobile Development integration testsMobile Development integration tests
Mobile Development integration tests
 
Don't screw it up! How to build durable API
Don't screw it up! How to build durable API Don't screw it up! How to build durable API
Don't screw it up! How to build durable API
 
EF Core (RC2)
EF Core (RC2)EF Core (RC2)
EF Core (RC2)
 
Spring framework 5: New Core and Reactive features
Spring framework 5: New Core and Reactive featuresSpring framework 5: New Core and Reactive features
Spring framework 5: New Core and Reactive features
 
IBM Connect 2014 - AD205: Creating State-of-the-Art Web Applications with Dom...
IBM Connect 2014 - AD205: Creating State-of-the-Art Web Applications with Dom...IBM Connect 2014 - AD205: Creating State-of-the-Art Web Applications with Dom...
IBM Connect 2014 - AD205: Creating State-of-the-Art Web Applications with Dom...
 
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsugFrom Spring Boot 2.2 to Spring Boot 2.3 #jsug
From Spring Boot 2.2 to Spring Boot 2.3 #jsug
 
Preparing for Growth - Architecting Giant Apps for Scalability and Build Speed
Preparing for Growth - Architecting Giant Apps for Scalability and Build SpeedPreparing for Growth - Architecting Giant Apps for Scalability and Build Speed
Preparing for Growth - Architecting Giant Apps for Scalability and Build Speed
 

More from VMware Tanzu

Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
VMware Tanzu
 
What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About It
VMware Tanzu
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023
VMware Tanzu
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at Scale
VMware Tanzu
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023
VMware Tanzu
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a Product
VMware Tanzu
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
VMware Tanzu
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
VMware Tanzu
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
VMware Tanzu
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
VMware Tanzu
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - French
VMware Tanzu
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - English
VMware Tanzu
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
VMware Tanzu
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
VMware Tanzu
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
VMware Tanzu
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software Engineer
VMware Tanzu
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs Practice
VMware Tanzu
 

More from VMware Tanzu (20)

Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
 
What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About It
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at Scale
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a Product
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - French
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - English
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software Engineer
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs Practice
 

Recently uploaded

Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 

Recently uploaded (20)

Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 

Spring Boot with Kotlin, Kofu and Coroutines

  • 1. © Copyright 2019 Pivotal Software, Inc. All rights Reserved. Sébastien Deleuze @sdeleuze 4 Juillet 2019 Spring Boot with Kotlin, Kofu and Coroutines
  • 2. Safe Harbor Statement The following is intended to outline the general direction of Pivotal's offerings. It is intended for information purposes only and may not be incorporated into any contract. Any information regarding pre-release of Pivotal offerings, future updates or other planned modifications is subject to ongoing evaluation by Pivotal and is subject to change. This information is provided without warranty or any kind, express or implied, and is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions regarding Pivotal's offerings. These purchasing decisions should only be based on features currently available. The development, release, and timing of any features or functionality described for Pivotal's offerings in this presentation remain at the sole discretion of Pivotal. Pivotal has no obligation to update forward looking information in this presentation. 2
  • 3. 2018 Coroutines 2019 Android is Kotlin first 2016 Kotlin 1.0 Kotlin on start.spring.io Gradle Kotlin DSL 2017 Spring official Kotlin support Android official Kotlin support A little bit of history
  • 4. The Kotlin rise continues
  • 10. steps to go from a typical Spring Boot application in Java to an idiomatic Kotlin one3
  • 11. Step 1 Java to Kotlin
  • 12.
  • 13.
  • 14. Code
  • 15. Step 2 Spring MVC to WebFlux with Coroutines
  • 16. WebFlux provides Spring MVC programming model built on top a reactive engine instead of Servlet
  • 17. CompletableFuture Flow.Publisher Mono Flux Single / Maybe Flowable Spring WebFlux/Data with Reactive Streams APIs Application ...
  • 18. Scalability No more 1 request per thread
  • 21. Backpressure Also outside the JVM via R2DBC and RSocket
  • 22. R2DBC
  • 23. R2DBC is a reactive SPI* for SQL drivers * Service Provider Interface
  • 24. Only depends on Reactive Streams
  • 25. R2DBC SPI Spring Data R2DBC PostgreSQL SQL Server H2 MySQL ...
  • 27. Coroutines are Kotlin lightweight threads allowing to write non-blocking code in an imperative way 2 7
  • 28. CompletableFuture Flow.Publisher Mono Flux Single / Maybe Flowable suspend fun Flow Spring WebFlux/Data with Reactive Streams APIs Application
  • 29. How ReactiveX APIs translate to Coroutines fun handler(): Mono<Void> suspend fun handler() fun handler(): Mono<T> suspend fun handler(): T? fun handler(): Flux<T> fun handler(): Flow<T>
  • 30. interface WeatherService { fun fetchWeather(location: String): Mono<Weather> } val location = "Lyon, France" mainService.fetchWeather(location) .timeout(Duration.ofSeconds(2)) .doOnError { logger.error(it.message) } .onErrorResume { backupService.fetchWeather(location) } .map { String.format("Weather in %s is %s", it.location, it.description) } .subscribe { logger.info(it) } interface WeatherService { suspend fun fetchWeather(location: String): Weather } val location = "Lyon, France" val weather = try { withTimeout(2000L) { mainService.fetchWeather(location) } } catch (ex: CancellationException) { logger.error(ex.message) backupService.fetchWeather(location) } String.format("Weather in %s is %s", weather.location, weather.description) Reactor declarative API Coroutines imperative API
  • 31. Flow type introduced in Coroutines 1.2
  • 32. Finite or infinite number of elements
  • 34. Operators are extension functions and easy to implement
  • 35. Code
  • 36. Step 3 Annotations and Spring Boot auto configuration to explicit configuration via Kofu DSL
  • 38. Router DSL router { (accept(APPLICATION_JSON) and "/api").nest { "/admin".nest { GET("/ticket", ticketingHandler::findAll) GET("/ticket/random", ticketingHandler::randomDraw) GET("/favorite", favoriteHandler::findAll) GET("/{year}/talk", talkHandler::findAdminByEventId) } GET("/talk/{login}", talkHandler::findOne) GET("/{year}/talk", talkHandler::findByEventId) "/user".nest { GET("/", userHandler::findAll) POST("/", userHandler::create) GET("/{login}", userHandler::findOne) } } }
  • 39. Beans DSL val myBeans = beans { bean<Foo>() bean<Bar>() bean("bazBean") { Baz().apply { message = "Hello world" } } profile("foobar") { bean { FooBar(ref("bazBean")) } } bean(::myRouter) } class Foo class Bar(private val foo: Foo) class Baz(var message: String = "") class FooBar(private val baz: Baz) fun myRouter(foo: Foo, bar: Bar, baz: Baz) = router { ... }
  • 40. Spring Fu is an incubator intended to mature experimental features before inclusion in top-level Spring projects (Framework, Boot, Data, etc.) 4 0
  • 41. Spring Fu introduce a third DSL
  • 42. Kofu
  • 43. Kofu is a minimalist, efficient and explicit configuration model for Spring Boot using a Kotlin DSL 4 3
  • 44. Kofu configuration for Spring Boot application(WebApplicationType.SERVLET) { logging { level = LogLevel.DEBUG } beans { bean<SampleService>() bean<SampleHandler>() } webMvc { port = if (profiles.contains("test")) 8181 else 8080 router { val handler = ref<SampleHandler>() GET("/", handler::hello) POST("/api", handler::json) } converters { string() jackson { indentOutput = true } } } } Experim ental
  • 45. Code
  • 46. Kofu 0.2 is work in progress ● Spring Security DSL ● Spring Data JDBC, Redis, Cassandra, JOOQ ● Type safe configuration Spring Framework 5.2 / Spring Boot 2.2 (September 2019) ● Official Coroutines support ● Significant throughput improvements ● Significantly faster startup ● Less memory consumption ● Data classes for configuration properties Spring Framework 5.3 (2020) ● Out of the box GraalVM native image setup 4 6