not only streams for akademia jlabs

156
Konrad `ktoso` Malawski @ ITAkademia J-Labs, 2017 Reactive more than just streams

Upload: konrad-malawski

Post on 11-Apr-2017

322 views

Category:

Technology


6 download

TRANSCRIPT

Page 1: Not Only Streams for Akademia JLabs

Konrad `ktoso` Malawski @ ITAkademia J-Labs, 2017

Reactive more than just streams

Page 2: Not Only Streams for Akademia JLabs

Underlying motto for this talk, and our continued research.

“We can do better than that.”

Page 3: Not Only Streams for Akademia JLabs

Konrad `ktoso` Malawski

Akka Team, Reactive Streams TCK,

Persistence, Streams & HTTP, Core, Remoting

Page 4: Not Only Streams for Akademia JLabs

Konrad `@ktosopl` Malawski

work: akka.io lightbend.com personal blog: http://kto.so

communities: geecon.org Java.pl / KrakowScala.pl sckrk.com GDGKrakow.pl lambdakrk.pl

Page 5: Not Only Streams for Akademia JLabs

Konrad `@ktosopl` Malawski

work: akka.io lightbend.com personal blog: http://kto.so

communities: geecon.org Java.pl / KrakowScala.pl sckrk.com GDGKrakow.pl lambdakrk.pl

Page 6: Not Only Streams for Akademia JLabs
Page 7: Not Only Streams for Akademia JLabs

The concurrent & distributed applications toolkit

Akka is a toolkit and runtime for building highly concurrent, distributed, and resilient message-driven applications on the JVM

Page 8: Not Only Streams for Akademia JLabs

The concurrent & distributed applications toolkit

Akka is a toolkit and runtime for building highly concurrent, distributed, and resilient message-driven applications on the JVM

Page 9: Not Only Streams for Akademia JLabs

Actors – Concurrency / high perf. messaging Cluster – Location transparent, resilient clusters Persistence – EventSourcing support (many DBs) HTTP – Fully Async & Reactive Http Server

…and much more (kafka, cassandra, testing, …)

Page 10: Not Only Streams for Akademia JLabs

And the many meanings it carries.

Reactive

Page 11: Not Only Streams for Akademia JLabs

And the many meanings it carries.

Reactive

Page 12: Not Only Streams for Akademia JLabs

The many meanings of Reactive

reactivemanifesto.org

Page 13: Not Only Streams for Akademia JLabs

The many meanings of Reactive

Page 14: Not Only Streams for Akademia JLabs
Page 15: Not Only Streams for Akademia JLabs
Page 16: Not Only Streams for Akademia JLabs

So what are Reactive Streams actually?

Page 17: Not Only Streams for Akademia JLabs

So what are Reactive Streams actually?

Page 18: Not Only Streams for Akademia JLabs

So what are Reactive Streams actually?

Page 19: Not Only Streams for Akademia JLabs

Getting the complete picture

Page 20: Not Only Streams for Akademia JLabs

Getting the complete picture (yet… not the topic of today’s talk)

Page 21: Not Only Streams for Akademia JLabs

How to think about these techniques?

bit.ly/why-reactive

Page 22: Not Only Streams for Akademia JLabs

”The actor model in computer science is a m a t h e m a t i c a l m o d e l o f c o n c u r r e n t computation that treats actors as the universal primitives of concurrent computation. ”

Wikipedia

The Actor Model

Page 23: Not Only Streams for Akademia JLabs

An Actor

and acts on them by: • Sending messages • Changing its state / behaviour • Creating more actors

receives messages

Page 24: Not Only Streams for Akademia JLabs

An ActorA concurrency and distribution construct.

an addressable, location-transparent, entity

Show diagram showing people interacting with each other.

Page 25: Not Only Streams for Akademia JLabs

Not Only Server-Client

Page 26: Not Only Streams for Akademia JLabs

HTTP/2 “push” still needs a “pull”

https://blog.cloudflare.com/announcing-support-for-http-2-server-push-2

Page 27: Not Only Streams for Akademia JLabs

Clusters, direct, p2p communication

