The term 'streams' has been getting pretty overloaded recently–it's hard to know where to best use different technologies with streams in the name. In this talk by noted hAkker Konrad Malawski, we'll disambiguate what streams are and what they aren't, taking a deeper look into Akka Streams (the implementation) and Reactive Streams (the standard).
You'll be introduced to a number of real life scenarios where applying back-pressure helps to keep your systems fast and healthy at the same time. While the focus is mainly on the Akka Streams implementation, the general principles apply to any kind of asynchronous, message-driven architectures.
25. Fast Publisher will send at-most 3 elements.
This is pull-based-backpressure.
Reactive Streams: “dynamic push/pull”
26. JEP-266 – soon…!
public final class Flow {
private Flow() {} // uninstantiable
@FunctionalInterface
public static interface Publisher<T> {
public void subscribe(Subscriber<? super T> subscriber);
}
public static interface Subscriber<T> {
public void onSubscribe(Subscription subscription);
public void onNext(T item);
public void onError(Throwable throwable);
public void onComplete();
}
public static interface Subscription {
public void request(long n);
public void cancel();
}
public static interface Processor<T,R> extends Subscriber<T>, Publisher<R> {
}
}
27. Reactive Streams: goals
1) Avoiding unbounded buffering across async boundaries
2)Inter-op interfaces between various libraries
28. Reactive Streams: goals
1) Avoiding unbounded buffering across async boundaries
2)Inter-op interfaces between various libraries
Argh, implementing a correct RS Publisher
or Subscriber is so hard!
29. Reactive Streams: goals
1) Avoiding unbounded buffering across async boundaries
2)Inter-op interfaces between various libraries
Argh, implementing a correct
RS Publisher or Subscriber is so hard!
30. Reactive Streams: goals
1) Avoiding unbounded buffering across async boundaries
2)Inter-op interfaces between various libraries
Argh, implementing a correct
RS Publisher or Subscriber is so hard!
You should be using
Akka Streams abstractions instead!
31. Akka Streams
Streams complement Actors,
they do not replace them.
Actors – distribution (location transparency)
Streams – back-pressured + more rigid-blueprint
32. Akka is a Toolkit, pick the right tools for the job.
Runar’s excellent talk @ Scala.World 2015
Asynchronous processing toolbox:
Power
Constraints
33. Akka is a Toolkit, pick the right tools for the job.
Asynchronous processing toolbox:
Constraints
Power
34. Akka is a Toolkit, pick the right tools for the job.
Single value, no streaming by definition.
Local abstraction.
Execution contexts.
Power
Constraints
35. Akka is a Toolkit, pick the right tools for the job.
Mostly static processing layouts.
Well typed and Back-pressured!
Constraints
Power
36. Akka is a Toolkit, pick the right tools for the job.
Plain Actor’s younger brother, experimental.
Location transparent, well typed.
Technically unconstrained in actions performed
Constraints
Power
37. Akka is a Toolkit, pick the right tools for the job.
Runar’s excellent talk @ Scala.World 2015
Location transparent.
Various resilience mechanisms.
(watching, persistent recovering, migration, pools)
Untyped and unconstrained in actions performed.
Constraints
Power
48. Akka HTTP
Joint effort of Spray and Akka teams.
Complete HTTP Server/Client implementation.
Learns from Spray’s 3-4 years history.
Since the beginning with
streaming as first class citizen.
Side note:
Lagom also utilises Akka Streams for streaming.
49. Streaming in Akka HTTP
DEMO
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]
50. Streaming in Akka HTTP
DEMO
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, _]
51. Streaming in Akka HTTP
DEMO
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, _]
Websocket connection as a:
Flow[ws.Message, ws.Message]
56. Kafka + Akka = BFF
Akka is Arbitrary processing.
Kafka is somewhat more than a message queue,
but very focused on “the log”.
Spark shines with it’s data-science focus.
62. Next steps for Akka
Completely new Akka Remoting (goal: 1M+ msg/s (!)),
(it is built using Akka Streams).
More integrations for Akka Streams stages,
also dynamic fan-in/out A.K.A.“the Hub”.
Reactive Kafka polishing and stable release with SoftwareMill.
“Confirmed Streams” work from Reactive Kafka generalised.
Akka Typed likely to progress again.
Of course, continued maintenance of Cluster and others.
63. Upgrade your grey matter
Two free O’Reilly eBooks by Lightbend
DOWNLOAD NOWDOWNLOAD NOW