akka streams
Reactive Integrations with
that just work™
Johan Andrén
Konrad Malawski
Johan Andrén
Akka Team
Stockholm Scala User Group
Konrad `ktoso` Malawski
Akka Team,
Reactive Streams TCK,
Persistence, HTTP
Special thanks
Make building powerful concurrent &
distributed applications simple.
Akka is a toolkit and runtime
for building highly concurrent,
distributed, and resilient
message-driven applications
on the JVM
Actors – simple & high performance concurrency
Cluster / Remoting – location transparency, resilience
Cluster tools – and more prepackaged patterns
Streams – back-pressured stream processing
Persistence – Event Sourcing
HTTP – complete, fully async and reactive HTTP Server
Official Kafka, Cassandra, DynamoDB integrations, tons
more in the community
Complete Java & Scala APIs for all features
What’s in the toolkit?
“Stream”
has many meanings
akka streams
Asynchronous back pressured stream processing
Source Sink
Process
akka streams
Asynchronous back pressured stream processing
Source Sink
Process
(possible)
asynchronous
boundaries
akka streams
Asynchronous back pressured stream processing
Source Sink
Process
10 msg/s 1 msg/s
OutOfMemoryError!!
akka streams
Asynchronous back pressured stream processing
Source Sink
Process
10 msg/s 1 msg/s
hand me 3 morehand me 3 more
1 msg/s
akka streams
Not only linear streams
Source
SinkProcess
Source
Sink
Process Process
Reactive Streams
Reactive Streams is an initiative to provide a standard for
asynchronous stream processing with non-blocking back
pressure. This encompasses efforts aimed at runtime
environments (JVM and JavaScript) as well as network
protocols
http://www.reactive-streams.org
Reactive Streams
RS Library A RS library B
async
boundary
Reactive Streams
RS Library A RS library B
async
boundary
Make building powerful concurrent &
distributed applications simple.
The API
Akka Streams
Complete and awesome
Java and Scala APIs
(Just like everything in Akka)
Akka Streams in 20 seconds:
Source<Integer, NotUsed> source = null;



Flow<Integer, String, NotUsed> flow =

Flow.<Integer>create().map((Integer n) -> n.toString());



Sink<String, CompletionStage<String>> sink =

Sink.foreach(str -> System.out.println(str));



RunnableGraph<NotUsed> runnable =
source.via(flow).to(sink);



runnable.run(materializer);

Akka Streams in 20 seconds:
CompletionStage<Done> done =

Source.single(42)

.map(n -> n.toString())

.runForeach(System.out::println, materializer);

Akka Streams in 20 seconds:
CompletionStage<String> firstString =

Source.single(1)

.map(n -> n.toString())

.runWith(Sink.head(), materializer);

Source.single(1).map(i -> i.toString).runWith(Sink.head())
// types: _
Source<Int, NotUsed>
Flow<Int, String, NotUsed>
Sink<String, CompletionStage<String>>
Akka Streams in 20 seconds:
Materialization
Gears from GeeCON.org,(it’s an awesome conf)
What is “materialization” really?
What is “materialization” really?
What is “materialization” really?
What is “materialization” really?
AlpA community for Streams connectors
http://blog.akka.io/integrations/2016/08/23/intro-alpakka
Alpakka – a community for Stream connectors
Threading & Concurrency in Akka Streams Explained (part I)
Mastering GraphStages (part I, Introduction)
Akka Streams Integration, codename Alpakka
A gentle introduction to building Sinks and Sources using GraphStage APIs
(Mastering GraphStages, Part II)
Writing Akka Streams Connectors for existing APIs
Flow control at the boundary of Akka Streams and a data provider
Akka Streams Kafka 0.11
Alpakka – a community for Stream connectors
Existing examples:
MQTT
AMQP
Streaming HTTP
Streaming TCP
Streaming FileIO
Cassandra Queries
“Reactive Kafka” (akka-stream-kafka)
S3, SQS & other Amazon APIs
Streaming JSON
Streaming XML
Alpakka – a community for Stream connectors
Demo
Alpakka – a community for Stream connectors
Demo
Akka Streams & HTTP
streams
& HTTP
Streaming in Akka HTTP
http://doc.akka.io/docs/akka/2.4.7/scala/stream/stream-customize.html#graphstage-scala
“Framed entity streaming” https://github.com/akka/akka/pull/20778
HttpServer as a:
Flow[HttpRequest, HttpResponse]
Streaming in Akka HTTP
http://doc.akka.io/docs/akka/2.4.7/scala/stream/stream-customize.html#graphstage-scala
“Framed entity streaming” https://github.com/akka/akka/pull/20778
HttpServer as a:
Flow[HttpRequest, HttpResponse]
HTTP Entity as a:
Source[ByteString, _]
Streaming from Akka HTTP
Streaming from Akka HTTP
Streaming from Akka HTTP
No demand from TCP
=
No demand upstream
=
Source won’t generate tweets
=>
Bounded memory
stream processing!
Demo
Akka <3 contributions
Easy to contribute tickets:
https://github.com/akka/akka/issues?q=is%3Aissue+is%3Aopen+label%3Aeasy-to-contribute
https://github.com/akka/akka/issues?q=is%3Aissue+is%3Aopen+label%3A%22nice-to-have+%28low-prio%29%22
Akka Stream Contrib
https://github.com/akka/akka-stream-contrib
Mailing list:
https://groups.google.com/group/akka-user
Public chat rooms:
http://gitter.im/akka/dev developing Akka
http://gitter.im/akka/akka using Akka
Thanks for listening!
@apnylle
blog.akka.io
markatta.com/codemonkey
johan.andren@lightbend.com
Sample sources
https://github.com/johanandren/akka-stream-samples/tree/vjug24

