SlideShare une entreprise Scribd logo
1  sur  16
The choice is yours
Internal notes
Introduction
Just a few minutes ago, Phil Webb spoke to us about
changes happening in the industry and how Spring
adapts itself to those changes, by giving you choices.
Now we're going to show some of the new choices
available in Spring Framework 5, Spring Boot 2 and
Spring Data Kay combined together.
I think we have seen enough slides now, it is about
time we do some live coding!
start.spring.io
To get started with a new project, start.spring.io is the go-to
place.
[Search usual suspects in the search box]
Did you know that you can actually do the same thing right
from your IDE?
[In the IDE, project creation]
We’re going to build a fully non-blocking, reactive web
application: The app itself is very simple, it will give you a
list of restaurants which we can filter based on some
category.
=> Start with a test
Start with a test
[Attempt to create Restaurant, firechat discussion about starting with a test]
In Spring Framework 5 we have introduced the WebTestClient. It feels similar to
using MockMvc but it is an actual client that can be used for live integration tests
against any server.
[Add @Autowired private WebTestClient webClient]
We’re building a web-application so let’s focus on testing the controller!
[Switch to @WebFluxTest]
Here we are going to use it to test our reactive controller directly, i.e. without a
running server (just like with MockMvc).
Let’s get a list of affordable sushi places, because that’s useful…
[Write test with expectStatus OK that leads to 404]
=> Repository, implementation, test is green
Repository, test implementation, test is green
We need a Restaurant type and let’s assume that the controller gets data from a
Repository
[Create Restaurant, RestaurantRepository, Inject repository in Controller]
In a reactive application, we need to return a reactive streams publisher that will give
us the data once it’s available, instead of the data itself. We will use the Flux and
Mono implementations of a RS Publisher from the Reactor project.
Let’s create a mock for the repository using @MockBean.
We can improve the test to assert the content of the response
Now we can add a GetMapping to /restaurants.
[Implement @GetMapping]
Project reactor provides us with many operators for a Flux or Mono. Think of it like
Java 8 Stream but with the ability to compose asynchronous logic without worrying
about thread
[Test is green]
Spring Data
Spring Data Kay has reactive support for Redis, MongoDB, Couchbase and
Cassandra. When you ask for data from a remote repository, you can’t be certain
that the data will come to you immediately. And with a reactive data repository, we
are not holding any threads waiting for the data to come.
For the demo we are going to use MongoDB. As usual, starters will guide you. And,
as you need to be reactive end to end, you can count on Spring Data to give you
support for that use case.
[Add starter]
The data can be a finite collection of elements or an infinite stream. You can add
operations to declare what needs to be done with the data once it comes, just like
you declare operations over Java 8 streams.
[Add @Document/@Id on domain - Change repo - Use repo in controller]
=> Start the app
Start the app
We haven’t actually started the application till now. We’ve been
using a mock repository for so long but let’s connect to an actual
mongodb instance.
We can now invoke our actual endpoint and, let’s say, find fast food
places instead
[http :8080/restaurants category==fast-food maxPrice==15]
I heard “Jack in The Flux” [Whoever is there] is really good and I
wonder if it’s available tonight.
=> WebClient
WebClient
Let's create another endpoint that provides the first three restaurants that are
available tonight. We can get the availability data from a remote service that’s
running on port 8081.
[http :8081/restaurants/Domonos/availability]
The service might not always respond as quickly, or there may be time between
individual items, but we will stream the data as it comes without any extra cost, we
will not be blocking or holding threads at any point.
[Invoke again to show the latency http :8081/restaurants/Domonos/availability]
We could use the RestTemplate to contact the service, injecting a
RestTemplateBuilder to get defaults and your customizations, if any. But that’s
not a good choice here.
=> WebClient (2)
WebClient (2)
Indeed, RestTemplate is a blocking API. we don't want to make blocking
calls from the server side where we are processing many requests
concurrently. And didn't we want to stream the data? We can't do that with
the RestTemplate. Let's use the new reactive, non-blocking WebClient.
Consistent developer experience with Webclient.Builder
[Add the WebClient with baseUrl(localhost:8081) + template for the call]
Now we have a WebClient, we can create a new endpoint, get all the
restaurants from the repository and for each restaurant we ask the remote
service if there is a table available.
[Create the endpoint, add flatMap to this::getAvailability]
=> flatMap
flatMap
Here, think of flatMap as something that performs nested asynchronous
operations, in this case, getting the restaurant availability for the restaurant is an
async operation. At the end, flatMap will produce a single publisher using all the
nested publishers. It’s not really a new concept, Java 8 Stream API has flatMap too.
We're building a pipeline that make non-blocking calls, and the next thing is to
filter the restaurants based on availability and take only the first 3 from the
resulting flux.
Here you see the power of using Reactor in action. We're composing multiple,
asynchronous operations, without blocking, and without dealing with threads.
Simply declare what needs to be done and let it be handled in the most efficient
manner.
[http :8080/restaurants/available —stream]
=> Web Stack
Web Stack
We haven’t really talked about our web stack. What we’ve been using so far is
Spring WebFlux that co-exists with Spring MVC. Spring WebFlux runs on Netty
(which is an async runtime), by default. Tomcat/jetty are perfectly capable as well
and you can easily switch to any of them.
When using Tomcat/Jetty with WebFlux we do not use any of the blocking parts of
the Servlet API and stick to the Servlet 3.1 non-blocking API.
There is actually a session on this later today by Tomcat committer Violeta if you
want to know more. [Show slide]
Even though you have the option of making your application fully non-blocking
and asynchronous, we fully expect that you would still like to continue using
Spring MVC while taking advantage of the webClient API.
[Fireside chat about switching to Spring MVC]
=> Spring MVC
Spring MVC
[Switch, run the app again] So what just happened here.. We ran the same code on
both Spring MVC and WebFlux. What are the differences?
Underneath WebFlux eliminates all blocking and runs on a different concurrency
model. There are also features that are possible in WebFlux only.
The key point here is that Spring MVC users can also take advantage of certain
reactive features by using reactive clients like the WebClient or Spring Data
reactive repositories. This is a scenario we fully anticipate and support as a first-
class citizen.
This connects back to the theme of choice. We provide choice at every level and in
many cases you can start using reactive features in existing applications. But it
still uses blocking I/O to write the result to the HTTP response.
Oh you are reminding me of Rossen’s session later today that’s going to cover this
topic in more details. [Show slide]
=> [If we have time] Quick look at the restaurant reservation service
Quick look at the restaurant reservation
service
One part of adapting to change is to support new programming
languages that are coming up.
Kotlin, a language created by Jetbrains, that runs on the JVM is
gaining popularity because of the ability to write short and concise
code. Spring Framework 5 added dedicated support for Kotlin and
start.spring.io also lets you create a Spring Boot project using
Kotlin.
The restaurant availability service that we have running in the
background is itself a Spring Boot app written in Kotlin. [Walk
through the service a bit and show functional routing etc].
Actuator
[Remove web starter, stop the app]
Users really liked the actuator support that was available for a Spring MVC app.
How do we get the same thing with WebFlux?
Actually, that’s quite easy, just add the actuator starter as you would do naturally.
In Spring Boot 2.0, we've added support for running Actuator on top of WebFlux in
addition to the existing support for Spring MVC. Adding that support required us to
create a better abstraction for Actuator endpoints. That abstraction has allowed us
to also add support for Jersey as well.
[Add starter + start the app, show /actuator/health]
Actuators can contain sensitive information, for example, the env endpoint shows
the entire Spring environment. For security purposes, all endpoints other than info
and health are disabled by default so that they don’t get exposed accidentally.
[Expose all endpoints using the management.endpoints.web.expose property]
=> Actuator (2)
Actuator (2)
There are various improvements, notably the output format gives more
information now. Let’s get some information about the property we just set
[Hit the env endpoint for the key, explain the origin support]
As usual, the health endpoint gets health information from the supported
indicators based on your environment and any custom indicator you may have
implemented. Some indicators may use a blocking API and we want this to be
as transparent as possible for you so we wrap them and execute them on a
separate scheduler. But we also have now a reactive specific contract as you’ll
most likely have to return a Publisher for your custom health indicators
[Add custom health indicator and refresh the app]
One simple example is to use the WebClient to check that a remote service is
available. In this case, I am checking that our reservation service is up).
=> Banner and conclusion
Banner and Conclusion
So that was a short tour of the developer experience with Spring Boot and the reactive
support. Again, you’ll get a chance to explore those in more details this week. There’s
one missing bit though
[Firechat discussion about banner]
[Switch to console, start the app]
Joke driven development is the new gold standard.
Intended to trick you by creating an animated gif of my full screen just for the purpose of
the joke but Phil said if you demo, you implement it.
You can try it out by dropping your favourite animated gif support as of Spring Boot 2.0 M7.
This feature is almost as useful as the origin support.
Maybe it is. Maybe it isn’t. Regardless, the choice is yours. Thank you very much and enjoy
the conference!