Page 28: Not Only Streams for Akademia JLabs

Clusters, direct, p2p communication

Page 29: Not Only Streams for Akademia JLabs

Clusters, direct, p2p communication

Page 30: Not Only Streams for Akademia JLabs

Clusters, direct, p2p communication

Page 31: Not Only Streams for Akademia JLabs

Not Only JSON“The Internet is running in debug mode.”

— Rüdiger Möller

http://java-is-the-new-c.blogspot.de/2014/10/why-protocols-are-messy-concept.html

Page 32: Not Only Streams for Akademia JLabs

Not Only JSON: Example dataMediaContent {

media = Media {

uri = "http://javaone.com/keynote.mpg"

title = "Javaone Keynote"

width = 640

height = 480

format = "video/mpg4"

duration = 18000000

size = 58982400

bitrate = 262144

persons = ["Bill Gates", "Steve Jobs"]

player = JAVA

copyright = null

}

}

images = [

Image {

uri = "http://javaone.com/keynote_large.jpg"

title = "Javaone Keynote"

width = 1024

height = 768

size = LARGE

}

Image {

uri = "http://javaone.com/keynote_small.jpg"

title = "Javaone Keynote"

width = 320

height = 240

size = SMALL

}

]

Page 33: Not Only Streams for Akademia JLabs

create ser deser total size

protostuff 68 433 634 1067ns 239bytes

protobuf 121 1173 719 1891 239

kryo-serializer 53 1480 1331 2810 286

thrift 95 1455 731 2186 349

. . .

json/jackson/manual 52 1039 1228 2267 468

json/jackson/databind 54 1164 1866 3030 485

json/gson/databind 56 4667 4403 9070 486

xml/xstream+c-aalto 54 3310 6732 10042 525

xml/JAXB 54 4354 141333 145686 719

java-built-in 53 5046 23279 28325 889

Not Only JSON: Benchmarks

Slide only to illustrate order-of-magniture differences. Don’t over-focus on numbers.

All details here: https://github.com/eishay/jvm-serializers/wiki

Page 34: Not Only Streams for Akademia JLabs

Not Only JSON: Benchmarks create ser deser total size

protostuff 68 433 634 1067ns 239bytes

protobuf 121 1173 719 1891 239

kryo-serializer 53 1480 1331 2810 286

thrift 95 1455 731 2186 349

. . .

json/jackson/manual 52 1039 1228 2267 468

json/jackson/databind 54 1164 1866 3030 485

json/gson/databind 56 4667 4403 9070 486

xml/xstream+c-aalto 54 3310 6732 10042 525

xml/JAXB 54 4354 141333 145686 719

java-built-in 53 5046 23279 28325 889

Slide only to illustrate order-of-magniture differences. Don’t over-focus on numbers.

All details here: https://github.com/eishay/jvm-serializers/wiki

Page 35: Not Only Streams for Akademia JLabs

Not Only JSON: Benchmarks

Slide only to illustrate order-of-magniture differences. Don’t over-focus on numbers.

All details here: https://github.com/eishay/jvm-serializers/wiki

create ser deser total size

protostuff 68 433 634 1067ns 239bytes

protobuf 121 1173 719 1891 239

kryo-serializer 53 1480 1331 2810 286

thrift 95 1455 731 2186 349

. . .

json/jackson/manual 52 1039 1228 2267 468

json/jackson/databind 54 1164 1866 3030 485

json/gson/databind 56 4667 4403 9070 486

xml/xstream+c-aalto 54 3310 6732 10042 525

xml/JAXB 54 4354 141333 145686 719

java-built-in 53 5046 23279 28325 889

Page 36: Not Only Streams for Akademia JLabs

Advantages of Async Messaging

Page 37: Not Only Streams for Akademia JLabs

Time holding Connection

Page 38: Not Only Streams for Akademia JLabs

Time holding Connection

Page 39: Not Only Streams for Akademia JLabs

Time holding Connection

Page 40: Not Only Streams for Akademia JLabs

Time holding Connection

AFAIK: Addressed by HTTP/2,

since you can open “subStreams.”

