SlideShare uma empresa Scribd logo
1 de 68
Baixar para ler offline
Reactive Card Magic
@JavaFXpert
Web on Reactive Stack with Spring
About Presenter James Weaver
@JavaFXpert
Developer Advocate and International Speaker for Pivotal
@JavaFXpert
@JavaFXpert
Reactive Card Magic
What will we cover?
• Spring WebFlux (what, why, etc.)
• Reactive systems and Reactive programming
• Reactive programming in Java
• Project Reactor
• WebClient reactive client
• Code and concepts walkthrough of Reactive Card Magic application
@JavaFXpert
Spring WebFlux
What is it?
@JavaFXpert
A non-blocking, reactive web framework that
supports Reactive Streams back pressure, and
runs on servers such as Netty, Undertow, and
Servlet 3.1+ containers.
See: Web on Reactive Stack by the Spring team
WebFlux
Like WebMVC but Reactive
@JavaFXpert
Spring WebFlux
Why was it created?
• Because of mobile devices, IoT, and our continuing trend to live online,
some apps today have millions of clients.
• Many apps have Black Friday* style usage patterns, where demand can
spike exponentially.
• Factors such as these drive the need for a non-blocking web stack that:
• handles concurrency with a small number of threads and
• scales with less hardware resources.
@JavaFXpert
* Referring to the busiest shopping day of the year in the US, not the last Friday before Christmas in the UK :-)
@JavaFXpert
@JavaFXpert
@JavaFXpert
Spring WebFlux
Other reasons for creating it
• Continuation style APIs enabled by Java 8 lambda
expressions allow declarative composition of
asynchronous logic
• Lambdas also enabled Spring WebFlux to offer
functional web endpoints alongside with annotated
controllers
@JavaFXpert
Spring WebFlux
What does reactive mean?
• Reactive refers to programming models (and systems) that
are built around asynchronously reacting to external changes
(such as messages and events)
• An important mechanism in reactive is non-blocking back
pressure (flow control) *
@JavaFXpert
See: Web on Reactive Stack by the Spring team
* In synchronous, imperative code, blocking calls serve as a
natural form of back pressure that forces the caller to wait.
reactivemanifesto.org
The Reactive Manifesto
@JavaFXpert
Reactive systems vs. Reactive programming
• Reactive systems represent an architectural style
that allows multiple individual applications to coalesce
as a single unit, reacting to its surroundings, while
remaining aware of each other
• Reactive programming is a subset of asynchronous
programming and a paradigm where the availability of
new information drives the logic forward rather than
having control flow driven by a thread-of-execution
@JavaFXpert
From Reactive programming vs. Reactive systems by Jonas Bonér and Viktor Klang
Some Reactive programming use cases
• External Service Calls
• Highly Concurrent Message Consumers
• Spreadsheets
• Abstraction Over (A)synchronous Processing
@JavaFXpert
From: Notes on Reactive Programming Part I: The Reactive Landscape by Dave Syer
Reactive Programming in Java
A brief and incomplete history
• Reactive programming ideas have been around for a while, appearing
in programming languages (e.g. Erlang) and libraries (e.g. Reactive
Extensions for .NET)
• The open source RxJava (Reactive Extensions for Java) project
helped move reactive programming forward on the Java platform.
• The Reactive Streams initiative provided a standard and specification
for compatibility among reactive implementations in Java. This
initiative is a collaboration between engineers from Kaazing,
Lightbend, Netflix, Pivotal, Red Hat, Twitter and others.
@JavaFXpert
Reactive Programming in Java
• Reactive Streams
• RxJava
• Reactor
• Spring Framework 5
• Ratpack
• Akka
• Vert.x
@JavaFXpert
From: Notes on Reactive Programming Part I: The Reactive Landscape by Dave Syer
Reactive Streams:
@JavaFXpert
github.com/reactive-streams/reactive-streams-jvm
Is a standard and specification for stream-oriented libraries
that:
• process a potentially unbounded number of elements
• sequentially,
• with the ability to asynchronously pass elements between
components,
• with mandatory non-blocking backpressure.
reactive-streams.org
public interface Subscriber<T> {
public void onSubscribe(Subscription s);
public void onNext(T t);
public void onError(Throwable t);
public void onComplete();
}
public interface Subscriber<T> {
public void onSubscribe(Subscription s);
public void onNext(T t);
public void onError(Throwable t);
public void onComplete();
}
Reactive Streams API for Java
@JavaFXpert
enables interoperability between different Reactive implementations
public interface Publisher<T> {
public void subscribe(Subscriber<? super T> s);
}
public interface Subscription {
public void request(long n);
public void cancel();
}
public interface Processor<T, R>
extends Subscriber<T>, Publisher<R> {
}
Adopted by Java 9 in the Flow class
Reactive Streams with Spring
@JavaFXpert
From: Servlet and Reactive Stacks in Spring Framework 5 by Rossen Stoyanchev
Streaming to database with non-blocking back pressure
JSON stream
Reactive Streams with Spring
@JavaFXpert
From: Servlet and Reactive Stacks in Spring Framework 5 by Rossen Stoyanchev
Streaming from database with non-blocking back pressure
JSON stream
23
Project Reactor
The reactive library of choice for Spring WebFlux
Project Reactor
Avoiding callback hell and other asynchronous pitfalls
Reactive libraries such as Reactor aim to address drawbacks of "classic"
asynchronous approaches on the JVM while also focusing on additional aspects:
• Composability and readability
• Data as a flow manipulated with a rich vocabulary of operators
• Nothing happens until you subscribe
• Backpressure or the ability for the consumer to signal the producer that the
rate of emission is too high
• High level but high value abstraction that is concurrency-agnostic
@JavaFXpertSee: From Imperative to Reactive Programming in Project Reactor Guide
abstract class Flux<T>
implements Publisher<T> {
...
}
abstract class Flux<T>
implements Publisher<T> {
...
}
Reactive Types
abstract class Mono<T>
implements Publisher<T> {
...
}
abstract class Mono<T>
implements Publisher<T> {
...
}
Reactive Types
Reactive Types
•Mono<T>
Reactive Types
•Mono<T>
•Flux<T>
Flux.just("Hello", "Reactor", "World")
.subscribe(s -> System.out.println(s));
@JavaFXpert
Hello
Reactor
World
Project Reactor
Simple example
Project Reactor
Marble diagram: Mono
@JavaFXpert
Project Reactor
Marble diagram: Flux
@JavaFXpert
Marble diagrams
32
12:51 13:00
Flip
Flip
Reactive Marbles
rxmarbles.com
37
App we’ll use for code examples
@JavaFXpert
@JavaFXpert
CardDeck
Repository
Hand
Frequency
Respository
Card Deck
Service
Card
Shuffling
Service
Proxy
Poker
Service
Card
Deck
Controller
Poker
Controller
Poker
Service
Card Deck
Data Loader
WebClient
Mono<CardHand> Flux<HandFrequency>
Flux<Card>Mono<String>
Flux<HandFrequency>
Flux<Card>Flux<Card>
Reactive Card Magic
Application Architecture
Getting a New Deck
@JavaFXpert
@RestController
@RequestMapping("/cards/deck")
public class CardDeckController {
private final CardDeckService cardDeckService;
@Autowired
public CardDeckController(
CardDeckService cardDeckService) {
this.cardDeckService = cardDeckService;
}
@GetMapping("/new")
public Mono<CardHand> getCardDeck(@RequestParam(defaultValue = "52")
int numcards) {
return cardDeckService.generate()
.take(numcards)
.collectList()
.map(l -> new CardHand(l, "New Deck"));
}
}
@JavaFXpert
Annotated controller example
@RestController
@RequestMapping("/cards/deck")
public class CardDeckController {
private final CardDeckService cardDeckService;
@Autowired
public CardDeckController(
CardDeckService cardDeckService) {
this.cardDeckService = cardDeckService;
}
@GetMapping("/new")
public Mono<CardHand> getCardDeck(@RequestParam(defaultValue = "52")
int numcards) {
return cardDeckService.generate()
.take(numcards)
.collectList()
.map(l -> new CardHand(l, "New Deck"));
}
}
Annotated controller example
@JavaFXpert
@Bean
RouterFunction<ServerResponse> newDeckRoutes(CardDeckService cds) {
int defaultNumCards = 52;
return RouterFunctions.route(
RequestPredicates.GET("/newdeck"),
request -> cds.generate()
.take(request.queryParam("numcards")
.map(Integer::parseInt).orElse(defaultNumCards))
.collectList()
.map(l -> new CardHand(l,"New Deck"))
.flatMap(ServerResponse.ok()::syncBody));
}
Functional endpoint example
@JavaFXpert
Spring WebFlux
Using WebClient
WebClient is a reactive, non-blocking client for HTTP requests with a
functional-style API client and Reactive Streams support. By comparison to
the RestTemplate, WebClient is:
• non-blocking, reactive, and supports higher concurrency with less
hardware resources.
• provides a functional API that takes advantage of Java 8 lambdas.
• supports both synchronous and asynchronous scenarios.
• supports streaming up or down from a server.
@JavaFXpertFrom Web on Reactive Stack - WebClient
Identifying a Poker hand
@JavaFXpert
WebClient pokerWebClient = WebClient.create("http://127.0.0.1:8080");
Mono<String> pokerHandMono = pokerWebClient.post()
.uri("/poker/idhand")
.body(cardFlux, Card.class)
.retrieve()
.bodyToMono(String.class);
WebClient example
@JavaFXpert
Calling an endpoint to identify a Poker hand
Using Reactor operators
examples from the Reactive Card Magic application
@JavaFXpert
Mono
defaultIfEmpty()
flatMap()
flatMapMany()
map()
retryWhen()
then()
timeout()
Flux
as() flatMapIterable() sort()
collectList() fromArray() subscribe()
compose() fromStream() subscribeOn()
concatWith() index() take()
defer() just() transform()
distinct() map() zip()
filter() range()
flatMap() skip()
Dealing ten cards of same suit
@JavaFXpert
@GetMapping("/{suit}")
public Mono<CardHand> getCardDeckBySuit(
@PathVariable String suit,
@RequestParam(defaultValue = "10") int numcards
) {
return cardDeckService.generate()
.filter(card -> card.getSuit()
.equalsIgnoreCase(suit))
.take(numcards)
.collectList()
.map(l -> new CardHand(l, "Only " + suit));
}
@JavaFXpert
Dealing ten cards of same suit
Examining filter(), take(), collectList() and map() operators
@GetMapping("/{suit}")
public Mono<CardHand> getCardDeckBySuit(
@PathVariable String suit,
@RequestParam(defaultValue = "10") int numcards
) {
return cardDeckService.generate()
.filter(card -> card.getSuit()
.equalsIgnoreCase(suit))
.take(numcards)
.collectList()
.map(l -> new CardHand(l, "Only " + suit));
}
@JavaFXpert
Dealing ten cards of same suit
Examining filter(), take(), collectList() and map() operators
Flux filter operator
public final Flux<T> filter(Predicate<? super T> p)
@JavaFXpert
API documentation
Flux take operator
public final Flux<T> take(long n)
@JavaFXpert
API documentation
Flux collectList operator
public final Mono<List<T>> collectList()
@JavaFXpert
API documentation
Mono map operator
public final <R> Mono<R> map(Function<? super T,? extends R> mapper)
@JavaFXpert
API documentation
Flux<Card>
filter( card -> )
take( 10 )
Flux<Card>
Flux<Card>
collectList()
Mono<List<Card>>
map( list -> new CardHand(list, “Only s“))
Mono<CardHand>
Only
Hearts
take( 9 )take( 8 )take( 7 )take( 6 )take( 5 )take( 4 )take( 3 )take( 2 )take( 1 )take( 0 )
Deal Poker hand: Alternating
@JavaFXpert
private static final Comparator<Card> worthComparator =
Comparator.comparingInt(Card::getWorth);
public Flux<Card> dealPokerHand(Flux<Card> cardFlux) {
return cardFlux.index()
.take(9)
.filter(t -> t.getT1() % 2 == 0)
.map(Tuple2::getT2) // (t -> t.getT2())
.sort(worthComparator);
}
@JavaFXpert
Examining index() and sort() operators
Deal Poker hand: Alternating
Flux index operator
public final Flux<Tuple2<Long,T>> index()
@JavaFXpertAPI documentation
Flux index operator and Tuple2
Flux<Tuple2<Long,Card>>
@JavaFXpertTuple2 API documentation
1
0
2
3
index value
Flux sort operator
public final Flux<T> sort(Comparator<? super T> sortFunction)
@JavaFXpertAPI documentation
take( 9 )take( 8 )take( 7 )take( 6 )take( 5 )take( 4 )take( 3 )take( 2 )take( 1 )take( 0 )
Flux<Card>
index()
Flux<Tuple2<Long,Card>>
filter( t -> t.getT1() % 2 == 0 )
map( Tuple2::getT2 )
1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8Flux<Tuple2<Long,Card>>
Flux<Tuple2<Long,Card>> 0 2 4 6 8
Flux<Card>
Flux<Card>
sort(worthComparator)
0
take( 9 )
Reactive Card Magic
If we have time, walk through more code including:
• Additional shuffling operations such as Riffle Shuffle
• Populating the Card Deck repository
• The /shuffledealrepeat endpoint
• The /handfrequencies endpoint
• Testing with StepVerifier
@JavaFXpert
Spring WebFlux
Spring MVC and/or WebFlux?
@JavaFXpertFrom Web on Reactive Stack - Applicability
Reactive Card Magic
What have we covered? Any more questions?
• Spring WebFlux (what, why, etc.)
• Reactive systems and Reactive programming
• Reactive programming in Java
• Project Reactor
• WebClient reactive client
• Code and concepts walkthrough of Reactive Card Magic application
@JavaFXpert
Web resources
• Spring Framework 5 Web on Reactive Stack:

docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#spring-webflux
• Project Reactor:

projectreactor.io
• The Reactive Manifesto:

reactivemanifesto.org
• Reactive Card Magic app:

github.com/JavaFXpert/card-deck-demo
• James Weaver’s blogs:
• JavaFXpert.com
• CulturedEar.com
@JavaFXpert
Reactive Card Magic
@JavaFXpert
Web on Reactive Stack with Spring

Mais conteúdo relacionado

Mais procurados

Introduction to Reactive programming
Introduction to Reactive programmingIntroduction to Reactive programming
Introduction to Reactive programmingDwi Randy Herdinanto
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOPDzmitry Naskou
 
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Scrum Breakfast Vietnam
 
Intro to Reactive Programming
Intro to Reactive ProgrammingIntro to Reactive Programming
Intro to Reactive ProgrammingStéphane Maldini
 
Introduction to Spring webflux
Introduction to Spring webfluxIntroduction to Spring webflux
Introduction to Spring webfluxKnoldus Inc.
 
[Webinar]: Working with Reactive Spring
[Webinar]: Working with Reactive Spring[Webinar]: Working with Reactive Spring
[Webinar]: Working with Reactive SpringKnoldus Inc.
 
Project Reactor Now and Tomorrow
Project Reactor Now and TomorrowProject Reactor Now and Tomorrow
Project Reactor Now and TomorrowVMware Tanzu
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introductionJonathan Holloway
 
GraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster EverywhereGraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster EverywhereJ On The Beach
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudEberhard Wolff
 
Discover Quarkus and GraalVM
Discover Quarkus and GraalVMDiscover Quarkus and GraalVM
Discover Quarkus and GraalVMRomain Schlick
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥Remo Jansen
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices ArchitectureIdan Fridman
 

Mais procurados (20)

Introduction to Reactive programming
Introduction to Reactive programmingIntroduction to Reactive programming
Introduction to Reactive programming
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
Intro to Reactive Programming
Intro to Reactive ProgrammingIntro to Reactive Programming
Intro to Reactive Programming
 
Introduction to Spring webflux
Introduction to Spring webfluxIntroduction to Spring webflux
Introduction to Spring webflux
 
[Webinar]: Working with Reactive Spring
[Webinar]: Working with Reactive Spring[Webinar]: Working with Reactive Spring
[Webinar]: Working with Reactive Spring
 
Project Reactor Now and Tomorrow
Project Reactor Now and TomorrowProject Reactor Now and Tomorrow
Project Reactor Now and Tomorrow
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
GraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster EverywhereGraalVM: Run Programs Faster Everywhere
GraalVM: Run Programs Faster Everywhere
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
 
Discover Quarkus and GraalVM
Discover Quarkus and GraalVMDiscover Quarkus and GraalVM
Discover Quarkus and GraalVM
 