Contenu connexe

Tendances

Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
Java Servlets
Java ServletsJava Servlets
Java ServletsEmprovise
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycleDhruvin Nakrani
 
Laravel mail example how to send an email using markdown template in laravel 8
Laravel mail example how to send an email using markdown template in laravel 8Laravel mail example how to send an email using markdown template in laravel 8
Laravel mail example how to send an email using markdown template in laravel 8Katy Slemon
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programmingKumar
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
Laurentiu macovei meteor. a better way of building apps
Laurentiu macovei   meteor. a better way of building appsLaurentiu macovei   meteor. a better way of building apps
Laurentiu macovei meteor. a better way of building appsCodecamp Romania
 
Extending Retrofit for fun and profit
Extending Retrofit for fun and profitExtending Retrofit for fun and profit
Extending Retrofit for fun and profitMatthew Clarke
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009Dr Nic Williams
 
Request dispatching in servlet
Request dispatching in servletRequest dispatching in servlet
Request dispatching in servletvikram singh
 
Create a meteor chat app in 30 minutes
Create a meteor chat app in 30 minutesCreate a meteor chat app in 30 minutes
Create a meteor chat app in 30 minutesDesignveloper
 
Automated shutdown
Automated shutdownAutomated shutdown
Automated shutdownMario Berend
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletFahmi Jafar
 

