SlideShare a Scribd company logo
1 of 42
Reactive Streams
Beyond the manifesto
László van den Hoek
• Will code for food since 2008
• Rubix/Lightbend partnership instigator
• Currently @ KLPD 👮🏻 building a data platform
Non-blocking processing with event loops
Non-blocking processing with event loops
Fast producer, slow consumer
OutOfMemoryError
Use cases for managing control flow
• Upstream supply exceeds downstream capacity
• …constantly, but cannot scale downstream
• …occasionally; bursty source.
• Messages need to be processed in-order
• Partitioning and sharding may help, but maybe not enough
• Efficient use of resources
• Provision for what you need, not for what you (could) get
• Concrete example: sensor data
Reactive Streams
• Available since 2013; latest version: 1.0.2 (19-12-2017)
• “asynchronous streams of data with non-blocking back pressure”
• a.k.a. async pull-push flow control
• 4 interfaces, 7 methods, 43 rules for implementors:
• Publisher<T>
• subscribe(Subscriber<? super T> s)
• Subscriber<T>
• onSubscribe(Subscription s), onNext(T t), onError(Throwable t), onComplete()
• Subscription
• request(long n), cancel()
• Processor<T,R> extends Subscriber<T>, Publisher<R>
• Included in Java SE since JDK9 through JEP-266 as java.util.concurrent.Flow.*
• Different implementations can be connected and converted
request(n) request(n)
onNext(t) onNext(t)
Source stream
(Publisher)
Explicit demand model propagates backpressure
Store
(Subscriber)
Processor
Message flow
request(1)
Store
(Subscriber)
request(n)
onNext(t) onNext(t)
Source stream
(Publisher)
Dealing with unbackpressured upstream
Processor
Message flow
DROPDROP
Akka – a JVM implementation of the actor model
• Actors can:
• receive messages
• asynchronously send messages to other actors
• create and supervise child actors
• change their own internal state while processing a message
• When an actor encounters a problem, it will notify its parent, who can either:
• Resume
• Restart
• Stop
• Escalate
History of the Actor model
• Proposed in 1973 by Carl Hewitt
• Implemented in Erlang in 1980’s
– 99.9999999% (!) uptime in telco setting
• Implemented in Scala in 2006
– Had problems
• Akka: separate project started in 2009
– Scala and Java API’s
– Replaced Scala implementation in 2012
– Java API is fully supported and up to date
So what does an actor do?
• Receive messages
• Send messages to any actor address
• Create and supervise child actors
• Change the way it will process the next message
Why is this a good abstraction?
• Explicit about unreliability and handling it
– A slow actor is a dead actor
• Communicate solely by message passing
– eliminates shared state bottleneck
• Scale up for “free*”
– Immutability means parallellizability
Example Actor System
/user/rest
/user/rest/process
/user/rest/process/persist
/user/rest/process/retrieve
Supervision (a.k.a. Let It Crash)
• Resume
– catch(Exception e) {}
Resume
/user/rest
/user/rest/process
/user/rest/process/persist
/user/rest/process/retrieve
Supervision (a.k.a. Let It Crash)
• Resume
– catch(Exception e) {}
• Restart
– this = new Child()
Example Actor System
/user/rest
/user/rest/process
/user/rest/process/persist
/user/rest/process/retrieve
Supervision (a.k.a. Let It Crash)
• Resume
– catch(Exception e) {}
• Restart
– this = new Child()
• Stop
– Parent ! Terminated
Stop
/user/rest
/user/rest/process
/user/rest/process/persist
/user/rest/process/retrieve
Supervision (a.k.a. Let It Crash)
• Resume
– catch(Exception e) {}
• Restart
– this = new Child()
• Stop
– Parent ! Terminated
• Escalate
– throw(e)
Example Actor System
/user/rest
/user/rest/process
/user/rest/process/persist
/user/rest/process/retrieve
Akka-specific features
• On top of the actor model, Akka provides:
– Ordered message arrival
– Scaling out with location transparency
– Tool box with high-level components
• Circuit breaker
Akka-specific features
• On top of the actor model, Akka provides:
– Ordered message arrival
– Scaling out with location transparency
– Tool box with high-level components
• Circuit breaker
Ordered message arrival
• actor.send(m1)
• actor.send(m2)
• In receive() method of actor, you will
never get m2 before m1
actoranyone
m1
m2
Doesn’t hold transitively
• actor1.send(m1)
• actor2.send(m2)
• In receive() method of actor1:
– actor2.forward(m1)
actor1
anyone
m1
m2
actor2
m1
No way to tell
what actor2 will see
Akka-specific features
• On top of the actor model, Akka provides:
– Ordered message arrival
– Scaling out with location transparency
– Tool box with high-level components
• Circuit breaker
Location transparency
VM 1
VM 2 VM 3
Akka-specific features
• On top of the actor model, Akka provides:
– Ordered message arrival
– Scaling out with location transparency
– Tool box with high-level components
• Circuit breaker
Circuit breaker
/user/rest
/user/rest/process
/user/rest/process/persist
/user/rest/process/retrieve
Delegate “risky” tasks (e.g. calls over network)
Akka Streams implements Reactive Streams
Publisher Processor Subscriber
Source Flow Sink
implements implements implements
Akka Streams code example: split/aggregate
CompletionStage<List<Integer>> ret =
Source.from(Arrays.asList("1-2-3", "2-3", "3-4"))
.map(s -> Arrays.asList(s.split("-")))
//split all messages into sub-streams
.splitWhen(a -> true)
//now split each collection
.mapConcat(f -> f)
//Sub-streams logic
.map(s -> Integer.valueOf(s))
//aggregate each sub-stream
.reduce((a, b) -> a + b)
//and merge back the result into the original stream
.mergeSubstreams()
.runWith(Sink.seq(), materializer);
//result: List(6, 5, 7)
Akka HTTP
• Built on top of Akka Streams
• HTTP requests and responses are represented with Akka Streams types:
• Requests as Source<HttpRequest, ?>
• Responses as Sink<HttpResponse, ?>
• Message bodies as Source<ByteString, ?>
Reactive Enterprise Integration using Akka
• System integration in a nutshell:
• Input
• Transform
• Output
• Camel lets you define these separately, but no native streaming support
• RxJava lets you define streams, but not in a reusable way
• Akka Streams lets you define reusable, reactive components
• Akka HTTP is an async HTTP client built on top of Akka Streams
• Alpakka provides a set of backpressure-aware components…
Alpaca?
val jmsSource: Source[String, KillSwitch] =
JmsConsumer.textSource( // (1)
JmsConsumerSettings(connectionFactory).withBufferSize(10).withQueue("test")
)
val webSocketFlow: Flow[ws.Message, ws.Message, Future[WebSocketUpgradeResponse]] = // (2)
Http().webSocketClientFlow(WebSocketRequest("ws://localhost:8080/webSocket/ping"))
val (runningSource, wsUpgradeResponse): (KillSwitch, Future[WebSocketUpgradeResponse]) =
// stream element type
jmsSource //: String
.map(ws.TextMessage(_)) //: ws.TextMessage (3)
.viaMat(webSocketFlow)(Keep.both) //: ws.TextMessage (4)
.mapAsync(1)(wsMessageToString) //: String (5)
.map("client received: " + _) //: String (6)
.toMat(Sink.foreach(println))(Keep.left) // (7)
.run()
Alpakka connectors
• AMQP Connector
• Apache Geode
connector
• Apache Solr
Connector
• AWS DynamoDB
Connector
• AWS Kinesis
Connector
• AWS Lambda
Connector
• AWS S3 Connector
• AWS SNS Connector
• AWS SQS Connector
• MongoDB Connector
• MQTT Connector
• OrientDB Connector
• Server-sent Events
(SSE) Connector
• Slick (JDBC)
Connector
• Spring Web
• Unix Domain Socket
Connector
• File IO
• Azure Storage Queue
Connector
• Cassandra Connector
• Elasticsearch
Connector
• File Connectors
• FTP Connector
• Google Cloud Pub/Sub
• Google Firebase Cloud
Messaging
• HBase connector
• IronMq Connector
• JMS Connector
• Azure
• AWS Kinesis
• Camel
• Eventuate
• FS2
• HTTP Client
• MongoDB
• Kafka
• Pulsar
• TCP
Akka
Actors
Akka Streams
Akka HTTP
Alpakka
Reactive
Streams
Vert.X : Akka
≡
Containers : λ
RxJava is backwards compatible
• Android does not fully support Java 8; support for java.util.function.* only since Android 7.0
• RxJava (including 2.x) targets Android 2.3+  JDK 6
• Own set of interfaces to support FP
• Extra adapter classes needed for Reactive Streams
Links
• Konrad Malawski - Why Reactive? http://www.oreilly.com/programming/free/files/why-reactive.pdf