GraalVM
GraalVMGraalVM
GraalVM
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
Quarkus k8s
Quarkus   k8sQuarkus   k8s
Quarkus k8s
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices Architecture
 
React workshop
React workshopReact workshop
React workshop
 
GraalVm and Quarkus
GraalVm and QuarkusGraalVm and Quarkus
GraalVm and Quarkus
 

Semelhante a Reactive Card Magic: Understanding Spring WebFlux and Project Reactor

20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the tradeshinolajla
 
Reactive java programming for the impatient
Reactive java programming for the impatientReactive java programming for the impatient
Reactive java programming for the impatientGrant Steinfeld
 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016Trayan Iliev
 
Reactive microservices with eclipse vert.x
Reactive microservices with eclipse vert.xReactive microservices with eclipse vert.x
Reactive microservices with eclipse vert.xRam Maddali
 
Reactive for the Impatient - Mary Grygleski
Reactive for the Impatient - Mary GrygleskiReactive for the Impatient - Mary Grygleski
Reactive for the Impatient - Mary GrygleskiPolyglotMeetups
 
Reactive in Android and Beyond Rx
Reactive in Android and Beyond RxReactive in Android and Beyond Rx
Reactive in Android and Beyond RxFabio Tiriticco
 
Intro to Reactor
Intro to ReactorIntro to Reactor
Intro to ReactorJon Brisbin
 