Tendances (20)

SERVIET
SERVIETSERVIET
SERVIET
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Initialize database in Mule part2
Initialize database in Mule part2Initialize database in Mule part2
Initialize database in Mule part2
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Servlet
Servlet Servlet
Servlet
 
Laravel mail example how to send an email using markdown template in laravel 8
Laravel mail example how to send an email using markdown template in laravel 8Laravel mail example how to send an email using markdown template in laravel 8
Laravel mail example how to send an email using markdown template in laravel 8
 
Servlets
ServletsServlets
Servlets
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Rack
RackRack
Rack
 
Laurentiu macovei meteor. a better way of building apps
Laurentiu macovei   meteor. a better way of building appsLaurentiu macovei   meteor. a better way of building apps
Laurentiu macovei meteor. a better way of building apps
 
Extending Retrofit for fun and profit
Extending Retrofit for fun and profitExtending Retrofit for fun and profit
Extending Retrofit for fun and profit
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009
 
Request dispatching in servlet
Request dispatching in servletRequest dispatching in servlet
Request dispatching in servlet
 
Create a meteor chat app in 30 minutes
Create a meteor chat app in 30 minutesCreate a meteor chat app in 30 minutes
Create a meteor chat app in 30 minutes
 
Automated shutdown
Automated shutdownAutomated shutdown
Automated shutdown
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
 

Similaire à Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017

The complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrrThe complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrrAfreenK
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet backdoor
 
servlet 2.5 & JSP 2.0
servlet 2.5 & JSP 2.0servlet 2.5 & JSP 2.0
servlet 2.5 & JSP 2.0megrhi haikel
 
WebSocket Push Fallback - Transcript.pdf
WebSocket Push Fallback - Transcript.pdfWebSocket Push Fallback - Transcript.pdf
WebSocket Push Fallback - Transcript.pdfShaiAlmog1
 
GraphQL Introduction with Spring Boot
GraphQL Introduction with Spring BootGraphQL Introduction with Spring Boot
GraphQL Introduction with Spring Bootvipin kumar
 
How do I - Networking and Webservices - Transcript.pdf
How do I - Networking and Webservices - Transcript.pdfHow do I - Networking and Webservices - Transcript.pdf
How do I - Networking and Webservices - Transcript.pdfShaiAlmog1
 
Online grocery store
Online grocery storeOnline grocery store
Online grocery storeKavita Sharma
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and ServletsRaghu nath
 
appserver.io tutorial
appserver.io tutorialappserver.io tutorial
appserver.io tutorialappserver.io
 