Page 41: Not Only Streams for Akademia JLabs

Long running task, sync vs. async

Page 42: Not Only Streams for Akademia JLabs

Long running task, sync vs. async

Page 43: Not Only Streams for Akademia JLabs

Long running task, sync vs. async

Page 44: Not Only Streams for Akademia JLabs

Single Reactive AppAny benefits?

Page 45: Not Only Streams for Akademia JLabs

Reactive on the Application level

https://speakerdeck.com/benjchristensen/applying-rxjava-to-existing-applications-at-philly-ete-2015

Page 46: Not Only Streams for Akademia JLabs

“Not-quite-Reactive-System” The reason we started researching into transparent to users flow control.

Page 47: Not Only Streams for Akademia JLabs
Page 48: Not Only Streams for Akademia JLabs
Page 49: Not Only Streams for Akademia JLabs
Page 50: Not Only Streams for Akademia JLabs
Page 51: Not Only Streams for Akademia JLabs
Page 52: Not Only Streams for Akademia JLabs
Page 53: Not Only Streams for Akademia JLabs

“Best practices are solutions to yesterdays problems.”

https://twitter.com/FrankBuytendijk/status/795555578592555008

Circuit breaking as substitute of flow-control

Page 54: Not Only Streams for Akademia JLabs

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

Page 55: Not Only Streams for Akademia JLabs

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

Page 56: Not Only Streams for Akademia JLabs

HTTP/1.1 503 Service Unavailable

HTTP/1.1 503 Service Unavailable

Throttling as represented by 503 responses. Client will back-off… but how?What if most of the fleet is throttling?

Page 57: Not Only Streams for Akademia JLabs

http://doc.akka.io/docs/akka/2.4/common/circuitbreaker.html

HTTP/1.1 503 Service Unavailable

HTTP/1.1 503 Service Unavailable

Page 58: Not Only Streams for Akademia JLabs

http://doc.akka.io/docs/akka/2.4/common/circuitbreaker.html

Page 59: Not Only Streams for Akademia JLabs

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

“slamming the breaks”

Page 60: Not Only Streams for Akademia JLabs

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

“slamming the breaks”

Page 61: Not Only Streams for Akademia JLabs

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

“slamming the breaks”

Page 62: Not Only Streams for Akademia JLabs

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

“slamming the breaks”

Page 63: Not Only Streams for Akademia JLabs

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

“slamming the breaks”

Page 64: Not Only Streams for Akademia JLabs

See also, Nitesh Kant, Netflix @ Reactive Summit https://www.youtube.com/watch?v=5FE6xnH5Lak

We’ll re-visit this specific case in a bit :-)

“slamming the breaks”

Page 65: Not Only Streams for Akademia JLabs

Are absolutely useful!

Still… “We can do better than that.”

Circuit Breakers

Page 66: Not Only Streams for Akademia JLabs
Page 67: Not Only Streams for Akademia JLabs
Page 68: Not Only Streams for Akademia JLabs
Page 69: Not Only Streams for Akademia JLabs

But we’ll need everyone to understand some shared semantics…

We can do better.

Page 70: Not Only Streams for Akademia JLabs

A fundamental building block. Not end-user API by itself.

reactive-streams.org

Reactive Streams

Page 71: Not Only Streams for Akademia JLabs

Reactive StreamsMore of an SPI (Service Provider Interface),

than API.

reactive-streams.org

Page 72: Not Only Streams for Akademia JLabs

“Stream”

Page 73: Not Only Streams for Akademia JLabs

“Stream” What does it mean?!

Page 74: Not Only Streams for Akademia JLabs

Suddenly everyone jumped on the word “Stream”.

Akka Streams / Reactive Streams started end-of-2013.

“Streams”

* when put in “” the word does not appear in project name, but is present in examples / style of APIs / wording.

Page 75: Not Only Streams for Akademia JLabs

Suddenly everyone jumped on the word “Stream”.

Akka Streams / Reactive Streams started end-of-2013.

“Streams”

Akka Streams Reactive Streams RxJava “streams”* Spark Streaming Apache Storm “streams”* Java Steams (JDK8) Reactor “streams”* Kafka Streams ztellman / Manifold (Clojure)