Streaming to a New Jakarta EE
Streaming to a New Jakarta EEStreaming to a New Jakarta EE
Streaming to a New Jakarta EEJ On The Beach
 
Streaming to a new Jakarta EE
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EEMarkus Eisele
 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Trayan Iliev
 
Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingAraf Karsh Hamid
 
Microservices with Spring 5 Webflux - jProfessionals
Microservices  with Spring 5 Webflux - jProfessionalsMicroservices  with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionalsTrayan Iliev
 
Reactive Streams 1.0.0 and Why You Should Care (webinar)
Reactive Streams 1.0.0 and Why You Should Care (webinar)Reactive Streams 1.0.0 and Why You Should Care (webinar)
Reactive Streams 1.0.0 and Why You Should Care (webinar)Legacy Typesafe (now Lightbend)
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
Андрій Рева, "How to build reactive java application"
Андрій Рева, "How to build reactive java application"Андрій Рева, "How to build reactive java application"
Андрій Рева, "How to build reactive java application"Sigma Software
 
Journey into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsJourney into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsKevin Webber
 

Semelhante a Reactive Card Magic: Understanding Spring WebFlux and Project Reactor (20)

Reactive Applications in Java
Reactive Applications in JavaReactive Applications in Java
Reactive Applications in Java
 
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
 
Reactive java programming for the impatient
Reactive java programming for the impatientReactive java programming for the impatient
Reactive java programming for the impatient
 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016
 
Reactive microservices with eclipse vert.x
Reactive microservices with eclipse vert.xReactive microservices with eclipse vert.x
Reactive microservices with eclipse vert.x
 
Reactive for the Impatient - Mary Grygleski
Reactive for the Impatient - Mary GrygleskiReactive for the Impatient - Mary Grygleski
Reactive for the Impatient - Mary Grygleski
 
Reactive in Android and Beyond Rx
Reactive in Android and Beyond RxReactive in Android and Beyond Rx
Reactive in Android and Beyond Rx
 
REACTIVE A New Hope!
REACTIVE A New Hope!REACTIVE A New Hope!
REACTIVE A New Hope!
 
Intro to Reactor
Intro to ReactorIntro to Reactor
Intro to Reactor
 
Streaming to a New Jakarta EE
Streaming to a New Jakarta EEStreaming to a New Jakarta EE
Streaming to a New Jakarta EE
 
Streaming to a new Jakarta EE
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EE
 
Reactive Spring 5
Reactive Spring 5Reactive Spring 5
Reactive Spring 5
 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018
 
Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive Programming
 
Microservices with Spring 5 Webflux - jProfessionals
Microservices  with Spring 5 Webflux - jProfessionalsMicroservices  with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionals
 
Reactive Streams 1.0.0 and Why You Should Care (webinar)
Reactive Streams 1.0.0 and Why You Should Care (webinar)Reactive Streams 1.0.0 and Why You Should Care (webinar)
Reactive Streams 1.0.0 and Why You Should Care (webinar)
 
Reactive mesh
Reactive meshReactive mesh
Reactive mesh
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Андрій Рева, "How to build reactive java application"
Андрій Рева, "How to build reactive java application"Андрій Рева, "How to build reactive java application"
Андрій Рева, "How to build reactive java application"
 
Journey into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsJourney into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka Streams
 

Mais 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
 

Mais 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
 