More Related Content

What's hot

Kafkaesque days at linked in in 2015
Kafkaesque days at linked in in 2015Kafkaesque days at linked in in 2015
Kafkaesque days at linked in in 2015
Joel Koshy
 
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
confluent
 
Running large scale Kafka upgrades at Yelp (Manpreet Singh,Yelp) Kafka Summit...
Running large scale Kafka upgrades at Yelp (Manpreet Singh,Yelp) Kafka Summit...Running large scale Kafka upgrades at Yelp (Manpreet Singh,Yelp) Kafka Summit...
Running large scale Kafka upgrades at Yelp (Manpreet Singh,Yelp) Kafka Summit...
confluent
 

What's hot (20)

Akka and Kubernetes: Reactive From Code To Cloud
Akka and Kubernetes: Reactive From Code To CloudAkka and Kubernetes: Reactive From Code To Cloud
Akka and Kubernetes: Reactive From Code To Cloud
 
Non-blocking IO to tame distributed systems ー How and why ChatWork uses async...
Non-blocking IO to tame distributed systems ー How and why ChatWork uses async...Non-blocking IO to tame distributed systems ー How and why ChatWork uses async...
Non-blocking IO to tame distributed systems ー How and why ChatWork uses async...
 
What’s expected in Spring 5
What’s expected in Spring 5What’s expected in Spring 5
What’s expected in Spring 5
 
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
 