* when put in “” the word does not appear in project name, but is present in examples / style of APIs / wording.

Apache GearPump “streams” Apache [I] Streams (!) Apache [I] Beam “streams” Apache [I] Quarks “streams” Apache [I] Airflow “streams” (dead?) Apache [I] Samza Scala Stream Scalaz Streams, now known as FS2 Swave.io Java InputStream / OutputStream / … :-)

Page 76: Not Only Streams for Akademia JLabs

The specification.Reactive Streams

Origins of

Page 77: Not Only Streams for Akademia JLabs

Reactive Streams – why it all started

Page 78: Not Only Streams for Akademia JLabs

Reactive Streams – why it all started

Page 79: Not Only Streams for Akademia JLabs

What is back-pressure?

?

Page 80: Not Only Streams for Akademia JLabs

What is back-pressure?

Page 81: Not Only Streams for Akademia JLabs

No no no…! Not THAT Back-pressure!

Also known as: flow control.

What is back-pressure?

Page 82: Not Only Streams for Akademia JLabs

No no no…! Not THAT Back-pressure!

Also known as: application level flow control.

What is back-pressure?

Page 83: Not Only Streams for Akademia JLabs

Reactive Streams - story: 2013’s impls

~2013:

Reactive Programming becoming widely adopted on JVM.

- Play introduced “Iteratees”- Akka (2009) had Akka-IO (TCP etc.)- Ben starts work on RxJava

http://blogs.msdn.com/b/rxteam/archive/2009/11/17/announcing-reactive-extensions-rx-for-net-silverlight.aspxhttp://infoscience.epfl.ch/record/176887/files/DeprecatingObservers2012.pdf - Ingo Maier, Martin Odersky

https://github.com/ReactiveX/RxJava/graphs/contributorshttps://github.com/reactor/reactor/graphs/contributors

https://medium.com/@viktorklang/reactive-streams-1-0-0-interview-faaca2c00bec#.69st3rndy

Teams discuss need for back-pressure in simple user API.Play’s Iteratee / Akka’s NACK in IO.

}

Page 84: Not Only Streams for Akademia JLabs

Reactive Streams - story: 2013’s impls

2014–2015:

Reactive Streams Spec & TCK development, and implementations.

1.0 released on April 28th 2015, with 5+ accompanying implementations.

2015Proposed to be included with JDK9 by Doug Leavia JEP-266 “More Concurrency Updates”

http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/6e50b992bef4/src/java.base/share/classes/java/util/concurrent/Flow.java

Page 85: Not Only Streams for Akademia JLabs

Reactive Streams - story: 2013’s impls

2014–2015:

Reactive Streams Spec & TCK development, and implementations.

1.0 released on April 28th 2015, with 5+ accompanying implementations.

2015Proposed to be included with JDK9 by Doug Leavia JEP-266 “More Concurrency Updates”

http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/6e50b992bef4/src/java.base/share/classes/java/util/concurrent/Flow.java

Page 86: Not Only Streams for Akademia JLabs

But what does it do!?

Reactive Streams

Page 87: Not Only Streams for Akademia JLabs

Publisher[T] Subscriber[T]

Back-pressure explained

Page 88: Not Only Streams for Akademia JLabs

Fast Publisher Slow Subscriber

Push model

Page 89: Not Only Streams for Akademia JLabs

Subscriber usually has some kind of buffer.

Push model

Page 90: Not Only Streams for Akademia JLabs

Push model

Page 91: Not Only Streams for Akademia JLabs

Push model

Page 92: Not Only Streams for Akademia JLabs

What if the buffer overflows?

Push model

Page 93: Not Only Streams for Akademia JLabs

Use bounded buffer, drop messages + require re-sending

Push model

Page 94: Not Only Streams for Akademia JLabs

Kernel does this!Routers do this!

(TCP)

Use bounded buffer, drop messages + require re-sending

Push model

Page 95: Not Only Streams for Akademia JLabs

Increase buffer size… Well, while you have memory available!

Push model