Último

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
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (20)

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 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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Reactive Card Magic: Understanding Spring WebFlux and Project Reactor

  • 1. Reactive Card Magic @JavaFXpert Web on Reactive Stack with Spring
  • 2. About Presenter James Weaver @JavaFXpert Developer Advocate and International Speaker for Pivotal
  • 5. Reactive Card Magic What will we cover? • Spring WebFlux (what, why, etc.) • Reactive systems and Reactive programming • Reactive programming in Java • Project Reactor • WebClient reactive client • Code and concepts walkthrough of Reactive Card Magic application @JavaFXpert
  • 6. Spring WebFlux What is it? @JavaFXpert A non-blocking, reactive web framework that supports Reactive Streams back pressure, and runs on servers such as Netty, Undertow, and Servlet 3.1+ containers. See: Web on Reactive Stack by the Spring team
  • 7. WebFlux Like WebMVC but Reactive @JavaFXpert
  • 8. Spring WebFlux Why was it created? • Because of mobile devices, IoT, and our continuing trend to live online, some apps today have millions of clients. • Many apps have Black Friday* style usage patterns, where demand can spike exponentially. • Factors such as these drive the need for a non-blocking web stack that: • handles concurrency with a small number of threads and • scales with less hardware resources. @JavaFXpert * Referring to the busiest shopping day of the year in the US, not the last Friday before Christmas in the UK :-)
  • 12. Spring WebFlux Other reasons for creating it • Continuation style APIs enabled by Java 8 lambda expressions allow declarative composition of asynchronous logic • Lambdas also enabled Spring WebFlux to offer functional web endpoints alongside with annotated controllers @JavaFXpert
  • 13. Spring WebFlux What does reactive mean? • Reactive refers to programming models (and systems) that are built around asynchronously reacting to external changes (such as messages and events) • An important mechanism in reactive is non-blocking back pressure (flow control) * @JavaFXpert See: Web on Reactive Stack by the Spring team * In synchronous, imperative code, blocking calls serve as a natural form of back pressure that forces the caller to wait.
  • 15. Reactive systems vs. Reactive programming • Reactive systems represent an architectural style that allows multiple individual applications to coalesce as a single unit, reacting to its surroundings, while remaining aware of each other • Reactive programming is a subset of asynchronous programming and a paradigm where the availability of new information drives the logic forward rather than having control flow driven by a thread-of-execution @JavaFXpert From Reactive programming vs. Reactive systems by Jonas Bonér and Viktor Klang
  • 16. Some Reactive programming use cases • External Service Calls • Highly Concurrent Message Consumers • Spreadsheets • Abstraction Over (A)synchronous Processing @JavaFXpert From: Notes on Reactive Programming Part I: The Reactive Landscape by Dave Syer
  • 17. Reactive Programming in Java A brief and incomplete history • Reactive programming ideas have been around for a while, appearing in programming languages (e.g. Erlang) and libraries (e.g. Reactive Extensions for .NET) • The open source RxJava (Reactive Extensions for Java) project helped move reactive programming forward on the Java platform. • The Reactive Streams initiative provided a standard and specification for compatibility among reactive implementations in Java. This initiative is a collaboration between engineers from Kaazing, Lightbend, Netflix, Pivotal, Red Hat, Twitter and others. @JavaFXpert
  • 18. Reactive Programming in Java • Reactive Streams • RxJava • Reactor • Spring Framework 5 • Ratpack • Akka • Vert.x @JavaFXpert From: Notes on Reactive Programming Part I: The Reactive Landscape by Dave Syer
  • 19. Reactive Streams: @JavaFXpert github.com/reactive-streams/reactive-streams-jvm Is a standard and specification for stream-oriented libraries that: • process a potentially unbounded number of elements • sequentially, • with the ability to asynchronously pass elements between components, • with mandatory non-blocking backpressure. reactive-streams.org
  • 20. public interface Subscriber<T> { public void onSubscribe(Subscription s); public void onNext(T t); public void onError(Throwable t); public void onComplete(); } public interface Subscriber<T> { public void onSubscribe(Subscription s); public void onNext(T t); public void onError(Throwable t); public void onComplete(); } Reactive Streams API for Java @JavaFXpert enables interoperability between different Reactive implementations public interface Publisher<T> { public void subscribe(Subscriber<? super T> s); } public interface Subscription { public void request(long n); public void cancel(); } public interface Processor<T, R> extends Subscriber<T>, Publisher<R> { } Adopted by Java 9 in the Flow class
  • 21. Reactive Streams with Spring @JavaFXpert From: Servlet and Reactive Stacks in Spring Framework 5 by Rossen Stoyanchev Streaming to database with non-blocking back pressure JSON stream
  • 22. Reactive Streams with Spring @JavaFXpert From: Servlet and Reactive Stacks in Spring Framework 5 by Rossen Stoyanchev Streaming from database with non-blocking back pressure JSON stream
  • 23. 23 Project Reactor The reactive library of choice for Spring WebFlux
  • 24. Project Reactor Avoiding callback hell and other asynchronous pitfalls Reactive libraries such as Reactor aim to address drawbacks of "classic" asynchronous approaches on the JVM while also focusing on additional aspects: • Composability and readability • Data as a flow manipulated with a rich vocabulary of operators • Nothing happens until you subscribe • Backpressure or the ability for the consumer to signal the producer that the rate of emission is too high • High level but high value abstraction that is concurrency-agnostic @JavaFXpertSee: From Imperative to Reactive Programming in Project Reactor Guide
  • 25. abstract class Flux<T> implements Publisher<T> { ... } abstract class Flux<T> implements Publisher<T> { ... } Reactive Types
  • 26. abstract class Mono<T> implements Publisher<T> { ... } abstract class Mono<T> implements Publisher<T> { ... } Reactive Types
  • 29. Flux.just("Hello", "Reactor", "World") .subscribe(s -> System.out.println(s)); @JavaFXpert Hello Reactor World Project Reactor Simple example
  • 34.
  • 35. Flip
  • 36. Flip
  • 38. App we’ll use for code examples @JavaFXpert
  • 39. @JavaFXpert CardDeck Repository Hand Frequency Respository Card Deck Service Card Shuffling Service Proxy Poker Service Card Deck Controller Poker Controller Poker Service Card Deck Data Loader WebClient Mono<CardHand> Flux<HandFrequency> Flux<Card>Mono<String> Flux<HandFrequency> Flux<Card>Flux<Card> Reactive Card Magic Application Architecture
  • 40. Getting a New Deck @JavaFXpert
  • 41. @RestController @RequestMapping("/cards/deck") public class CardDeckController { private final CardDeckService cardDeckService; @Autowired public CardDeckController( CardDeckService cardDeckService) { this.cardDeckService = cardDeckService; } @GetMapping("/new") public Mono<CardHand> getCardDeck(@RequestParam(defaultValue = "52") int numcards) { return cardDeckService.generate() .take(numcards) .collectList() .map(l -> new CardHand(l, "New Deck")); } } @JavaFXpert Annotated controller example
  • 42. @RestController @RequestMapping("/cards/deck") public class CardDeckController { private final CardDeckService cardDeckService; @Autowired public CardDeckController( CardDeckService cardDeckService) { this.cardDeckService = cardDeckService; } @GetMapping("/new") public Mono<CardHand> getCardDeck(@RequestParam(defaultValue = "52") int numcards) { return cardDeckService.generate() .take(numcards) .collectList() .map(l -> new CardHand(l, "New Deck")); } } Annotated controller example @JavaFXpert
  • 43. @Bean RouterFunction<ServerResponse> newDeckRoutes(CardDeckService cds) { int defaultNumCards = 52; return RouterFunctions.route( RequestPredicates.GET("/newdeck"), request -> cds.generate() .take(request.queryParam("numcards") .map(Integer::parseInt).orElse(defaultNumCards)) .collectList() .map(l -> new CardHand(l,"New Deck")) .flatMap(ServerResponse.ok()::syncBody)); } Functional endpoint example @JavaFXpert
  • 44. Spring WebFlux Using WebClient WebClient is a reactive, non-blocking client for HTTP requests with a functional-style API client and Reactive Streams support. By comparison to the RestTemplate, WebClient is: • non-blocking, reactive, and supports higher concurrency with less hardware resources. • provides a functional API that takes advantage of Java 8 lambdas. • supports both synchronous and asynchronous scenarios. • supports streaming up or down from a server. @JavaFXpertFrom Web on Reactive Stack - WebClient
  • 45. Identifying a Poker hand @JavaFXpert
  • 46. WebClient pokerWebClient = WebClient.create("http://127.0.0.1:8080"); Mono<String> pokerHandMono = pokerWebClient.post() .uri("/poker/idhand") .body(cardFlux, Card.class) .retrieve() .bodyToMono(String.class); WebClient example @JavaFXpert Calling an endpoint to identify a Poker hand
  • 47. Using Reactor operators examples from the Reactive Card Magic application @JavaFXpert Mono defaultIfEmpty() flatMap() flatMapMany() map() retryWhen() then() timeout() Flux as() flatMapIterable() sort() collectList() fromArray() subscribe() compose() fromStream() subscribeOn() concatWith() index() take() defer() just() transform() distinct() map() zip() filter() range() flatMap() skip()
  • 48. Dealing ten cards of same suit @JavaFXpert
  • 49. @GetMapping("/{suit}") public Mono<CardHand> getCardDeckBySuit( @PathVariable String suit, @RequestParam(defaultValue = "10") int numcards ) { return cardDeckService.generate() .filter(card -> card.getSuit() .equalsIgnoreCase(suit)) .take(numcards) .collectList() .map(l -> new CardHand(l, "Only " + suit)); } @JavaFXpert Dealing ten cards of same suit Examining filter(), take(), collectList() and map() operators
  • 50. @GetMapping("/{suit}") public Mono<CardHand> getCardDeckBySuit( @PathVariable String suit, @RequestParam(defaultValue = "10") int numcards ) { return cardDeckService.generate() .filter(card -> card.getSuit() .equalsIgnoreCase(suit)) .take(numcards) .collectList() .map(l -> new CardHand(l, "Only " + suit)); } @JavaFXpert Dealing ten cards of same suit Examining filter(), take(), collectList() and map() operators
  • 51. Flux filter operator public final Flux<T> filter(Predicate<? super T> p) @JavaFXpert API documentation
  • 52. Flux take operator public final Flux<T> take(long n) @JavaFXpert API documentation
  • 53. Flux collectList operator public final Mono<List<T>> collectList() @JavaFXpert API documentation
  • 54. Mono map operator public final <R> Mono<R> map(Function<? super T,? extends R> mapper) @JavaFXpert API documentation
  • 55.
  • 56. Flux<Card> filter( card -> ) take( 10 ) Flux<Card> Flux<Card> collectList() Mono<List<Card>> map( list -> new CardHand(list, “Only s“)) Mono<CardHand> Only Hearts take( 9 )take( 8 )take( 7 )take( 6 )take( 5 )take( 4 )take( 3 )take( 2 )take( 1 )take( 0 )
  • 57. Deal Poker hand: Alternating @JavaFXpert
  • 58. private static final Comparator<Card> worthComparator = Comparator.comparingInt(Card::getWorth); public Flux<Card> dealPokerHand(Flux<Card> cardFlux) { return cardFlux.index() .take(9) .filter(t -> t.getT1() % 2 == 0) .map(Tuple2::getT2) // (t -> t.getT2()) .sort(worthComparator); } @JavaFXpert Examining index() and sort() operators Deal Poker hand: Alternating
  • 59. Flux index operator public final Flux<Tuple2<Long,T>> index() @JavaFXpertAPI documentation
  • 60. Flux index operator and Tuple2 Flux<Tuple2<Long,Card>> @JavaFXpertTuple2 API documentation 1 0 2 3 index value
  • 61. Flux sort operator public final Flux<T> sort(Comparator<? super T> sortFunction) @JavaFXpertAPI documentation
  • 62.
  • 63. take( 9 )take( 8 )take( 7 )take( 6 )take( 5 )take( 4 )take( 3 )take( 2 )take( 1 )take( 0 ) Flux<Card> index() Flux<Tuple2<Long,Card>> filter( t -> t.getT1() % 2 == 0 ) map( Tuple2::getT2 ) 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8Flux<Tuple2<Long,Card>> Flux<Tuple2<Long,Card>> 0 2 4 6 8 Flux<Card> Flux<Card> sort(worthComparator) 0 take( 9 )
  • 64. Reactive Card Magic If we have time, walk through more code including: • Additional shuffling operations such as Riffle Shuffle • Populating the Card Deck repository • The /shuffledealrepeat endpoint • The /handfrequencies endpoint • Testing with StepVerifier @JavaFXpert
  • 65. Spring WebFlux Spring MVC and/or WebFlux? @JavaFXpertFrom Web on Reactive Stack - Applicability
  • 66. Reactive Card Magic What have we covered? Any more questions? • Spring WebFlux (what, why, etc.) • Reactive systems and Reactive programming • Reactive programming in Java • Project Reactor • WebClient reactive client • Code and concepts walkthrough of Reactive Card Magic application @JavaFXpert
  • 67. Web resources • Spring Framework 5 Web on Reactive Stack:
 docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#spring-webflux • Project Reactor:
 projectreactor.io • The Reactive Manifesto:
 reactivemanifesto.org • Reactive Card Magic app:
 github.com/JavaFXpert/card-deck-demo • James Weaver’s blogs: • JavaFXpert.com • CulturedEar.com @JavaFXpert
  • 68. Reactive Card Magic @JavaFXpert Web on Reactive Stack with Spring