Building Eventing Systems for Microservice Architecture
Building Eventing Systems for Microservice Architecture  Building Eventing Systems for Microservice Architecture
Building Eventing Systems for Microservice Architecture
 
Designing for Distributed Systems with Reactor and Reactive Streams
Designing for Distributed Systems with Reactor and Reactive StreamsDesigning for Distributed Systems with Reactor and Reactive Streams
Designing for Distributed Systems with Reactor and Reactive Streams
 
Bootstrapping Microservices with Kafka, Akka and Spark
Bootstrapping Microservices with Kafka, Akka and SparkBootstrapping Microservices with Kafka, Akka and Spark
Bootstrapping Microservices with Kafka, Akka and Spark
 
Event Driven Architectures with Camel
Event Driven Architectures with CamelEvent Driven Architectures with Camel
Event Driven Architectures with Camel
 
Kafkaesque days at linked in in 2015
Kafkaesque days at linked in in 2015Kafkaesque days at linked in in 2015
Kafkaesque days at linked in in 2015
 
Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Reactive Design Patterns: a talk by Typesafe's Dr. Roland KuhnReactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
 
Time Machine
Time MachineTime Machine
Time Machine
 
A Journey to Reactive Function Programming
A Journey to Reactive Function ProgrammingA Journey to Reactive Function Programming
A Journey to Reactive Function Programming
 
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
 
Architecture of Falcon, a new chat messaging backend system build on Scala
Architecture of Falcon,  a new chat messaging backend system  build on ScalaArchitecture of Falcon,  a new chat messaging backend system  build on Scala
Architecture of Falcon, a new chat messaging backend system build on Scala
 
Kafka reliability velocity 17
Kafka reliability   velocity 17Kafka reliability   velocity 17
Kafka reliability velocity 17
 
Why Actor-Based Systems Are The Best For Microservices
Why Actor-Based Systems Are The Best For MicroservicesWhy Actor-Based Systems Are The Best For Microservices
Why Actor-Based Systems Are The Best For Microservices
 
Running large scale Kafka upgrades at Yelp (Manpreet Singh,Yelp) Kafka Summit...
Running large scale Kafka upgrades at Yelp (Manpreet Singh,Yelp) Kafka Summit...Running large scale Kafka upgrades at Yelp (Manpreet Singh,Yelp) Kafka Summit...
Running large scale Kafka upgrades at Yelp (Manpreet Singh,Yelp) Kafka Summit...
 
Introducing Exactly Once Semantics To Apache Kafka
Introducing Exactly Once Semantics To Apache KafkaIntroducing Exactly Once Semantics To Apache Kafka
Introducing Exactly Once Semantics To Apache Kafka
 
8th Athens Big Data Meetup - 1st Talk - Riding The Streaming Wave DIY Style
8th Athens Big Data Meetup - 1st Talk - Riding The Streaming Wave DIY Style8th Athens Big Data Meetup - 1st Talk - Riding The Streaming Wave DIY Style
8th Athens Big Data Meetup - 1st Talk - Riding The Streaming Wave DIY Style
 
