Slide 1

Slide 1 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Spring Workshop Mark Paluch, Pivotal Software, Inc. @mp911de

Slide 2

Slide 2 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @mp911de github.com/mp911de paluch.biz Mark Paluch

Slide 3

Slide 3 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Programm ! 10:00 Begrüßung ! 10:15–11:30 Was ist Reaktive Programmierung? ! 11:30-13:00 Einführung in Project Reactor ! 13:00-14:00 Mittagspause ! 14:00-15:00 Spring WebFlux ! 15:00–15:30 Pause ! 15:30-16:30 Reactive Spring Data !3

Slide 4

Slide 4 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What is Reactive Programming?

Slide 5

Slide 5 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Imperative ! Reactive ! Synchronous ! Blocking ! Non-Blocking ! Asynchronous ! Actors !5 Programming models

Slide 6

Slide 6 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !6 Understanding imperative HttpClient c = …; HttpGet get = new HttpGet("https://google.com"); HttpResponse response = c.execute(get);

Slide 7

Slide 7 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !7 Understanding imperative EntityManager entityManager = …; List users = … entityManager.getTransaction().begin(); for (User user : users) { entityManager.persist(user); } entityManager.getTransaction().commit();

Slide 8

Slide 8 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !8 Understanding imperative public void saveUsers() { EntityManager entityManager = …; List users = … entityManager.getTransaction().begin(); for (User user : users) { entityManager.persist(user); } entityManager.getTransaction().commit(); }

Slide 9

