This talk is about going back to the basics, when Reactive Programming was not a buzz and not used in the Enterprise Arena. There will be moments when you will regret being here, but then we will present you with the Beauty of the Seventies. This talk intends to make you travel through time, experiencing how things were done back then. From the Beauty of the Seventies we will move straight to the GoF Observer pattern, which has been implemented over and over again with Publish / Subscriber mechanisms. That will depict the foundations of what we have seen with Functional Programming, Reactive Programming, FRP and Reactive Streams. Although all that sounds interesting, it’s not our last stop. We still have to go over Java 9 and Spring Web Reactive Framework. It embraces Reactive Streams and Reactor, by defying the challenge of switching from imperative-style to non-blocking logic. It might be seem by some as shiny and new, but it’s based on a well established idea that has been helping us for more than 40 years.
2. One doesn’t need to be a subject
matter expert in order to share
knowledge. Whilst the one
sharing must be open to
criticism, the one listening has
to fact check, give feedback and
spread what has been learned.
The sharing process has to be
organic.
2
3. Wilder
Rodrigues
- X-Men; A.I.; and programming geek;
- 21 years hitting keyboards;
- Father of 3;
- Attended Computer Science for 3 years.
@wilderrodrigues
@ekholabs
3
4. What is it
about?
- The foundations
- A glance at FP
- Reactive Programming
- Reactive Streams
- Java 9 & Spring 5
4
11. Propagation of
Changes
By assigning the result of an expression:
a = b + c;
The variable ‘a’ only changes once the
expression is evaluated.
The difference with RP is that ‘a’ will
be updated at any time that ‘b’ or ‘c’
changes.
11
15. Reactive Manifesto
Responsive
Responsiveness is the cornerstone of
usability and utility.
Resilient
It’s achieved by replication,
containment, isolation and delegation.
Elastic
React to changes in the input rate.
Message-Driven
Ensures loose coupling, isolation and
location transparency.
15
16. Tackle the issues
Fully non-blocking and
asynchronous behaviour by enabling
the parallel use of computer
resources.
16
17. Reactive
Generations
0th gen.: consists of j.u.Observable and its
callback cousins addXXXListener() -> JDK 1.0
1st gen.: issues addressed by Meijer & MS
and first libs born -> Rx.NET,
Reactive4Java and RxJava.
2nd gen.: issues on synchronous
cancellation and back-pressure address by
the RxJava team.
17
18. Reactive
Generations
3rd gen.: fix back-pressure properly with
Reactive Stream spec -> 4 interfaces, 30 rules
and 7 methods. Behold the trinity: RxJava 2.x,
Project Reactor and Akka-Streams.
4th gen.: fluent libraries on top of Reactive
Streams spec now called operator-fusion.
5th gen.: extensions to support reactive IO
operations in the form of bi-directional
channels.
18
19. 0th generation -
DDP
Customer API
Observer subscribes to a
Subject for a given data
type.
Transport Stream processing
Parse header.
Feed publisher.
Notify subscribers - if any.
19
21. Interfaces and static methods for establishing flow-
controlled components.
Contains seven “one-way” message style defined
methods.
Non-blocking back pressure with a pull strategy, where
the consumer requests a number of messages to the
producer.
Collaboration between people from Kaazing, Netflix,
Pivotal, Red Hat, Twitter, Typesafe, and others.
21
27. Generators, Operators
and Subscribers
A Flux is a publisher of a sequence of events:
Flux<String> flux = Flux.just("a", "b", “c”);
Mono<String> mono = Mono.just(“a”);
Logging to standard out by calling the .log()
operator:
Flux<String> upper =
flux.log().map(String::toUpperCase);
27
28. Generators, Operators
and Subscribers
Calling .subscribe() will initiate the data
flow:
upper.log()
.map(String::toUpperCase)
.subscribe();
Or with a Consumer or a vanila Runnable:
.subscribe(System.out::println);
28
29. Threads, Schedulers and
Background Processing
Methods to control the thread boundaries:
.subscribeOn(Schedulers.parallel())
Switch processing to separate threads (splitting publisher items to another
publisher):
Flux.just("a", "b", "c")
.log()
.flatMap(value ->
Mono.just(value.toUpperCase())
.subscribeOn(Schedulers.parallel()),
2)
.subscribe(value -> {
log.info("Consumed: " + value);
})
29
30. Threads, Schedulers and
Background Processing
Split production and consumption of the data
with .publishOn():
Flux.just("a", "b", "c")
.log()
.map(String::toUpperCase)
.subscribeOn(Schedulers.parallel("sub"))
.publishOn(Schedulers.parallel("pub"), 2)
.subscribe(value -> {
log.info("Consumed: " + value);
});
30
31. Reactive Web
Reactive web framework:
@[Rest]Controller
programming model, but
on a reactive, non-
blocking engine.
Reactive WebClient with
full back-pressure
support.
31