VJUG24 - Reactive Integrations with Akka Streams

  • 1.
    akka streams Reactive Integrationswith that just work™ Johan Andrén Konrad Malawski
  • 2.
  • 3.
    Konrad `ktoso` Malawski AkkaTeam, Reactive Streams TCK, Persistence, HTTP Special thanks
  • 4.
    Make building powerfulconcurrent & distributed applications simple. Akka is a toolkit and runtime for building highly concurrent, distributed, and resilient message-driven applications on the JVM
  • 5.
    Actors – simple& high performance concurrency Cluster / Remoting – location transparency, resilience Cluster tools – and more prepackaged patterns Streams – back-pressured stream processing Persistence – Event Sourcing HTTP – complete, fully async and reactive HTTP Server Official Kafka, Cassandra, DynamoDB integrations, tons more in the community Complete Java & Scala APIs for all features What’s in the toolkit?
  • 7.
  • 8.
    akka streams Asynchronous backpressured stream processing Source Sink Process
  • 9.
    akka streams Asynchronous backpressured stream processing Source Sink Process (possible) asynchronous boundaries
  • 10.
    akka streams Asynchronous backpressured stream processing Source Sink Process 10 msg/s 1 msg/s OutOfMemoryError!!
  • 11.
    akka streams Asynchronous backpressured stream processing Source Sink Process 10 msg/s 1 msg/s hand me 3 morehand me 3 more 1 msg/s
  • 12.
    akka streams Not onlylinear streams Source SinkProcess Source Sink Process Process
  • 13.
    Reactive Streams Reactive Streamsis an initiative to provide a standard for asynchronous stream processing with non-blocking back pressure. This encompasses efforts aimed at runtime environments (JVM and JavaScript) as well as network protocols http://www.reactive-streams.org
  • 14.
    Reactive Streams RS LibraryA RS library B async boundary
  • 15.
    Reactive Streams RS LibraryA RS library B async boundary Make building powerful concurrent & distributed applications simple.
  • 16.
    The API Akka Streams Completeand awesome Java and Scala APIs (Just like everything in Akka)
  • 17.
    Akka Streams in20 seconds: Source<Integer, NotUsed> source = null;
 
 Flow<Integer, String, NotUsed> flow =
 Flow.<Integer>create().map((Integer n) -> n.toString());
 
 Sink<String, CompletionStage<String>> sink =
 Sink.foreach(str -> System.out.println(str));
 
 RunnableGraph<NotUsed> runnable = source.via(flow).to(sink);
 
 runnable.run(materializer);

  • 18.
    Akka Streams in20 seconds: CompletionStage<Done> done =
 Source.single(42)
 .map(n -> n.toString())
 .runForeach(System.out::println, materializer);

  • 19.
    Akka Streams in20 seconds: CompletionStage<String> firstString =
 Source.single(1)
 .map(n -> n.toString())
 .runWith(Sink.head(), materializer);

  • 20.
    Source.single(1).map(i -> i.toString).runWith(Sink.head()) //types: _ Source<Int, NotUsed> Flow<Int, String, NotUsed> Sink<String, CompletionStage<String>> Akka Streams in 20 seconds:
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
    AlpA community forStreams connectors http://blog.akka.io/integrations/2016/08/23/intro-alpakka
  • 27.
    Alpakka – acommunity for Stream connectors Threading & Concurrency in Akka Streams Explained (part I) Mastering GraphStages (part I, Introduction) Akka Streams Integration, codename Alpakka A gentle introduction to building Sinks and Sources using GraphStage APIs (Mastering GraphStages, Part II) Writing Akka Streams Connectors for existing APIs Flow control at the boundary of Akka Streams and a data provider Akka Streams Kafka 0.11
  • 28.
    Alpakka – acommunity for Stream connectors Existing examples: MQTT AMQP Streaming HTTP Streaming TCP Streaming FileIO Cassandra Queries “Reactive Kafka” (akka-stream-kafka) S3, SQS & other Amazon APIs Streaming JSON Streaming XML
  • 29.
    Alpakka – acommunity for Stream connectors Demo
  • 30.
    Alpakka – acommunity for Stream connectors Demo
  • 31.
    Akka Streams &HTTP streams & HTTP
  • 32.
    Streaming in AkkaHTTP http://doc.akka.io/docs/akka/2.4.7/scala/stream/stream-customize.html#graphstage-scala “Framed entity streaming” https://github.com/akka/akka/pull/20778 HttpServer as a: Flow[HttpRequest, HttpResponse]
  • 33.
    Streaming in AkkaHTTP http://doc.akka.io/docs/akka/2.4.7/scala/stream/stream-customize.html#graphstage-scala “Framed entity streaming” https://github.com/akka/akka/pull/20778 HttpServer as a: Flow[HttpRequest, HttpResponse] HTTP Entity as a: Source[ByteString, _]
  • 34.
  • 35.
  • 36.
    Streaming from AkkaHTTP No demand from TCP = No demand upstream = Source won’t generate tweets => Bounded memory stream processing! Demo
  • 37.
    Akka <3 contributions Easyto contribute tickets: https://github.com/akka/akka/issues?q=is%3Aissue+is%3Aopen+label%3Aeasy-to-contribute https://github.com/akka/akka/issues?q=is%3Aissue+is%3Aopen+label%3A%22nice-to-have+%28low-prio%29%22 Akka Stream Contrib https://github.com/akka/akka-stream-contrib Mailing list: https://groups.google.com/group/akka-user Public chat rooms: http://gitter.im/akka/dev developing Akka http://gitter.im/akka/akka using Akka
  • 38.
    Thanks for listening! @apnylle blog.akka.io markatta.com/codemonkey johan.andren@lightbend.com Samplesources https://github.com/johanandren/akka-stream-samples/tree/vjug24