Page 96: Not Only Streams for Akademia JLabs

Push model

Page 97: Not Only Streams for Akademia JLabs

Reactive Streams explained

Reactive Streams explained in 1 slide

Page 98: Not Only Streams for Akademia JLabs

Fast Publisher will send at-most 3 elements. This is pull-based-backpressure.

Reactive Streams: “dynamic push/pull”

Page 99: Not Only Streams for Akademia JLabs

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> { }}

Page 100: Not Only Streams for Akademia JLabs

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> { }}

Single basic (helper) implementation available in JDK:SubmissionPublisher

Page 101: Not Only Streams for Akademia JLabs

Reactive Streams: goals

1) Avoiding unbounded buffering across async boundaries

2)Inter-op interfaces between various libraries

Page 102: Not Only Streams for Akademia JLabs

Reactive Streams: goals1) Avoiding unbounded buffering across async boundaries

2) Inter-op interfaces between various libraries

Argh, implementing a correct RS Publisher or Subscriber is so hard!

Page 103: Not Only Streams for Akademia JLabs

1) Avoiding unbounded buffering across async boundaries

2) Inter-op interfaces between various libraries

Reactive Streams: goals

Argh, implementing a correct RS Publisher or Subscriber is so hard!

Page 104: Not Only Streams for Akademia JLabs

Reactive Streams: goals

Argh, implementing a correct RS Publisher or Subscriber is so hard!

You should be using Akka Streams instead!

1) Avoiding unbounded buffering across async boundaries

2) Inter-op interfaces between various libraries

Page 105: Not Only Streams for Akademia JLabs

Already made a huge industry impact

Reactive Streams

Page 106: Not Only Streams for Akademia JLabs

Back-pressure as a feature

Page 107: Not Only Streams for Akademia JLabs

Inspiring other technologies

Page 108: Not Only Streams for Akademia JLabs

Inspiring other technologies

It’s been a while since Java inspired other modern technologies, hasn’t it?

Page 109: Not Only Streams for Akademia JLabs

The implementation.

Complete and awesome Java and Scala APIs. As everything since day 1 in Akka.

Akka Streams

Page 110: Not Only Streams for Akademia JLabs

Akka Streams in 20 seconds: // types: Source[Out, Mat] Flow[In, Out, Mat] Sink[In, Mat]

// generally speaking, it's always: val ready = Source.from…(???).via(flow).map(i => i * 2).to(sink)

val mat: Mat = ready.run() // the usual example: val f: Future[String] = Source.single(1).map(i => i.toString).runWith(Sink.head)

Proper static typing!

Page 111: Not Only Streams for Akademia JLabs

Akka Streams in 20 seconds:

// types: _Source[Int, NotUsed] Flow[Int, String, NotUsed] Sink[String, Future[String]]

Source.single(1).map(i => i / 0).runWith(Sink.head)

Page 112: Not Only Streams for Akademia JLabs

Source.single(1).map(i => i.toString).runWith(Sink.head)

// types: _Source[Int, NotUsed] Flow[Int, String, NotUsed] Sink[String, Future[String]]

Akka Streams in 20 seconds:

Page 113: Not Only Streams for Akademia JLabs

Materialization

Gears from GeeCON.org, did I mention it’s an awesome conf?

Page 114: Not Only Streams for Akademia JLabs

What is “materialization” really?

Page 115: Not Only Streams for Akademia JLabs

What is “materialization” really?

Page 116: Not Only Streams for Akademia JLabs

What is “materialization” really?

Page 117: Not Only Streams for Akademia JLabs

What is “materialization” really?

Page 118: Not Only Streams for Akademia JLabs

Akka Streams & HTTP

streams& HTTP

Page 119: Not Only Streams for Akademia JLabs

A core feature not obvious to the untrained eye…!

Quiz time! TCP is a ______ protocol?

Akka Streams & HTTP

Page 120: Not Only Streams for Akademia JLabs

A core feature not obvious to the untrained eye…!

Quiz time! TCP is a STREAMING protocol!

Akka Streams & HTTP

Page 121: Not Only Streams for Akademia JLabs

