akka http: the reactive web...

16
Akka HTTP: The Reactive Web Toolkit Dr. Roland Kuhn @rolandkuhn — Akka Tech Lead

Upload: others

Post on 22-May-2020

33 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

Akka HTTP: The Reactive Web Toolkit

Dr. Roland Kuhn @rolandkuhn — Akka Tech Lead

Page 2: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

Live Demo

Page 3: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

API Design

• goals: • no magic

• supreme compositionality

• exhaustive model of bounded stream processing

• consequences: • immutable and reusable stream blueprints

• explicit materialization step

3

http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-M2/stream-design.html

Page 4: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

Materialization

• Akka Streams separate the what from the how • declarative Source/Flow/Sink DSL to create blueprint

• FlowMaterializer turns this into running Actors

• this allows alternative materialization strategies • optimization

• verification / validation

• cluster deployment

• only Akka Actors for now, but more to come!

4

Page 5: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

Akka HTTP

Page 6: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

Why do we add an HTTP module?

• Akka is about building distributed applications

• distribution implies integration • between internal (sub)systems➜ akka-cluster based on akka-remote

• with external systems➜ akka-http (lingua franca of the internet)

6

Page 7: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

HTTP Stream Topology

7

Page 8: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

The Application Stack

8

O/S-level network stack

Java NIO (JDK)

Akka IO

Akka HTTP Core

Akka HTTP

user- level

Page 9: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

Akka HTTP Core

• implements HTTP/1.1 according to the RFCs

• based upon the TCP facilities of Akka IO

• exposed as freely reusable stream transformations (BidiFlows & Flows)

• low-level and extensible implementation ofHTTP model and spec

9

Page 10: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

Stream Pipelines

10

TCP SSL HTTP App

Requests

Responsesoptional (not yet*)

* It was literally sooooo close, but didn’t make it for ScalaDays.

Page 11: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

A Quick View of the HTTP Model

11

case class HttpRequest( method: HttpMethod = HttpMethods.GET, uri: Uri = Uri./, headers: immutable.Seq[HttpHeader] = Nil, entity: RequestEntity = HttpEntity.Empty, protocol: HttpProtocol = HttpProtocols.`HTTP/1.1` ) extends HttpMessage

case class HttpResponse( status: StatusCode = StatusCodes.OK, headers: immutable.Seq[HttpHeader] = Nil, entity: ResponseEntity = HttpEntity.Empty, protocol: HttpProtocol = HttpProtocols.`HTTP/1.1` ) extends HttpMessage

Page 12: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

Akka HTTP

• builds upon Akka HTTP Core

• adds (un)marshaling for HttpEntities

• adds (de)compression (gzip / deflate)

• high-level server-side routing DSL • type-safe and flexible

• highly compositional building blocks (Directives)

• includes common behaviors pre-canned

12

Page 13: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

Live Demo

Page 14: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

When can we have it?

• currently pre-release versions: • reactive-streams 1.0.0-RC3

• Akka Streams & HTTP 1.0-M4

• still missing: • Akka HTTP client features

• SSL integration

• websockets

• Akka Streams & HTTP 1.0 expected end of Feb’15

14

Page 15: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

Resources

• https://github.com/akka/akka/tree/release-2.3-dev

• http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-M4/

• akka-user mailing list

15

Page 16: Akka HTTP: The Reactive Web Toolkitdownloads.typesafe.com/.../ScalaDaysSF2015/T1_Kuhn_Akka_Strea… · • reactive-streams 1.0.0-RC3 • Akka Streams & HTTP 1.0-M4 • still missing:

©Typesafe 2014 – All Rights Reserved