Making Scala Faster: 3 Expert Tips For Busy Development Teams
Making Scala Faster: 3 Expert Tips For Busy Development TeamsMaking Scala Faster: 3 Expert Tips For Busy Development Teams
Making Scala Faster: 3 Expert Tips For Busy Development Teams
 

Similar to Reactive Streams - László van den Hoek

Agile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKAAgile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKA
Paolo Platter
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
Konrad Malawski
 
Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011
Raymond Roestenburg
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
Yung-Lin Ho
 
Apache Kafka
Apache KafkaApache Kafka
Apache Kafka
Joe Stein
 
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lightbend
 

Similar to Reactive Streams - László van den Hoek (20)

Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015
 
Journey into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsJourney into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka Streams
 
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCBuilding a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
 
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
 
Actor model in .NET - Akka.NET
Actor model in .NET - Akka.NETActor model in .NET - Akka.NET
Actor model in .NET - Akka.NET
 
Agile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKAAgile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKA
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
 
Reactive Streams 1.0 and Akka Streams
Reactive Streams 1.0 and Akka StreamsReactive Streams 1.0 and Akka Streams
Reactive Streams 1.0 and Akka Streams
 
Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka Cluster
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and Reactor
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NETDotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
 
Akka.Net Overview
Akka.Net OverviewAkka.Net Overview
Akka.Net Overview
 
Streaming and Messaging
Streaming and MessagingStreaming and Messaging
Streaming and Messaging
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
 
Apache Kafka
Apache KafkaApache Kafka
Apache Kafka
 
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
 

More from RubiX BV

More from RubiX BV (11)

Reactive programming - Dirk Janssen (presentation 13th SPIN Meetup)
Reactive programming - Dirk Janssen (presentation 13th SPIN Meetup)Reactive programming - Dirk Janssen (presentation 13th SPIN Meetup)
Reactive programming - Dirk Janssen (presentation 13th SPIN Meetup)
 
Meetup hip 18 april 2017
Meetup hip 18 april 2017Meetup hip 18 april 2017
Meetup hip 18 april 2017
 
Rubix - Serverless architecture
Rubix - Serverless architectureRubix - Serverless architecture
Rubix - Serverless architecture
 
Crowd Designing Microservices Architecture
Crowd Designing Microservices ArchitectureCrowd Designing Microservices Architecture
Crowd Designing Microservices Architecture
 
Microservices - an integration perspective
Microservices - an integration perspectiveMicroservices - an integration perspective
Microservices - an integration perspective
 
RubiX ID - Big Data - Ruben Middeljans, Stephan Vos
RubiX ID - Big Data - Ruben Middeljans, Stephan VosRubiX ID - Big Data - Ruben Middeljans, Stephan Vos
RubiX ID - Big Data - Ruben Middeljans, Stephan Vos
 
RubiX ID - Continuous Integration & Continuous Delivery - Roel van den Berg, ...
RubiX ID - Continuous Integration & Continuous Delivery - Roel van den Berg, ...RubiX ID - Continuous Integration & Continuous Delivery - Roel van den Berg, ...
RubiX ID - Continuous Integration & Continuous Delivery - Roel van den Berg, ...
 
RubiX ID - SOA Governance - Wouter de Vries
RubiX ID - SOA Governance - Wouter de VriesRubiX ID - SOA Governance - Wouter de Vries
RubiX ID - SOA Governance - Wouter de Vries
 
RubiX ID - SOA Security - Ingrid Cox
RubiX ID - SOA Security - Ingrid CoxRubiX ID - SOA Security - Ingrid Cox
RubiX ID - SOA Security - Ingrid Cox
 
RubiX ID - Tibco business works™ 6 in de praktijk - Bart de Koning en Marcel ...
RubiX ID - Tibco business works™ 6 in de praktijk - Bart de Koning en Marcel ...RubiX ID - Tibco business works™ 6 in de praktijk - Bart de Koning en Marcel ...
RubiX ID - Tibco business works™ 6 in de praktijk - Bart de Koning en Marcel ...
 
RubiX ID - API management - Pim Gaemers
RubiX ID - API management - Pim GaemersRubiX ID - API management - Pim Gaemers
RubiX ID - API management - Pim Gaemers
 

Recently uploaded

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 