Streaming in Akka HTTPDEMO

HttpServer as a: Flow[HttpRequest, HttpResponse]

http://doc.akka.io/docs/akka/2.4/scala/stream/stream-customize.html#graphstage-scala “Framed entity streaming” https://github.com/akka/akka/pull/20778

Page 122: Not Only Streams for Akademia JLabs

Streaming in Akka HTTPDEMO

HttpServer as a: Flow[HttpRequest, HttpResponse]

HTTP Entity as a: Source[ByteString, _]

http://doc.akka.io/docs/akka/2.4/scala/stream/stream-customize.html#graphstage-scala “Framed entity streaming” https://github.com/akka/akka/pull/20778

Page 123: Not Only Streams for Akademia JLabs

Streaming in Akka HTTPDEMO

http://doc.akka.io/docs/akka/2.4/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]

Page 124: Not Only Streams for Akademia JLabs

It’s turtles buffers all the way down!

Page 125: Not Only Streams for Akademia JLabs

Streaming from Akka HTTP

Page 126: Not Only Streams for Akademia JLabs

Streaming from Akka HTTP

Page 127: Not Only Streams for Akademia JLabs

Streaming from Akka HTTP

Page 128: Not Only Streams for Akademia JLabs

Streaming from Akka HTTP (Scala)object Example extends App with SprayJsonSupport with DefaultJsonProtocol { import akka.http.scaladsl.server.Directives._ implicit val system = ActorSystem() implicit val mat = ActorMaterializer()

implicit val jsonRenderingMode = EntityStreamingSupport.json() implicit val TweetFormat = jsonFormat1(Tweet)

def tweetsStreamRoutes = path("tweets") { complete { Source.repeat(Tweet("")) } } Http().bindAndHandle(tweetsStreamRoutes, "127.0.0.1", 8080) System.out.println("Running at http://localhost:8080");}

Page 129: Not Only Streams for Akademia JLabs

Streaming from Akka HTTP (Java) public static void main(String[] args) { final ActorSystem system = ActorSystem.create(); final Materializer materializer = ActorMaterializer.create(system); final Http http = Http.get(system);

final Source<Tweet, NotUsed> tweets = Source.repeat(new Tweet("Hello world"));

final Route tweetsRoute = path("tweets", () -> completeWithSource(tweets, Jackson.marshaller(), EntityStreamingSupport.json()) );

final Flow<HttpRequest, HttpResponse, NotUsed> handler = tweetsRoute.flow(system, materializer);

http.bindAndHandle(handler, ConnectHttp.toHost("localhost", 8080), materializer ); System.out.println("Running at http://localhost:8080");

}

Page 130: Not Only Streams for Akademia JLabs

Streaming from Akka HTTP (Java) public static void main(String[] args) { final ActorSystem system = ActorSystem.create(); final Materializer materializer = ActorMaterializer.create(system); final Http http = Http.get(system);

final Source<Tweet, NotUsed> tweets = Source.repeat(new Tweet("Hello world"));

final Route tweetsRoute = path("tweets", () -> completeWithSource(tweets, Jackson.marshaller(), EntityStreamingSupport.json()) );

final Flow<HttpRequest, HttpResponse, NotUsed> handler = tweetsRoute.flow(system, materializer);

http.bindAndHandle(handler, ConnectHttp.toHost("localhost", 8080), materializer ); System.out.println("Running at http://localhost:8080");

}

Page 131: Not Only Streams for Akademia JLabs

Ecosystem that solves problems

> (is greater than) solving all the problems ourselves

Page 132: Not Only Streams for Akademia JLabs

Codename: Alpakka

// these are “Alpacasso”

Page 133: Not Only Streams for Akademia JLabs

A community for Streams connectors

Alpakka – a community for Stream connectors

Alp

Page 134: Not Only Streams for Akademia JLabs

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

Page 135: Not Only Streams for Akademia JLabs

Alpakka – a community for Stream connectors

Existing examples:MQTT / AMQPStreaming HTTPStreaming TCP

Streaming FileIO Amazon S3, SQS & more