Inversion of control using dependency injection in Web APIs using Unity Conta...
Inversion of control using dependency injection in Web APIs using Unity Conta...Inversion of control using dependency injection in Web APIs using Unity Conta...
Inversion of control using dependency injection in Web APIs using Unity Conta...Akhil Mittal
 
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
Frequently asked MuleSoft Interview Questions and Answers from TechlightningFrequently asked MuleSoft Interview Questions and Answers from Techlightning
Frequently asked MuleSoft Interview Questions and Answers from TechlightningArul ChristhuRaj Alphonse
 
Learn Angular 9/8 In Easy Steps
Learn Angular 9/8 In Easy Steps Learn Angular 9/8 In Easy Steps
Learn Angular 9/8 In Easy Steps Ahmed Bouchefra
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx javaCongTrung Vnit
 
Advance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletAdvance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletPayal Dungarwal
 
Reactotron - A Debugging Agent
Reactotron -  A Debugging AgentReactotron -  A Debugging Agent
Reactotron - A Debugging AgentMatthieu Vachon
 
learn mvc project in 7 day
learn mvc project in 7 daylearn mvc project in 7 day
learn mvc project in 7 dayQuach Long
 

Similaire à Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017 (20)

Spring diy projects
Spring diy projectsSpring diy projects
Spring diy projects
 
Spring learning path
Spring learning pathSpring learning path
Spring learning path
 
The complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrrThe complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrr
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
 
servlet 2.5 & JSP 2.0
servlet 2.5 & JSP 2.0servlet 2.5 & JSP 2.0
servlet 2.5 & JSP 2.0
 
Spring interview questions
Spring interview questionsSpring interview questions
Spring interview questions
 
WebSocket Push Fallback - Transcript.pdf
WebSocket Push Fallback - Transcript.pdfWebSocket Push Fallback - Transcript.pdf
WebSocket Push Fallback - Transcript.pdf
 
GraphQL Introduction with Spring Boot
GraphQL Introduction with Spring BootGraphQL Introduction with Spring Boot
GraphQL Introduction with Spring Boot
 
How do I - Networking and Webservices - Transcript.pdf
How do I - Networking and Webservices - Transcript.pdfHow do I - Networking and Webservices - Transcript.pdf
How do I - Networking and Webservices - Transcript.pdf
 
Online grocery store
Online grocery storeOnline grocery store
Online grocery store
 
TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
 
appserver.io tutorial
appserver.io tutorialappserver.io tutorial
appserver.io tutorial
 
Inversion of control using dependency injection in Web APIs using Unity Conta...
Inversion of control using dependency injection in Web APIs using Unity Conta...Inversion of control using dependency injection in Web APIs using Unity Conta...
Inversion of control using dependency injection in Web APIs using Unity Conta...
 
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
Frequently asked MuleSoft Interview Questions and Answers from TechlightningFrequently asked MuleSoft Interview Questions and Answers from Techlightning
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
 
Learn Angular 9/8 In Easy Steps
Learn Angular 9/8 In Easy Steps Learn Angular 9/8 In Easy Steps
Learn Angular 9/8 In Easy Steps
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
 
Advance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletAdvance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.Servlet
 
Reactotron - A Debugging Agent
Reactotron -  A Debugging AgentReactotron -  A Debugging Agent
Reactotron - A Debugging Agent
 
learn mvc project in 7 day
learn mvc project in 7 daylearn mvc project in 7 day
learn mvc project in 7 day
 

Plus de 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 ItVMware 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 2023VMware 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 ScaleVMware Tanzu
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023VMware 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 ProductVMware Tanzu
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready AppsVMware Tanzu
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And BeyondVMware 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.pdfVMware 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 2023VMware 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 2023VMware Tanzu
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptxVMware Tanzu
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchVMware Tanzu
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishVMware Tanzu
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVMware Tanzu
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - FrenchVMware 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 2023VMware 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 BootVMware Tanzu
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerVMware 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 PracticeVMware Tanzu
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsVMware Tanzu
 

Plus de VMware Tanzu (20)

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
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
 

Dernier

Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 

