6 years later
Krzysztof Ciesielski
@kpciesielski
ScalaUA 2020
22.08.2013, Jonas Boner
16.09.2014 version 2.0
Jonas Bonér, Dave Farley, Roland Kuhn, and Martin Thompson. With the help and refinement of many members in the community.
Kolejny buzzword?
Czy przyjął się tak jak "Mikroserwisy"?
Podzielił los "BigData"?
versus
Główny cel Reactive Manifesto
środki:
możliwości skalowania
(reagowanie na zmiany obciążenia, elastic)
izolowanie błędów (resilient)
łatwiejsze wdrożenia
łatwiejsze utrzymanie
Komunikacja: może być message-driven
Reactive Systems rely on asynchronous message-passing to establish a boundary between components that ensures loose coupling, isolation and location transparency. This boundary also provides the means to delegate failures as messages.
Samza, Spark Streaming, Flink, AWS Kinesis
Rozwój napędzany przez Machine Learning
Dlaczego reactive?
elastic, fault-tolerant (resilience)
"reagowanie na zmiany"
Eksplozja DevOps/Cloud
Kubernetes, usługi AWS (np Fargate), systemy monitoringu i automatycznego reagowania (np VictorOps)
Praktyki i narzędzia pozwalające budować kod:
Opisujący logikę przetwarzania, a nie przepływ sterowania.
Opis transformacji
Observer pattern
Hollywood Principle ("Don't call us, we'll call you")
Źródło: https://www.tomaszezula.com/2018/12/10/observer-pattern-in-rxjava/
Future[T] / scalaz Task[T]
Actor Model
RxJava
Vert.x
2014
Co się dzieje w ekosystemie
Reactive Streams
Akka Streams
scalaz-stream
Apache Kafka 0.8.1
2014
Co się dzieje w ekosystemie
Vaughn Vernon
Reactive Messaging Patterns with the Actor Model
2015
Work Pulling (Akka)
Źródło: https://redsigil.weebly.com/home/akka-work-pulling-pattern-and-some-background
Project Reactor (Java)
Żródło: https://speakerdeck.com/simonbasle/projectreactor-dot-io-reactor3-intro
2015
Żródło: https://speakerdeck.com/simonbasle/projectreactor-dot-io-reactor3-intro
Project Reactor (Java)
2015
Spring Framework 5 embraces Reactive Streams and Reactor for its own reactive use as well as in many of its core APIs.
2016
Źródło: http://mdabrowski.net/spring-boot-2-reaktywny-spring-webflux/
Akka Persistence, Streams + Alpakka
Kafka 2.3
RxJava
Vert.x
Functional Reactive Programming (FRP)
Cats-Effect, ZIO, Monix
JEE: Asynchronous CDI Events?
2019
val streamGraph = tweets
.filter(_.hashtags contains akkaTag)
.buffer(1000)
.map(t => 1)
.toMat(Sink.fold[Int, Int](0)(_ + _))(Keep.right)
val result: Future[Int] = streamGraph.run()
2019
val streamGraph = tweets
.filter(_.hashtags contains akkaTag)
.buffer(1000)
.map(t => 1)
.toMat(Sink.fold[Int, Int](0)(_ + _))(Keep.right)
val result: Future[Int] = streamGraph.run()
tweets
map
filter
Sink.fold
t
t
t
t
t
t
t
1
Flowable<Tweet> blocking = Flowable
.fromCallable(() -> {
// tweet processing
});
Flowable<Tweet> source = Flowable
.fromIterable(listOf(tweet1, tweet2, tweet3))
Flowable<Any> stream = source
.filter(tweet -> tweet.hashtags.contains(akkaTag))
.flatMap({ a: Tweet -> process(a) }, 3)
def process(tweet: Tweet): Future[ProcessedTweet] = ???
val streamGraph = tweets
.filter(_.hashtags contains akkaTag)
.mapAsync(parallelism = 3)(process)
.toMat(sink)(Keep.right)
tweets
process
filter
process
process
sink
Akka Streams + Alpakka
Kafka 2.3
val ks: UniqueKillSwitch =
RestartSource
.withBackoff(
minBackoff = config.restart.minBackoff,
maxBackoff = config.restart.maxBackoff,
randomFactor = config.restart.randomFactor
)(() => {
eventSource
.via(preProcessFlow)
.via(pipeline)
.via(postProcessFlow)
.withAttributes(supervisionStrategy(decider))
})
.viaMat(KillSwitches.single)(Keep.right)
.toMat(Sink.ignore)(Keep.left)
.run()
2019
Mroczna strona
Tomek Nurkiewicz: "Reactive Programming, lessons learned"
Andrzej Ludwikowski: "Event Sourcing - co może pójść nie tak?"
Jak zacząć?
https://www.lightbend.com/learn/lightbend-reactive-architecture
2019
@kpciesielski
https://softwaremill.com/join-us/