Reactive Streams - László van den Hoek

  • 2. László van den Hoek • Will code for food since 2008 • Rubix/Lightbend partnership instigator • Currently @ KLPD 👮🏻 building a data platform
  • 5. Fast producer, slow consumer OutOfMemoryError
  • 6. Use cases for managing control flow • Upstream supply exceeds downstream capacity • …constantly, but cannot scale downstream • …occasionally; bursty source. • Messages need to be processed in-order • Partitioning and sharding may help, but maybe not enough • Efficient use of resources • Provision for what you need, not for what you (could) get • Concrete example: sensor data
  • 7. Reactive Streams • Available since 2013; latest version: 1.0.2 (19-12-2017) • “asynchronous streams of data with non-blocking back pressure” • a.k.a. async pull-push flow control • 4 interfaces, 7 methods, 43 rules for implementors: • Publisher<T> • subscribe(Subscriber<? super T> s) • Subscriber<T> • onSubscribe(Subscription s), onNext(T t), onError(Throwable t), onComplete() • Subscription • request(long n), cancel() • Processor<T,R> extends Subscriber<T>, Publisher<R> • Included in Java SE since JDK9 through JEP-266 as java.util.concurrent.Flow.* • Different implementations can be connected and converted
  • 8. request(n) request(n) onNext(t) onNext(t) Source stream (Publisher) Explicit demand model propagates backpressure Store (Subscriber) Processor Message flow
  • 9. request(1) Store (Subscriber) request(n) onNext(t) onNext(t) Source stream (Publisher) Dealing with unbackpressured upstream Processor Message flow DROPDROP
  • 10. Akka – a JVM implementation of the actor model • Actors can: • receive messages • asynchronously send messages to other actors • create and supervise child actors • change their own internal state while processing a message • When an actor encounters a problem, it will notify its parent, who can either: • Resume • Restart • Stop • Escalate
  • 11. History of the Actor model • Proposed in 1973 by Carl Hewitt • Implemented in Erlang in 1980’s – 99.9999999% (!) uptime in telco setting • Implemented in Scala in 2006 – Had problems • Akka: separate project started in 2009 – Scala and Java API’s – Replaced Scala implementation in 2012 – Java API is fully supported and up to date
  • 12. So what does an actor do? • Receive messages • Send messages to any actor address • Create and supervise child actors • Change the way it will process the next message
  • 13. Why is this a good abstraction? • Explicit about unreliability and handling it – A slow actor is a dead actor • Communicate solely by message passing – eliminates shared state bottleneck • Scale up for “free*” – Immutability means parallellizability
  • 15. Supervision (a.k.a. Let It Crash) • Resume – catch(Exception e) {}
  • 17. Supervision (a.k.a. Let It Crash) • Resume – catch(Exception e) {} • Restart – this = new Child()
  • 19. Supervision (a.k.a. Let It Crash) • Resume – catch(Exception e) {} • Restart – this = new Child() • Stop – Parent ! Terminated
  • 21. Supervision (a.k.a. Let It Crash) • Resume – catch(Exception e) {} • Restart – this = new Child() • Stop – Parent ! Terminated • Escalate – throw(e)
  • 23. Akka-specific features • On top of the actor model, Akka provides: – Ordered message arrival – Scaling out with location transparency – Tool box with high-level components • Circuit breaker
  • 24. Akka-specific features • On top of the actor model, Akka provides: – Ordered message arrival – Scaling out with location transparency – Tool box with high-level components • Circuit breaker
  • 25. Ordered message arrival • actor.send(m1) • actor.send(m2) • In receive() method of actor, you will never get m2 before m1 actoranyone m1 m2
  • 26. Doesn’t hold transitively • actor1.send(m1) • actor2.send(m2) • In receive() method of actor1: – actor2.forward(m1) actor1 anyone m1 m2 actor2 m1 No way to tell what actor2 will see
  • 27. Akka-specific features • On top of the actor model, Akka provides: – Ordered message arrival – Scaling out with location transparency – Tool box with high-level components • Circuit breaker
  • 29. Akka-specific features • On top of the actor model, Akka provides: – Ordered message arrival – Scaling out with location transparency – Tool box with high-level components • Circuit breaker
  • 31. Delegate “risky” tasks (e.g. calls over network)
  • 32. Akka Streams implements Reactive Streams Publisher Processor Subscriber Source Flow Sink implements implements implements
  • 33. Akka Streams code example: split/aggregate CompletionStage<List<Integer>> ret = Source.from(Arrays.asList("1-2-3", "2-3", "3-4")) .map(s -> Arrays.asList(s.split("-"))) //split all messages into sub-streams .splitWhen(a -> true) //now split each collection .mapConcat(f -> f) //Sub-streams logic .map(s -> Integer.valueOf(s)) //aggregate each sub-stream .reduce((a, b) -> a + b) //and merge back the result into the original stream .mergeSubstreams() .runWith(Sink.seq(), materializer); //result: List(6, 5, 7)
  • 34. Akka HTTP • Built on top of Akka Streams • HTTP requests and responses are represented with Akka Streams types: • Requests as Source<HttpRequest, ?> • Responses as Sink<HttpResponse, ?> • Message bodies as Source<ByteString, ?>
  • 35. Reactive Enterprise Integration using Akka • System integration in a nutshell: • Input • Transform • Output • Camel lets you define these separately, but no native streaming support • RxJava lets you define streams, but not in a reusable way • Akka Streams lets you define reusable, reactive components • Akka HTTP is an async HTTP client built on top of Akka Streams • Alpakka provides a set of backpressure-aware components…
  • 37. val jmsSource: Source[String, KillSwitch] = JmsConsumer.textSource( // (1) JmsConsumerSettings(connectionFactory).withBufferSize(10).withQueue("test") ) val webSocketFlow: Flow[ws.Message, ws.Message, Future[WebSocketUpgradeResponse]] = // (2) Http().webSocketClientFlow(WebSocketRequest("ws://localhost:8080/webSocket/ping")) val (runningSource, wsUpgradeResponse): (KillSwitch, Future[WebSocketUpgradeResponse]) = // stream element type jmsSource //: String .map(ws.TextMessage(_)) //: ws.TextMessage (3) .viaMat(webSocketFlow)(Keep.both) //: ws.TextMessage (4) .mapAsync(1)(wsMessageToString) //: String (5) .map("client received: " + _) //: String (6) .toMat(Sink.foreach(println))(Keep.left) // (7) .run()
  • 38. Alpakka connectors • AMQP Connector • Apache Geode connector • Apache Solr Connector • AWS DynamoDB Connector • AWS Kinesis Connector • AWS Lambda Connector • AWS S3 Connector • AWS SNS Connector • AWS SQS Connector • MongoDB Connector • MQTT Connector • OrientDB Connector • Server-sent Events (SSE) Connector • Slick (JDBC) Connector • Spring Web • Unix Domain Socket Connector • File IO • Azure Storage Queue Connector • Cassandra Connector • Elasticsearch Connector • File Connectors • FTP Connector • Google Cloud Pub/Sub • Google Firebase Cloud Messaging • HBase connector • IronMq Connector • JMS Connector • Azure • AWS Kinesis • Camel • Eventuate • FS2 • HTTP Client • MongoDB • Kafka • Pulsar • TCP
  • 41. RxJava is backwards compatible • Android does not fully support Java 8; support for java.util.function.* only since Android 7.0 • RxJava (including 2.x) targets Android 2.3+  JDK 6 • Own set of interfaces to support FP • Extra adapter classes needed for Reactive Streams
  • 42. Links • Konrad Malawski - Why Reactive? http://www.oreilly.com/programming/free/files/why-reactive.pdf

Editor's Notes

  1. If the downstream does not signal demand, the upstream does not request any more items.
  2. If the downstream does not signal demand, the upstream does not request any more items.
  3. http://channel9.msdn.com/Shows/Going+Deep/Hewitt-Meijer-and-Szyperski-The-Actor-Model-everything-you-wanted-to-know-but-were-afraid-to-ask http://stackoverflow.com/questions/8426897/erlangs-99-9999999-nine-nines-reliability
  4. *: you still need to program it that way!
  5. http://doc.akka.io/docs/akka/snapshot/scala/fault-tolerance.html
  6. http://doc.akka.io/docs/akka/snapshot/scala/fault-tolerance.html
  7. http://doc.akka.io/docs/akka/snapshot/scala/fault-tolerance.html
  8. http://doc.akka.io/docs/akka/snapshot/scala/fault-tolerance.html
  9. http://www.slideshare.net/jboner/introducing-akka
  10. http://www.slideshare.net/jboner/introducing-akka
  11. http://www.slideshare.net/jboner/introducing-akka
  12. http://www.slideshare.net/jboner/introducing-akka