Dernier (20)

Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017

  • 1. The choice is yours Internal notes
  • 2. Introduction Just a few minutes ago, Phil Webb spoke to us about changes happening in the industry and how Spring adapts itself to those changes, by giving you choices. Now we're going to show some of the new choices available in Spring Framework 5, Spring Boot 2 and Spring Data Kay combined together. I think we have seen enough slides now, it is about time we do some live coding!
  • 3. start.spring.io To get started with a new project, start.spring.io is the go-to place. [Search usual suspects in the search box] Did you know that you can actually do the same thing right from your IDE? [In the IDE, project creation] We’re going to build a fully non-blocking, reactive web application: The app itself is very simple, it will give you a list of restaurants which we can filter based on some category. => Start with a test
  • 4. Start with a test [Attempt to create Restaurant, firechat discussion about starting with a test] In Spring Framework 5 we have introduced the WebTestClient. It feels similar to using MockMvc but it is an actual client that can be used for live integration tests against any server. [Add @Autowired private WebTestClient webClient] We’re building a web-application so let’s focus on testing the controller! [Switch to @WebFluxTest] Here we are going to use it to test our reactive controller directly, i.e. without a running server (just like with MockMvc). Let’s get a list of affordable sushi places, because that’s useful… [Write test with expectStatus OK that leads to 404] => Repository, implementation, test is green
  • 5. Repository, test implementation, test is green We need a Restaurant type and let’s assume that the controller gets data from a Repository [Create Restaurant, RestaurantRepository, Inject repository in Controller] In a reactive application, we need to return a reactive streams publisher that will give us the data once it’s available, instead of the data itself. We will use the Flux and Mono implementations of a RS Publisher from the Reactor project. Let’s create a mock for the repository using @MockBean. We can improve the test to assert the content of the response Now we can add a GetMapping to /restaurants. [Implement @GetMapping] Project reactor provides us with many operators for a Flux or Mono. Think of it like Java 8 Stream but with the ability to compose asynchronous logic without worrying about thread [Test is green]
  • 6. Spring Data Spring Data Kay has reactive support for Redis, MongoDB, Couchbase and Cassandra. When you ask for data from a remote repository, you can’t be certain that the data will come to you immediately. And with a reactive data repository, we are not holding any threads waiting for the data to come. For the demo we are going to use MongoDB. As usual, starters will guide you. And, as you need to be reactive end to end, you can count on Spring Data to give you support for that use case. [Add starter] The data can be a finite collection of elements or an infinite stream. You can add operations to declare what needs to be done with the data once it comes, just like you declare operations over Java 8 streams. [Add @Document/@Id on domain - Change repo - Use repo in controller] => Start the app
  • 7. Start the app We haven’t actually started the application till now. We’ve been using a mock repository for so long but let’s connect to an actual mongodb instance. We can now invoke our actual endpoint and, let’s say, find fast food places instead [http :8080/restaurants category==fast-food maxPrice==15] I heard “Jack in The Flux” [Whoever is there] is really good and I wonder if it’s available tonight. => WebClient
  • 8. WebClient Let's create another endpoint that provides the first three restaurants that are available tonight. We can get the availability data from a remote service that’s running on port 8081. [http :8081/restaurants/Domonos/availability] The service might not always respond as quickly, or there may be time between individual items, but we will stream the data as it comes without any extra cost, we will not be blocking or holding threads at any point. [Invoke again to show the latency http :8081/restaurants/Domonos/availability] We could use the RestTemplate to contact the service, injecting a RestTemplateBuilder to get defaults and your customizations, if any. But that’s not a good choice here. => WebClient (2)
  • 9. WebClient (2) Indeed, RestTemplate is a blocking API. we don't want to make blocking calls from the server side where we are processing many requests concurrently. And didn't we want to stream the data? We can't do that with the RestTemplate. Let's use the new reactive, non-blocking WebClient. Consistent developer experience with Webclient.Builder [Add the WebClient with baseUrl(localhost:8081) + template for the call] Now we have a WebClient, we can create a new endpoint, get all the restaurants from the repository and for each restaurant we ask the remote service if there is a table available. [Create the endpoint, add flatMap to this::getAvailability] => flatMap
  • 10. flatMap Here, think of flatMap as something that performs nested asynchronous operations, in this case, getting the restaurant availability for the restaurant is an async operation. At the end, flatMap will produce a single publisher using all the nested publishers. It’s not really a new concept, Java 8 Stream API has flatMap too. We're building a pipeline that make non-blocking calls, and the next thing is to filter the restaurants based on availability and take only the first 3 from the resulting flux. Here you see the power of using Reactor in action. We're composing multiple, asynchronous operations, without blocking, and without dealing with threads. Simply declare what needs to be done and let it be handled in the most efficient manner. [http :8080/restaurants/available —stream] => Web Stack
  • 11. Web Stack We haven’t really talked about our web stack. What we’ve been using so far is Spring WebFlux that co-exists with Spring MVC. Spring WebFlux runs on Netty (which is an async runtime), by default. Tomcat/jetty are perfectly capable as well and you can easily switch to any of them. When using Tomcat/Jetty with WebFlux we do not use any of the blocking parts of the Servlet API and stick to the Servlet 3.1 non-blocking API. There is actually a session on this later today by Tomcat committer Violeta if you want to know more. [Show slide] Even though you have the option of making your application fully non-blocking and asynchronous, we fully expect that you would still like to continue using Spring MVC while taking advantage of the webClient API. [Fireside chat about switching to Spring MVC] => Spring MVC
  • 12. Spring MVC [Switch, run the app again] So what just happened here.. We ran the same code on both Spring MVC and WebFlux. What are the differences? Underneath WebFlux eliminates all blocking and runs on a different concurrency model. There are also features that are possible in WebFlux only. The key point here is that Spring MVC users can also take advantage of certain reactive features by using reactive clients like the WebClient or Spring Data reactive repositories. This is a scenario we fully anticipate and support as a first- class citizen. This connects back to the theme of choice. We provide choice at every level and in many cases you can start using reactive features in existing applications. But it still uses blocking I/O to write the result to the HTTP response. Oh you are reminding me of Rossen’s session later today that’s going to cover this topic in more details. [Show slide] => [If we have time] Quick look at the restaurant reservation service
  • 13. Quick look at the restaurant reservation service One part of adapting to change is to support new programming languages that are coming up. Kotlin, a language created by Jetbrains, that runs on the JVM is gaining popularity because of the ability to write short and concise code. Spring Framework 5 added dedicated support for Kotlin and start.spring.io also lets you create a Spring Boot project using Kotlin. The restaurant availability service that we have running in the background is itself a Spring Boot app written in Kotlin. [Walk through the service a bit and show functional routing etc].
  • 14. Actuator [Remove web starter, stop the app] Users really liked the actuator support that was available for a Spring MVC app. How do we get the same thing with WebFlux? Actually, that’s quite easy, just add the actuator starter as you would do naturally. In Spring Boot 2.0, we've added support for running Actuator on top of WebFlux in addition to the existing support for Spring MVC. Adding that support required us to create a better abstraction for Actuator endpoints. That abstraction has allowed us to also add support for Jersey as well. [Add starter + start the app, show /actuator/health] Actuators can contain sensitive information, for example, the env endpoint shows the entire Spring environment. For security purposes, all endpoints other than info and health are disabled by default so that they don’t get exposed accidentally. [Expose all endpoints using the management.endpoints.web.expose property] => Actuator (2)
  • 15. Actuator (2) There are various improvements, notably the output format gives more information now. Let’s get some information about the property we just set [Hit the env endpoint for the key, explain the origin support] As usual, the health endpoint gets health information from the supported indicators based on your environment and any custom indicator you may have implemented. Some indicators may use a blocking API and we want this to be as transparent as possible for you so we wrap them and execute them on a separate scheduler. But we also have now a reactive specific contract as you’ll most likely have to return a Publisher for your custom health indicators [Add custom health indicator and refresh the app] One simple example is to use the WebClient to check that a remote service is available. In this case, I am checking that our reservation service is up). => Banner and conclusion
  • 16. Banner and Conclusion So that was a short tour of the developer experience with Spring Boot and the reactive support. Again, you’ll get a chance to explore those in more details this week. There’s one missing bit though [Firechat discussion about banner] [Switch to console, start the app] Joke driven development is the new gold standard. Intended to trick you by creating an animated gif of my full screen just for the purpose of the joke but Phil said if you demo, you implement it. You can try it out by dropping your favourite animated gif support as of Spring Boot 2.0 M7. This feature is almost as useful as the origin support. Maybe it is. Maybe it isn’t. Regardless, the choice is yours. Thank you very much and enjoy the conference!