Cassandra QueriesReactive Kafka (akka-stream-kafka)

S3, SQS & other Amazon APIsStreaming JSON ParsingStreaming XML Parsing

Page 136: Not Only Streams for Akademia JLabs

Reactive Streams / Akka Streams

Is now the time to adopt?

Page 137: Not Only Streams for Akademia JLabs

Totally, go for it.

Page 138: Not Only Streams for Akademia JLabs

ReactiveSocket.io

Taking it to the next level:

Page 139: Not Only Streams for Akademia JLabs

ReactiveSocket.io

Taking it to the next level:

A collaboration similar in spirit, and continuing from whereReactive Streams brought us today.

Page 140: Not Only Streams for Akademia JLabs

Reactive Streams over network boundaries

http://reactivesocket.io/

Reactive Streams = async boundaries Reactive Socket = RS + network boundaries

Page 141: Not Only Streams for Akademia JLabs

Reactive Streams over network boundaries

http://reactivesocket.io/

Reactive Streams = async boundaries Reactive Socket = RS + network boundaries

Primarily led by:- Ben Christensen, Todd Montgomery (Facebook) & team - Nitesh Kant (Netflix) & team

Lightbend on board as well – right now we’re prototyping with it.

Page 142: Not Only Streams for Akademia JLabs

Reactive Streams over network boundaries

“ReactiveSocket is an application protocol providing Reactive Streams semantics

over an asynchronous, binary boundary.”

http://reactivesocket.io/

Page 143: Not Only Streams for Akademia JLabs

Reactive Streams over network boundaries

Binary Support various platforms: - java - c++ - js - …

Page 144: Not Only Streams for Akademia JLabs

Reactive Streams over network boundaries

Async Obviously we want it to be async and properly bi-directional.

Page 145: Not Only Streams for Akademia JLabs

Reactive Streams over network boundaries

Application protocol

Again, bridging app-level semantics to wire semantics.

Reactive Streams semantics: - “you can do 10 requests”

Page 146: Not Only Streams for Akademia JLabs

Reactive Streams over network boundaries

Application protocol

Again, bridging app semantics to wire semantics.

Reactive Streams semantics: - “you can do 10 requests”

Extra Lease semantics: - “you can do 10 reqs in 30secs”

Page 147: Not Only Streams for Akademia JLabs

Lease semantics, “flipping the problem”

Page 148: Not Only Streams for Akademia JLabs

Lease semantics, “flipping the problem”

Page 149: Not Only Streams for Akademia JLabs

Lease semantics, “flipping the problem”

Page 150: Not Only Streams for Akademia JLabs

Exciting times ahead!

Page 151: Not Only Streams for Akademia JLabs

State and Future[_] of ReactiveReactive Systems – well established “goal” architecture …excellent building blocks available, and getting even better with:

Reactive-Streams eco-system blooming! … as very important building block of the puzzle.

Akka Streams driving implementation of Reactive Streams (first passing TCK, prime contributor to spec, strong ecosystem)

Reactive Socket continuing to improve app-level flow-control semantics. More control than “just use HTTP/2”. … considering resumability for streams as well.

The best is yet to come: combining all these components into resilient, scalable systems!

Page 152: Not Only Streams for Akademia JLabs

Happy hAkking!

Page 153: Not Only Streams for Akademia JLabs

We <3 contributions• Easy to contribute:

• 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: akka.io && github.com/akka • Reactive Streams: reactive-streams.org • Reactive Socket: reactivesocket.io

• 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

Page 154: Not Only Streams for Akademia JLabs

Pics

Gundam pictures from: http://www.wallpaperup.com/tag/gundam/3

Page 155: Not Only Streams for Akademia JLabs

Free e-book and printed report. bit.ly/why-reactive

Covers what reactive actually is.Implementing in existing architectures.

Thoughts from the team that’s buildingreactive apps since more than 6 years.

Obligatory “read my book!” slide :-)

Page 156: Not Only Streams for Akademia JLabs

Q/Aktoso @ lightbend.com twitter: ktosopl

github: ktosoteam blog: blog.akka.io

home: akka.io myself: kto.so