Slide 9 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !9 Understanding imperative HttpClient c = …; for (int i = 0; i < 10; i++) { HttpGet get = new HttpGet("https://google.com"); HttpResponse response = c.execute(get); // … }

Slide 10

Slide 10 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Use Case: Remote calls with latency !10 Request Data access Remote data service I/O Wait This one is waiting

Slide 11

Slide 11 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Makes assumptions over resource usage ! Developers are in charge of resource usage efficiency !11 Imperative programming

Slide 12

Slide 12 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Container calls code on a Thread ! Call continues until all work is done ! Thread is occupied ! Thread is released at the end of work • Latencies affect duration in which Thread is occupied !12 Imperative: Web applications

Slide 13

Slide 13 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Use Case: Synchronous fetch model !13 Service App Data store App Service

Slide 14

Slide 14 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Reactive is used to describe event-driven systems ! Reactive is used more for scalability and stability than for speed ! Reacts to resource availability !14 What is reactive?

Slide 15

Slide 15 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Use Case: Serve slow clients !15 Server

Slide 16

Slide 16 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Use Case: Serve slow clients !16 Server

Slide 17

Slide 17 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Use Case: Push message to client !17 Server Message Broker

Slide 18

Slide 18 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Live (continuous) database queries ! UI event handling (Android) ! Big Data ! Real time analytics ! HTTP/2 !18 Other use cases

Slide 19

Slide 19 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! A form of computer timing control protocol ! Starts processing after receiving a signal ! Completed eventually !19 Asynchronous

Slide 20

Slide 20 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Introduces concurrency ! Does not block the caller • At least in the first place ! Keeps more Threads busy !20 Asynchronous

Slide 21

Slide 21 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Unit of execution • Runnable ! Executor • Thread • ThreadPool !21 Asynchronous: Requirements

Slide 22

Slide 22 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Asynchronous: Future !22 AsyncRestTemplate asyncRestTemplate = … AsyncCassandraTemplate asyncCassandra = … SettableListenableFuture future = new SettableListenableFuture<>(); asyncRestTemplate.getForEntity("https://slow-service.com", String.class) .addCallback(response -> { Page page = new Page(); page.setId(…); page.setContent(response.getBody()); ListenableFuture insertFuture = asyncCassandra.insert(page); insertFuture.addCallback(savedPage -> future.set("OK"), failure -> future.setException(failure)); }, failure -> failure -> future.setException(failure)); return future;

Slide 23

Slide 23 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Asynchronous: Future !23 AsyncRestTemplate asyncRestTemplate = … AsyncCassandraTemplate asyncCassandra = … SettableListenableFuture future = new SettableListenableFuture<>(); asyncRestTemplate.getForEntity("https://slow-service.com", String.class) .addCallback(response -> { Page page = new Page(); page.setId(…); page.setContent(response.getBody()); ListenableFuture insertFuture = asyncCassandra.insert(page); insertFuture.addCallback(savedPage -> future.set("OK"), failure -> future.setException(failure)); }, failure -> failure -> future.setException(failure)); return future;

Slide 24

Slide 24 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Asynchronous: Future !24 AsyncRestTemplate asyncRestTemplate = … AsyncCassandraTemplate asyncCassandra = … SettableListenableFuture future = new SettableListenableFuture<>(); asyncRestTemplate.getForEntity("https://slow-service.com", String.class) .addCallback(response -> { Page page = new Page(); page.setId(…); page.setContent(response.getBody()); ListenableFuture insertFuture = asyncCassandra.insert(page); insertFuture.addCallback(savedPage -> future.set("OK"), failure -> future.setException(failure)); }, failure -> failure -> future.setException(failure)); return future;

Slide 25

Slide 25 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Asynchronous: Future !25 AsyncRestTemplate asyncRestTemplate = … AsyncCassandraTemplate asyncCassandra = … SettableListenableFuture future = new SettableListenableFuture<>(); asyncRestTemplate.getForEntity("https://slow-service.com", String.class) .addCallback(response -> { Page page = new Page(); page.setId(…); page.setContent(response.getBody()); ListenableFuture insertFuture = asyncCassandra.insert(page); insertFuture.addCallback(savedPage -> future.set("OK"), failure -> future.setException(failure)); }, failure -> failure -> future.setException(failure)); return future;

Slide 26

Slide 26 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Say „callback“ to a JavaScript developer and he will start crying instantaneously! – Venkat Subramaniam !26

Slide 27

Slide 27 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !27 Using Java types Non- Blocking Streaming Pattern Future x Pull CompletableFuture x Push Stream x Pull Iterator x Pull Input/OutputStream x Pull

Slide 28

Slide 28 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Available since Java 8 ! Functional composition ! Functional transformation !28 Asynchronous: CompletableFuture

Slide 29

Slide 29 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Asynchronous: CompletableFuture example !29 CompletableFuture> future = … future.thenCompose(response -> { Page page = new Page(); page.setId(…); page.setContent(response.getBody()); return asyncCassandra.insert(page); }).thenApply(Page::getId);

Slide 30

Slide 30 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !30 Concurrency effects public static class Test extends Thread { boolean keepRunning = true; public void run() { long count = 0; while (keepRunning) { count++; } System.out.println("Thread terminated after cycles: " + count); } } public static void main(String[] args) throws InterruptedException { Test t = new Test(); t.start(); System.out.println("Started"); Thread.sleep(1000); t.keepRunning = false; System.out.println("keepRunning set to false."); }

Slide 31

Slide 31 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Understanding the Java Memory Model is hard. Getting concurrency right is harder. !31

Slide 32

Slide 32 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Effects of an async fetch model !32 Request I/O Requires synchronization Still waiting, eh?

Slide 33

Slide 33 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Makes assumptions over resource usage ! Need a change • Change programming model !33 Imperative programming

Slide 34

Slide 34 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ We need a different toolset! !34

Slide 35

Slide 35 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ We need a different toolset! !35

Slide 36

Slide 36 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Allows building and composing asynchronous applications ! Reacts to the availability of resources ! Requires a reactive API !36 Reactive programming model

Slide 37

Slide 37 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Collaborative initiative to provide a standard for asynchronous stream processing with non-blocking back pressure. ! Co-designed by Twitter, Lightbend, Pivotal, Netflix and many others ! De-facto interop standard ! Java 9: Flow API !37 Reactive Streams

Slide 38

Slide 38 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Publisher and Subscriber !38 Subscriber Publisher Subscribe Data

Slide 39

Slide 39 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !39 Distributions org.reactivestreams:reactive-streams • Publisher • Subscriber • Subscription • Processor • Flow.Publisher • Flow.Subscriber • Flow.Subscription • Flow.Processor Part of Java 9 in java.util.concurrent

Slide 40

Slide 40 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Apply a wide range of operators: map, split, merge, delay RxJava 1 2 Project Reactor Akka Streams !40 Reactive libraries

Slide 41

Slide 41 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !41 Reactive APIs on the JVM Reactive API Reactive Streams
 Type Non-Reactive
 Streams Type RxJava 1 Observable
 Single
 Completable RxJava 2 Flowable Observable
 Single
 Maybe,Completable Akka Streams 2 Source
 Sink
 Flow Project Reactor Mono
 Flux

Slide 42

Slide 42 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !42 Reactive APIs on the JVM: Generations Reactive API Generation Support RxJava 1 2nd Limited back pressure RxJava 2 4th Reactive Streams + operator fusion Akka Streams 2 3rd Reactive Streams + actor fusion Project Reactor 4th Reactive Streams + operator fusion

Slide 43

Slide 43 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Use Reactor if • using Java 8 ! Use RxJava if • stuck with Java 6 • need checked Exceptions in functions !43 RxJava 2 or Project Reactor

Slide 44

Slide 44 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! „Volume knob“ for data emission ! Communicates demand (capacity) of the subscriber to the publisher !44 Back pressure

Slide 45

Slide 45 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Request all the data ! Now !45 Asynchronous fetch model AsyncHttpClient c = …; for (int i = 0; i < 10; i++) { HttpGet get = new HttpGet("https://google.com"); Future response = c.execute(get); // … }

Slide 46

Slide 46 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Asynchronous fetch model !46 Remote App Remote Remote App can’t keep up (Back pressure)

Slide 47

Slide 47 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Publisher and Subscriber !47 Subscriber Publisher Publish as fast as possible

Slide 48

Slide 48 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !48 Publisher I/O thread push

Slide 49

Slide 49 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Back pressure control !49 Subscriber Publisher Demand

Slide 50

Slide 50 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Back pressure control !50 Subscriber Publisher Demand

Slide 51

Slide 51 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive fetch model !51 Data store App Data store Data store Data store App

Slide 52

Slide 52 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Zeit für Fragen 11:30-13:00 Einführung in Project Reactor

Slide 53

Slide 53 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Introduction to Project Reactor

Slide 54

Slide 54 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How do you achieve asynchronous, non-blocking processing? Without losing your mind? !54

Slide 55

Slide 55 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !55

Slide 56

Slide 56 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !56

Slide 57

Slide 57 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !57 List Iterator Future Future> .get() for-each .hasNext() Request thread pulls

Slide 58

Slide 58 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !58 Publisher Thread pushes data

Slide 59

Slide 59 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !59 Iterable Iterator Publisher Subscriber vs.

Slide 60

Slide 60 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !60 Subscriber Publisher feedback push events produces consumes Relation between Publisher and Subscriber

Slide 61

Slide 61 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !61 Subscriber Publisher feedback push events produces consumes interfaces from Reactive Streams spec Relation between Publisher and Subscriber

Slide 62

Slide 62 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !62 Subscriber Publisher feedback 0..N elements + 0..1 (complete | error) produces consumes Signals

Slide 63

Slide 63 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !63 Subscriber Publisher push events produces consumes Demand (Back pressure control) Back pressure

Slide 64

Slide 64 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !64 Subscriber Publisher push events produces consumes can I have an API though?

Slide 65

Slide 65 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !65 Subscriber Publisher push events produces consumes

Slide 66

Slide 66 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !66 Project Reactor 3

Slide 67

Slide 67 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Composing asynchronous & event-based sequences, using non-blocking operators ! Without sacrifice • No callback hell • No Futures ! End to end Reactive Streams !67 Project Reactor

Slide 68

Slide 68 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Duration ! CompletableFuture ! Stream !68 Focus on Java 8

Slide 69

Slide 69 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Project Reactor Types !69 Mono Flux 0..1..Error 0..N..Error

Slide 70

Slide 70 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !70 This is the timeline of the Flux. Time flows from left to right. These are items emitted by the Flux. This vertical line indicates that the Flux has completed successfully. These dotted lines and this box indicate that a transformation is being applied to the Flux. The text inside the box shows the nature of the transformation. If for some reason the Flux terminates abnormally, with an error, the vertical line is replaced by an X. This Flux is the result of the transformation. operator 1 2 3 4 5 6 1 2 3 Explaining reactive operations

Slide 71

Slide 71 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Explaining reactive operations !71 Transformed Completion signal Error signal Emitted element Time

Slide 72

Slide 72 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Flux !72 These are items emitted by the Flux. operator 1 2 3 4 5 6 1 2 3

Slide 73

Slide 73 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Mono !73 This is the eventual item emitted by the Mono. operator 1 1

Slide 74

Slide 74 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !74 Operators an Rx-inspired API with a vocabulary of operators similar to RxJava...

Slide 75

Slide 75 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !75 Operators an Rx-inspired API ...but not exactly the same

Slide 76

Slide 76 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !76 Flux/Mono generator operator operator operator nothing happens until you subscribe

Slide 77

Slide 77 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !77 Flux/Mono generator Subscriber operator operator operator nothing happens until you subscribe

Slide 78

Slide 78 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Flux/Mono generator Subscriber operator operator operator Sub Sub Sub per Subscription state

Slide 79

Slide 79 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ data flows Flux/Mono generator Subscriber operator operator operator Sub Sub Sub

Slide 80

Slide 80 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Reactor is agnostic ! Facilitates switching ! Schedulers !80 Threading (contexts)

Slide 81

Slide 81 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! single: Single-Threaded scheduler ! elastic: Grows (unbounded) as needed • used for I/O offloading ! parallel: Fixed-sized at number of CPU cores • Event-Loop ! timer: Timed tasks !81 Schedulers

Slide 82

Slide 82 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! publishOn • switch emission of the Publisher on a thread ! subscribeOn • make the subscription and request happen on a particular thread !82 Context switching

Slide 83

Slide 83 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !83 Flux/Mono generator operator subscribeOn operator publishOn operator operator Subscriber Sub Sub Sub Sub Sub Sub

Slide 84

Slide 84 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !84 Flux/Mono generator operator subscribe On operator publish On operator operator Subscriber Sub Sub Sub Sub Sub Sub

Slide 85

Slide 85 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !85 Flux/Mono generator operator subscribeOn operator publishOn operator operator Subscriber Sub Sub Sub Sub Sub Sub

Slide 86

Slide 86 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !86 Flux/Mono generator operator subscribeOn operator publishOn operator operator Subscriber Sub Sub Sub Sub Sub Sub

Slide 87

Slide 87 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !87 Flux/Mono generator operator subscribeOn operator publishOn operator operator Subscriber Sub Sub Sub Sub Sub Sub

Slide 88

Slide 88 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !88 Flux/Mono generator operator subscribeOn operator publishOn operator operator Subscriber Sub Sub Sub Sub Sub Sub

Slide 89

Slide 89 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Operator time! map, filter, buffer !89

Slide 90

Slide 90 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !90 Flux.range Subscriber map filter buffer

Slide 91

Slide 91 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !91

Slide 92

Slide 92 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !92

Slide 93

Slide 93 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !93

Slide 94

Slide 94 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !94 Flux.range Subscriber map filter buffer

Slide 95

Slide 95 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !95 Flux.range Subscriber map filter buffer

Slide 96

Slide 96 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !96 Flux.range Subscriber map filter buffer

Slide 97

Slide 97 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !97 Flux.range Subscriber map filter buffer

Slide 98

Slide 98 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !98 Flux.range Subscriber map filter buffer

Slide 99

Slide 99 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !99 Flux.range Subscriber map filter buffer

Slide 100

Slide 100 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !100 Flux.range Subscriber map filter buffer

Slide 101

Slide 101 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !101 Flux.range(5, 3) .map(i -> i + 3) .filter(i -> i % 2 == 0) .buffer(3)

Slide 102

Slide 102 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !102 Flux.range(5, 3) .map(i -> i + 3) .filter(i -> i % 2 == 0) .buffer(3) 5, 6, 7 | 8, 9, 10 | 8, 10 | [8,10]|

Slide 103

Slide 103 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Operator time²! flatMap all the things !103

Slide 104

Slide 104 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Asynchronous sub-process ! Map to 0, 1 or N elements !104 flatMap operator

Slide 105

Slide 105 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !105

Slide 106

Slide 106 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !106

Slide 107

Slide 107 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !107

Slide 108

Slide 108 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !108 flatMap(user -> tweetStream(user))

Slide 109

Slide 109 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !109 flatMap(user -> tweetStream(user))

Slide 110

Slide 110 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !110 flatMap(user -> tweetStream(user))

Slide 111

Slide 111 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !111 flatMap(user -> tweetStream(user))

Slide 112

Slide 112 text

Unless otherwise indicated, these slides are 
 © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Coding Time!

Slide 113

Slide 113 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Zeit für Fragen

Slide 114

Slide 114 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring WebFlux

Slide 115

Slide 115 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! It’s all about efficient resource usage ! Turn around the idea of imperative programming ! React to the availability of resources !115 What is Reactive Spring

Slide 116

Slide 116 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Scaling !116

Slide 117

Slide 117 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Spring WebFlux – Reactive web applications ! Spring Data – Reactive data store support ! Spring Cloud Stream – Message-driven microservices ! Spring Boot – Reactive auto configuration ! Spring Security – Security for reactive web applications ! Spring Cloud Gateway – API Gateway !117 Reactive Spring portfolio

Slide 118

Slide 118 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Spring’s reactive web framework ! End to end non-blocking and asynchronous execution !118 What is WebFlux?

Slide 119

Slide 119 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Project Reactor 3.1 ! Spring Framework 5.0 ! Optional: Spring Boot 2.0 !119 Requirements

Slide 120

Slide 120 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !120

Slide 121

Slide 121 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !121

Slide 122

Slide 122 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Servlet API is thread-bound ! Servlet API has no native HTTP/2 support (yet) ! No notion of back pressure ! SSE API’s (Server-sent events) are vendor-specific !122

Slide 123

Slide 123 text

Unless otherwise indicated, these slides are 
 © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Coding Time!

Slide 124

Slide 124 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Allows usage of Reactive types ! Improves asynchronous usage (DeferredResult) ! Improves SSE streaming usage (ResponseBodyEmitter) ! Everything else is blocking !124 Spring Web MVC

Slide 125

Slide 125 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Zeit für Fragen 15:00–15:30 Pause 15:30-16:30 Reactive Spring Data

Slide 126

Slide 126 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Spring Data

Slide 127

Slide 127 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Accessing data today !127 Request Data access Remote data service I/O Wait This one is waiting

Slide 128

Slide 128 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Accessing data today !128 Request Data access Remote data service Multiple calls Bulk fetch

Slide 129

Slide 129 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Keep resources busy ! Connection contention ! Usually synchronous/blocking ! Multiple requests ! Asynchronous isn’t always a good answer !129 Todays’ data access

Slide 130

Slide 130 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Project Reactor 3.1 ! Spring Framework 5.0 ! Spring Data 2.0 ! A reactive (asynchronous, ideally non-blocking) driver ! Optional: Spring Boot 2.0 !130 Requirements for Reactive Spring Data

Slide 131

Slide 131 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Reactive Template API ! Reactive Repository support ! Reduced feature set !131 Reactive Spring Data

Slide 132

Slide 132 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! MongoDB ! Apache Cassandra ! Redis ! Couchbase !132 Reactive Spring Data modules

Slide 133

Slide 133 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! JDBC is a blocking API ! JPA is a blocking API ! Sorry, no reactive JPA support so far ! …but !133 What about JPA

Slide 134

Slide 134 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Efforts from Oracle • ADBA ! Efforts from Pivotal • R2DBC ! Third-party • RxJava2 JDBC • Vert.x drivers !134 Reactive Relational Database Access

Slide 135

Slide 135 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Not a priority but feasible • Neo4j • Solr • ElasticSearch !135 Future reactive Spring Data modules

Slide 136

Slide 136 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Non-blocking I/O ! Threading-infrastructure ! Back pressure ! Integration with reactive libraries !136 Why reactive drivers?

Slide 137

Slide 137 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive fetch model !137 Data store App Data store Data store Data store App

Slide 138

Slide 138 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !138 Imperative Template API T insert(T objectToSave) void insertAll(Collection<…> objects)

Slide 139

Slide 139 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !139 Reactive Template API Mono insert(T objectToSave) Mono insert(Mono objectToSave)

Slide 140

Slide 140 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !140 Reactive Repository API public interface ReactivePersonRepository extends ReactiveCrudRepository {
 
 Flux findByLastname(String lastname);
 
 @Query("{ 'firstname': ?0 }")
 Mono customQuery(String firstname); Flux findByLastname(Mono lastname); }

Slide 141

Slide 141 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !141 Reactive Repository API public interface ReactivePersonRepository extends ReactiveCrudRepository {
 
 Flux findByLastname(String lastname);
 
 @Query("{ 'firstname': ?0 }")
 Mono customQuery(String firstname); Flux findByLastname(Mono lastname); }

Slide 142

Slide 142 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !142 Reactive Repository API public interface ReactivePersonRepository extends ReactiveCrudRepository {
 
 Flux findByLastname(String lastname);
 
 @Query("{ 'firstname': ?0 }")
 Mono customQuery(String firstname); Flux findByLastname(Mono lastname); }

Slide 143

Slide 143 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !143 Reactive Repository API public interface ReactivePersonRepository extends ReactiveCrudRepository {
 
 Flux findByLastname(String lastname);
 
 @Query("{ 'firstname': ?0 }")
 Mono customQuery(String firstname); Flux findByLastname(Mono lastname); }

Slide 144

Slide 144 text

Unless otherwise indicated, these slides are 
 © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Coding Time!

Slide 145

Slide 145 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Blocking driver ! Reactive driver ! Requires both drivers and two connections ! Collection operations (CRUD, Geo-commands) ! Aggregation streaming ! No GridFS, MapReduce, Grouping support in Spring Data !145 Reactive MongoDB

Slide 146

Slide 146 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Asynchronous driver (adoption layer) ! Feature parity ! Optional: Asynchronous Template API with ListenableFuture !146 Reactive Apache Cassandra

Slide 147

Slide 147 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Reactive driver (used for blocking operations as well) ! Reactive Template API ! Planned: Reactive Pub/Sub ! No Reactive Repository support !147 Reactive Redis

Slide 148

Slide 148 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Reactive driver (used for blocking operations as well) ! Reactive Template API ! Reactive Repository support !148 Reactive Couchbase

Slide 149

Slide 149 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Going Reactive

Slide 150

Slide 150 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Change your mindset ! Non-blocking • I/O • Computation ! Consider if reactive is benefit or burden !150 What does it take to go reactive?

Slide 151

Slide 151 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Carefully consider whether it makes sense ! Functional-reactive programming is a good answer for a certain class of problems ! Can improve code ! Can clutter code !151 Existing applications

Slide 152

Slide 152 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Get familiar with the vocabulary • Asynchronous • non-blocking • back pressure • reactive • reactive extensions • streams operators !152 Reactive language

Slide 153

Slide 153 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Don’t implment Reactive Streams interfaces yourself • Unless you’re trying the RS TCK to pass ! Reactive Streams is just the contract • Use a reactive composition library ! Nothing happens until subscription !153 Reactive Streams

Slide 154

Slide 154 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ! Carefully select your tools • API • Drivers ! Tooling is important ! Define code styles ! Learn reading the stack trace !154 Reactive composition library

Slide 155

Slide 155 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !155 … at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory at java.lang.Thread.run(Thread.java:745)

Slide 156

Slide 156 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !156 java.lang.NullPointerException: The mapper returned a null value. at java.util.Objects.requireNonNull(Objects.java:228) at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:37 at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:37 at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:76) at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:37 at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java: at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:37 at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:37 at reactor.core.publisher.FluxFlatMap$FlatMapMain.innerNext(FluxFlatMap.java:778)

Slide 157

Slide 157 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !157 Assembly trace from producer [reactor.core.publisher.MonoMapFuseable] : reactor.core.publisher.Mono.map(Mono.java:2126) org.springframework.data.redis.core.DefaultReactiveValueOperations.lambda$get$12(DefaultRea org.springframework.data.redis.core.DefaultReactiveValueOperations.lambda$createMono$23(Def org.springframework.data.redis.core.ReactiveRedisTemplate.doInConnection(ReactiveRedisTempl org.springframework.data.redis.core.ReactiveRedisTemplate.lambda$createMono$1(ReactiveRedis reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:45) reactor.core.publisher.MonoSwitchIfEmpty.subscribe(MonoSwitchIfEmpty.java:44) reactor.core.publisher.Mono.block(Mono.java:1263) workshop.CachingController.getOrCreate(CachingController.java:44) org.springframework.web.reactive.result.method.InvocableHandlerMethod.doInvoke(InvocableHan org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$invoke$0(Invoc

Slide 158

Slide 158 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ !158 Error has been observed by the following operator(s): |_ Mono.map(DefaultReactiveValueOperations.java:157) |_ Flux.from(ReactiveRedisTemplate.java:296) |_ Flux.doOnSignal(ReactiveRedisTemplate.java:296) |_ Mono.from(ReactiveRedisTemplate.java:272) |_ Mono.defer(ReactiveRedisTemplate.java:272) |_ Mono.switchIfEmpty(CachingController.java:44) |_ Mono.error(InvocableHandlerMethod.java:127) |_ Mono.flatMap(InvocableHandlerMethod.java:116) |_ Mono.doOnSignal(RequestMappingHandlerAdapter.java:191) |_ Mono.error(RequestMappingHandlerAdapter.java:215) |_ Mono.onErrorResume(RequestMappingHandlerAdapter.java:192) |_ Mono.defer(RequestMappingHandlerAdapter.java:189) |_ Mono.then(RequestMappingHandlerAdapter.java:189) |_ Mono.flatMap(DispatcherHandler.java:129) |_ Mono.flatMap(DispatcherHandler.java:130) |_ Mono.error(ResponseStatusExceptionHandler.java:47) |_ Mono.onErrorResume(ExceptionHandlingWebHandler.java:67)

Slide 159

Slide 159 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Zeit für Fragen Mark Paluch • @mp911de

Slide 160

Slide 160 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Resources ! Code - Repository @ Github ! Reactor Rx Lite API – Repository @ Github ! Spring Data Examples – Repository @ Github ! Spring projects release calendar – Google Calendar !160 @mp911de

Slide 161

Slide 161 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Backup !161

Slide 162

Slide 162 text

Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactive Execution Model !162 Request Data access Reactive remote data service That’s not the data you’re looking for Remote data service Stream Demand Dispatcher