101
Reactive
Programming
types &
operators
Reactor 3
and Spring
Reactor
debugging
testing
and
other beasts
backpressure
and
Slide 4
Slide 4 text
101
Reactive
Programming
types &
operators
Reactor 3
and Spring
Reactor
debugging
testing
and
reactor-netty
other beasts
backpressure
and
reactor-kafka...
Slide 5
Slide 5 text
Reactive Programming 101
what does it bring to the table?
Slide 6
Slide 6 text
WHY?
because blocking is evil
Slide 7
Slide 7 text
sync/blocking
main thread processing
resumes
I/O
BAD
! app does
nothing
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
processing
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
subscribeOn
make the subscription and request happen
on a particular thread
Slide 74
Slide 74 text
Flux/Mono
generator
operator
subscribeO
n
operator
publishOn
operator
operator
Subscriber
Sub
Sub
Sub
Sub
Sub
Sub
Slide 75
Slide 75 text
Flux/Mono
generator
operator
subscribe
On
operator
publish
On
operator
operator
Subscriber
Sub
Sub
Sub
Sub
Sub
Sub
Slide 76
Slide 76 text
Flux/Mono
generator
operator
subscribeO
n
operator
publishOn
operator
operator
Subscriber
Sub
Sub
Sub
Sub
Sub
Sub
Slide 77
Slide 77 text
Flux/Mono
generator
operator
subscribeO
n
operator
publishOn
operator
operator
Subscriber
Sub
Sub
Sub
Sub
Sub
Sub
Slide 78
Slide 78 text
Flux/Mono
generator
operator
subscribeO
n
operator
publishOn
operator
operator
Subscriber
Sub
Sub
Sub
Sub
Sub
Sub
Slide 79
Slide 79 text
Flux/Mono
generator
operator
subscribeO
n
operator
publishOn
operator
operator
Subscriber
Sub
Sub
Sub
Sub
Sub
Sub
Slide 80
Slide 80 text
Testing & Debugging
in an asynchronous world
Slide 81
Slide 81 text
Testing a Publisher
StepVerifier
Slide 82
Slide 82 text
Testing a Publisher
with Virtual Time support
Slide 83
Slide 83 text
Simulate a source
TestPublisher
Slide 84
Slide 84 text
Debugging Issues
stacktraces get hard to decipher
Slide 85
Slide 85 text
usually just show
where Subscription happens
Slide 86
Slide 86 text
java.lang.IndexOutOfBoundsException: Source emitted more than one item
at reactor.core.publisher.MonoSingle$SingleSubscriber.onNext(MonoSingle.java:120)
at
reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onNext(FluxOnAssembly.java:314)
...
...
at reactor.core.publisher.Mono.subscribeWith(Mono.java:2668)
at reactor.core.publisher.Mono.subscribe(Mono.java:2629)
at reactor.core.publisher.Mono.subscribe(Mono.java:2604)
at reactor.core.publisher.Mono.subscribe(Mono.java:2582)
at reactor.guide.GuideTests.debuggingActivated(GuideTests.java:727)
Slide 87
Slide 87 text
Find where the Flux
was instantiated (assembly)
Slide 88
Slide 88 text
Checkpoint()
or full assembly tracing
Slide 89
Slide 89 text
costly!
Checkpoint()
or full assembly tracing
Slide 90
Slide 90 text
Assembly trace from producer [reactor.core.publisher.MonoSingle] :
reactor.core.publisher.Flux.single(Flux.java:5335)
reactor.guide.GuideTests.scatterAndGather(GuideTests.java:689)
reactor.guide.GuideTests.populateDebug(GuideTests.java:702)
Slide 91
Slide 91 text
BACKPRESSURE
and other beasts
Slide 92
Slide 92 text
Publisher Subscriber
subscribe
Slide 93
Slide 93 text
Publisher Subscriber
push data as fast as possible
Slide 94
Slide 94 text
Publisher Subscriber
subscribe
with small request
(eg. 1)
Slide 95
Slide 95 text
Publisher Subscriber
1 onNext
Slide 96
Slide 96 text
Publisher Subscriber
request more
(eg. 2)
Slide 97
Slide 97 text
Publisher Subscriber
2 onNext
Slide 98
Slide 98 text
Publisher Subscriber
backpressure
Slide 99
Slide 99 text
other ways of dealing with backpressure
eg. drop, buffer...