Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Reactive Spring Workshop
Slide 2
Slide 2 text
Reactive Programming 101 what does it bring to the table?
Slide 3
Slide 3 text
WHY?
Slide 4
Slide 4 text
WHY? because blocking is evil
Slide 5
Slide 5 text
sync/blocking main thread processing resumes I/O ! app does nothing
Slide 6
Slide 6 text
sync/blocking main thread processing resumes I/O BAD ! app does nothing
Slide 7
Slide 7 text
async & blocking main thread wait & join ! new threads, costly ! complex
Slide 8
Slide 8 text
async & blocking main thread wait & join ! new threads, costly ! complex BAD
Slide 9
Slide 9 text
async & nonblocking “event loop” in non-blocking processin g chunks no more threads than needed
Slide 10
Slide 10 text
how do you achieve that without losing your mind ?
Slide 11
Slide 11 text
Reactive Programming
Slide 12
Slide 12 text
Composing asynchronous & event-based sequences, using non-blocking operators “ ”
Slide 13
Slide 13 text
without sacrifice
Slide 14
Slide 14 text
without sacrifice Callbacks ? Futures ? easy to block hard to compose callback hell ! not readable
Slide 15
Slide 15 text
Pull? Push!
Slide 16
Slide 16 text
Pull? Push!
Slide 17
Slide 17 text
vs Iterable - Iterator Publisher - Subscriber
Slide 18
Slide 18 text
Data in Flux
Slide 19
Slide 19 text
Publisher Subscriber push events produces consumes feedback
Slide 20
Slide 20 text
interfaces from Reactive Streams spec Publisher Subscriber feedback consumes push events produces
Slide 21
Slide 21 text
Publisher Subscriber push events produces consumes feedback Subscriber onNext(T) onComplete(); onError(Throwable);
Slide 22
Slide 22 text
Publisher Subscriber produces consumes feedback 0..N elements + 0..1 (complete | error)
Slide 23
Slide 23 text
Publisher Subscriber push events produces consumes feedback backpressure
Slide 24
Slide 24 text
Publisher Subscriber push events produces consumes feedback can I have an API though?
Slide 25
Slide 25 text
Publisher Subscriber push events produces consumes feedback
Slide 26
Slide 26 text
Reactor 3 types and operators
Slide 27
Slide 27 text
Flux for 0..N elements
Slide 28
Slide 28 text
No content
Slide 29
Slide 29 text
Mono for at most 1 element
Slide 30
Slide 30 text
No content
Slide 31
Slide 31 text
Reactive Streams all the way
Slide 32
Slide 32 text
focus on Java 8
Slide 33
Slide 33 text
focus on Java 8 Duration, CompletableFuture, Streams
Slide 34
Slide 34 text
an Rx-inspired API with a vocabulary of operators similar to RxJava...
Slide 35
Slide 35 text
an Rx-inspired API ...but not exactly the same
Slide 36
Slide 36 text
Flux/Mono generator operator operator operator nothing happens until you subscribe
Slide 37
Slide 37 text
Flux/Mono generator Subscriber operator operator operator nothing happens until you subscribe
Slide 38
Slide 38 text
Flux/Mono generator Subscriber operator operator operator per Subscription state Sub Sub Sub
Slide 39
Slide 39 text
Flux/Mono generator Subscriber operator operator operator data flows Sub Sub Sub
Slide 40
Slide 40 text
“elements of functional programming”
Slide 41
Slide 41 text
threading contexts
Slide 42
Slide 42 text
Reactor is agnostic
Slide 43
Slide 43 text
however it facilitates switching
Slide 44
Slide 44 text
Schedulers
Slide 45
Slide 45 text
Schedulers elastic, parallel, single, timer...
Slide 46
Slide 46 text
publishOn switch rest of the flux on a thread
Slide 47
Slide 47 text
subscribeOn make the subscription and request happen on a particular thread
Slide 48
Slide 48 text
Flux/Mono generator operator subscribeOn operator publishOn operator operator Subscriber Sub Sub Sub Sub Sub Sub
Slide 49
Slide 49 text
Flux/Mono generator operator subscribe On operator publish On operator operator Subscriber Sub Sub Sub Sub Sub Sub
Slide 50
Slide 50 text
Flux/Mono generator operator subscribeOn operator publishOn operator operator Subscriber Sub Sub Sub Sub Sub Sub
Slide 51
Slide 51 text
Flux/Mono generator operator subscribeOn operator publishOn operator operator Subscriber Sub Sub Sub Sub Sub Sub
Slide 52
Slide 52 text
Flux/Mono generator operator subscribeOn operator publishOn operator operator Subscriber Sub Sub Sub Sub Sub Sub
Slide 53
Slide 53 text
Flux/Mono generator operator subscribeOn operator publishOn operator operator Subscriber Sub Sub Sub Sub Sub Sub
Slide 54
Slide 54 text
CODING TIME!
Slide 55
Slide 55 text
No content
Slide 56
Slide 56 text
Bonus Slides operator step-by-step examples, backpressure
Slide 57
Slide 57 text
map, filter, buffer
Slide 58
Slide 58 text
Flux.range Subscriber map filter buffer
Slide 59
Slide 59 text
No content
Slide 60
Slide 60 text
No content
Slide 61
Slide 61 text
No content
Slide 62
Slide 62 text
Flux.range(5, 3) .map(i -> i + 3) .filter(i -> i % 2 == 0) .buffer(3)
Slide 63
Slide 63 text
Flux.range Subscriber map filter buffer
Slide 64
Slide 64 text
Flux.range Subscriber map filter buffer
Slide 65
Slide 65 text
Flux.range Subscriber map filter buffer
Slide 66
Slide 66 text
Flux.range Subscriber map filter buffer
Slide 67
Slide 67 text
Flux.range Subscriber map filter buffer
Slide 68
Slide 68 text
Flux.range Subscriber map filter buffer
Slide 69
Slide 69 text
Flux.range Subscriber map filter buffer
Slide 70
Slide 70 text
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 71
Slide 71 text
retry
Slide 72
Slide 72 text
Flux.from Subscriber map filter retry Publisher from HTTP reactive client
Slide 73
Slide 73 text
No content
Slide 74
Slide 74 text
Flux.from Subscriber map filter retry Publisher from HTTP reactive client
Slide 75
Slide 75 text
Flux.from Subscriber map filter retry Publisher from HTTP reactive client resubscribe
Slide 76
Slide 76 text
Trickier: flatMap async sub-processes
Slide 77
Slide 77 text
No content
Slide 78
Slide 78 text
flatMap(user -> tweetStream(user))
Slide 79
Slide 79 text
flatMap(user -> tweetStream(user))
Slide 80
Slide 80 text
flatMap(user -> tweetStream(user))
Slide 81
Slide 81 text
flatMap(user -> tweetStream(user))
Slide 82
Slide 82 text
No content
Slide 83
Slide 83 text
& much more...
Slide 84
Slide 84 text
backpressure the "volume control"
Slide 85
Slide 85 text
Publisher Subscriber subscribe
Slide 86
Slide 86 text
Publisher Subscriber push data as fast as possible
Slide 87
Slide 87 text
Publisher Subscriber subscribe with small request (eg. 1)
Slide 88
Slide 88 text
Publisher Subscriber 1 onNext
Slide 89
Slide 89 text
Publisher Subscriber request more (eg. 2)
Slide 90
Slide 90 text
Publisher Subscriber 2 onNext
Slide 91
Slide 91 text
Publisher Subscriber backpressure
Slide 92
Slide 92 text
other ways of dealing with backpressure eg. drop, buffer...
Slide 93
Slide 93 text
Credits ! Robot Devil: copyright FOX ! Volume Knob: CC0 (via Pixabay) ! Camel Shape: CC0 (via Pixabay) ! Dromedary Shape: CC-By-SA USPN,Whidou (via Wikimedia) ! Thread Balls: CC0 (via Pixabay) ! Coding Time: derived from KEMUDA Computer Lab (CC-By-SA Andy.aug, via Wikimedia) ! Sound Table: CC0 (via Pexels) ! Dam: CC-By-SA Matthew Hatton (via geograph.org.uk) ! logos: Pivotal, Spring, Twitter and Github logo copyright their respective companies.