SlideShare a Scribd company logo
1 of 46
Download to read offline
Introduction to Akka HTTP
Building scalable rest service in Scala
https://github.com/shashankgowdal/introduction-to-akkahttp
● Shashank L
● Senior Software engineer at Tellius
● Part time big data consultant and trainer
at datamantra.io
● www.shashankgowda.com
Agenda
● Motivation
● Akka, Reactive streams
● Akka Http
● Akka Http High level API
● Testing
● Additional functionality
● Working with files
● Websockets
● Akka Http with Spark
Scala frameworks to build REST API
● Play/Lift
○ Full stack web framework
● Scalatra
○ Lightweight but requires a application container for
deployment
● Spray
○ Lightweight and robust as it's asynchronous and built on top
of Actors
● Akka HTTP
○ Next version of Spray framework
Why Akka HTTP
● Its 2.0 version of Spray.io
● Internals of Spray have been rewritten to use
Reactive streams
● Reactive streams idea gel well with earlier ideas of
Spray
● Multiple level API
Akka
● Toolkit and runtime for building highly concurrent,
distributed, and fault tolerant applications on the JVM
● Uses message passing based concurrency model
● Written in Scala
● Scale up or out
● Program at higher level
● Distributable by design
● Message passing is built on top of AkkaActor model
Akka actor
● Receives message and takes action to handle them
● Consists of
○ Behaviour
○ State
○ Mailbox
Reactive streams
● Asynchronous
● Stream processing
● Back-pressured
● Interoperability
● Few Implementations
○ Akka Streams
○ RxJava
○ Play
○ Kafka
● Spark streaming with Kafka receiver
Akka streams
● Akka’s implementation of Reactive streams
● DSL for building a complete stream
● Higher level abstraction over the actor model
● Stream inputs and outputs are typesafe
● Internally uses Actor to implement Reactive stream
properties
Source, Flow and Sink
Source, Flow and Sink
com.shashank.akkahttp.IntroductionToStream
implicit val sys = ActorSystem("IntroductionToStream")
implicit val mat:Materializer = ActorMaterializer()
val source = Source(List(1, 2, 3))
val flow = Flow[Int].map(_.toString)
val sink = Sink.foreach(println)
val runnableGraph = source via flow to sink
runnableGraph.run()
HTTP server with Akka streams
HTTPServer as a:
Flow[HttpRequest, HttpResponse]
Socket
input
Bytes ⇒
HttpRequest
HttpRequest ⇒
HttpResponse
HttpResponse
⇒ Bytes
Socket
Sink
Akka Http server using Flow
implicit val sys = ActorSystem("IntroductionToAkkaHttp")
implicit val mat:Materializer = ActorMaterializer()
val requestResponseFlow = Flow.fromFunction[HttpRequest, HttpResponse]( request => {
println(request.toString)
HttpResponse(StatusCodes.OK, entity = "Hello!")
})
Http().bindAndHandle(requestResponseFlow, "localhost", 8080)
com.shashank.akkahttp.basic.serving.StreamsServing
Akka HTTP
● Part of Akka project
● HTTP toolkit (Client and Server)
● On top of akka-actor and akka-streams
● Multiple levels of abstraction - Open API
● Scalable, Max throughput, acceptable latency
● APIs in both Scala and Java
Akka HTTP - Implementation
● Fully asynchronous and nonblocking
● Focused on higher level API
● Lightweight
● Modular
● Testable
● Based on spray.io
● Better streaming REST functionality support
Akka HTTP stack
Akka HTTP structure
Akka HTTP module
akka-http
akka-http-core
akka-http-testkit
akka-http-
spray-json
akka-http-xml
Akka HTTP - Parts
● akka-http-core
○ low-level server & client side HTTP implementation
● akka-http
○ high-level API : DSL, (un)marshalling, (de)compression
● akka-http-testkit
○ Utilities for testing server-side implementation
● akka-http-spray-json
○ (de)serialization from/to JSON with spray-json
● akka-http-xml
○ (de)serialization from/to XML with scala-xml
HTTP model
● Fully immutable, case-class based
● Abstraction for most HTTP things (Types!)
● Little logic inside
● Lots of predefined types - media type, status code,
encodings etc
● Efficient parsing and rendering
● Clients/Connected services should obey the standard
HTTP model - Examples
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`)
case class HttpResponse(status: StatusCode = StatusCodes.OK,
headers: immutable.Seq[HttpHeader] = Nil,
entity: ResponseEntity = HttpEntity.Empty,
protocol: HttpProtocol = HttpProtocols.`HTTP/1.1`)
case class Uri(scheme: String,
authority: Authority,
path: Path,
rawQueryString: Option[String],
fragment: Option[String])
HTTP model - Examples
object ContentTypes {
val `application/json` = ContentType(MediaTypes.`application/json`)
val `application/octet-stream` = ContentType(MediaTypes.`application/octet-stream`)
val `text/plain(UTF-8)` = MediaTypes.`text/plain` withCharset HttpCharsets.`UTF-8`
val `text/html(UTF-8)` = MediaTypes.`text/html` withCharset HttpCharsets.`UTF-8`
val `text/xml(UTF-8)` = MediaTypes.`text/xml` withCharset HttpCharsets.`UTF-8`
val `text/csv(UTF-8)` = MediaTypes.`text/csv` withCharset HttpCharsets.`UTF-8`
val NoContentType = ContentType(MediaTypes.NoMediaType)
}
val `US-ASCII` = register("US-ASCII")("iso-ir-6", "ANSI_X3.4-1968", "ANSI_X3.4-1986", "ISO_646.irv:1991", "ASCII", "ISO646-US",
"us", "IBM367", "cp367", "csASCII")
val `ISO-8859-1` = register("ISO-8859-1")("iso-ir-100", "ISO_8859-1", "latin1", "l1", "IBM819", "CP819", "csISOLatin1")
val `UTF-8` = register("UTF-8")("UTF8")
val `UTF-16` = register("UTF-16")("UTF16")
val `UTF-16BE` = register("UTF-16BE")()
val `UTF-16LE` = register("UTF-16LE")()
HTTP server functional way
● Low level HTTP API
● Provided by akka-http-core-module
implicit val sys = ActorSystem("IntroductionToAkkaHttp")
implicit val mat:Materializer = ActorMaterializer()
val handler :(HttpRequest => HttpResponse) = {
case HttpRequest(HttpMethods.GET, Uri.Path("/ping"), _, _, _) =>
HttpResponse(StatusCodes.OK, entity = "pong!")
case r =>
HttpResponse(status = StatusCodes.BadRequest)
}
Http().bindAndHandleSync(handler, "localhost", 8080)
com.shashank.akkahttp.basic.serving.FunctionalServing
Akka Http high level API
HTTP Server Nice way!
● Low level API becomes uneasy to handle when we
need large number of routes
● For this we should use higher level API by akka-http
● Route using Routing DSL
implicit val sys = ActorSystem("IntroductionToAkkaHttp")
implicit val mat:Materializer = ActorMaterializer()
val routes: Route = ???
Http(sys).bindAndHandle(route, "localhost", 8090)
Routing DSL
● Internal domain specific language for routing
● How most services are actually written
● Layer to the application
● Type safe but flexible
● Not just routing - behaviour definition
● Very composable
● Fun, powerful and looks clean
Routing DSL - Example
val route =
path("welcome"){
get{
complete {
"welcome to rest service"
}
}
} ~
path("demo"){
get{
complete {
"welcome to demonstration"
}
}
}
Http().bindAndHandle(route, "localhost", 8090)
com.shashank.akkahttp.basic.routing.RoutingDSL
Directives
● A Directive is a small building block used for creating
routes.
● There are some predefined directives( get, post,
complete etc.)
● We can also define our custom directives.
● Roles: extracting, transforming request or response,
filtering, side-effecting
● ~136 predefined directives
Rejections
● Produced by directives
● Travel down the routing structure
● EmptyRejection is thrown when no route completes
● Can be extended
● Can be cancelled
● Handling rejection = transforming it to response
● Ex. MethodRejection, AuthorizationFailedRejection,
MissingCookieRejection, MissingQueryParamRejection
Rejections
● ~ operator connects two routes in a way that allows a
second route to get a go at a request if the first route
"rejected" it.
path("order") {
get {
complete("Received GET")
} ~
post {
complete("Received POST")
}
}
com.shashank.akkahttp.basic.routing.Rejection
Failures
● Are triggered by exceptions
● Travel up the routing structure
● Can be handled by handleExceptions directive or
top-level ExceptionHandler
● Can be used to simplify the flow for validation
purpose
com.shashank.akkahttp.basic.routing.Failure
Testing Akka Http
● Simple and straightforward
● Allows to assert responses returned for given
requests
● Integrates well with Scalatest
Get("/ping") ~> route ~> check{
status === OK
entity.as[String] === "It Works!"
}
com.shashank.akkahttp.basic.routing.TestKit
Testkit
Additional Rest functionalities in
Akka Http
Query parameters
def parameters(param: <ParamDef[T]>): Directive1[T]
● Mandatory parameters
● Optional parameters
● Parameters with required value
● Deserialized parameter
● Repeated parameter
● Deserialized parameter into Case class
(Un)Marshalling
● Marshalling - high level → low (wire) level
● Unmarshalling - low (wire) level → high level
● Many predefined (un) marshallers are available
● Extensible
● JSON and XML supported
● Type-class approach - Implicit resolution
Custom Http entity data
● Akka Http JSON support
● Support conversion to and from JVM objects to wire
representation like JSON, XML etc
● SprayJsonSupport provides a
FromEntityUnmarshaller[T] and ToEntityMarshaller[T]
for every type T with Spray Json Reader/Writer
com.shashank.akkahttp.basic.routing.CustomEntityWithJson
Custom directive
● Configuration labelling
● Transforming existing directives
● Directive0, Directive1
● Authorization
● Authentication
com.shashank.akkahttp.basic.routing.CustomDirective
Working with Files
File upload
def uploadedFile(fieldName: String): Directive1[(FileInfo, File)]
● Streams the contents of a file uploaded as a multipart
form into a temporary file on disk
● Cannot start processing the file unless it written
completely to temporary file
com.shashank.akkahttp.basic.routing.FileUpload
File upload stream
def fileUpload(fieldName: String): Directive1[(FileInfo,
Source[ByteString, Any])]
● Simple access to the stream of bytes for a file
uploaded as a multipart form together with metadata
about the upload as extracted value.
com.shashank.akkahttp.basic.routing.FileUploadStream
Websockets
Websocket
● WebSocket is a protocol that provides a bi-directional channel
between browser and webserver
● Data is exchanged in messages whereby a message can either
be binary data or unicode text
Server side websocket in AkkaHttp
● Akka HTTP provides a stream-based implementation of the
WebSocket protocol
● basic unit of data exchange in the WebSocket is a message i.e
TextMessage or BinaryMessage
● Websocket handshake is managed and hidden from application
layer
● A message handler is expected to be implemented as a
Flow[Message, Message, Any]
● Testing Websocket using WSProbe
com.shashank.akkahttp.basic.routing.Websocket
Akka HTTP with Spark
Spark Cluster
Akka Http
Rest
server
Client
HDFS
Pros and Cons
● Pros
○ Backed by Lightbend(Typesafe)
○ Integration layers
○ Microservices
○ Pure REST APIs
● Cons
○ Full fledged web applications (server side template generation)
○ Not mature enough
○ Easy to start, hard to master
References
● Akka HTTP - A reactive web toolkit
● Akka HTTP - What, Why and How
● Introduction to Akka HTTP
● Akka HTTP documentation
http://doc.akka.io/docs/akka/2.4.2/scala/http/
● http://blog.madhukaraphatak.com/categories/akka-http/

More Related Content

What's hot

Building distributed processing system from scratch - Part 2
Building distributed processing system from scratch - Part 2Building distributed processing system from scratch - Part 2
Building distributed processing system from scratch - Part 2datamantra
 
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 StreamsKevin Webber
 
Building Distributed Systems from Scratch - Part 1
Building Distributed Systems from Scratch - Part 1Building Distributed Systems from Scratch - Part 1
Building Distributed Systems from Scratch - Part 1datamantra
 
Introduction to Spark Streaming
Introduction to Spark StreamingIntroduction to Spark Streaming
Introduction to Spark StreamingKnoldus Inc.
 
Introduction to Apache Spark 2.0
Introduction to Apache Spark 2.0Introduction to Apache Spark 2.0
Introduction to Apache Spark 2.0Knoldus Inc.
 
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...Lightbend
 
Structured Streaming with Kafka
Structured Streaming with KafkaStructured Streaming with Kafka
Structured Streaming with Kafkadatamantra
 
Introduction to Datasource V2 API
Introduction to Datasource V2 APIIntroduction to Datasource V2 API
Introduction to Datasource V2 APIdatamantra
 
Serverless Event Streaming with Pulsar Functions
Serverless Event Streaming with Pulsar FunctionsServerless Event Streaming with Pulsar Functions
Serverless Event Streaming with Pulsar FunctionsStreamNative
 
Migrating to spark 2.0
Migrating to spark 2.0Migrating to spark 2.0
Migrating to spark 2.0datamantra
 
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous ArchitecturesUnderstanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous ArchitecturesLightbend
 
Spark on Kubernetes
Spark on KubernetesSpark on Kubernetes
Spark on Kubernetesdatamantra
 
Introduction to Structured streaming
Introduction to Structured streamingIntroduction to Structured streaming
Introduction to Structured streamingdatamantra
 
Reactive database access with Slick3
Reactive database access with Slick3Reactive database access with Slick3
Reactive database access with Slick3takezoe
 
Specs2 whirlwind tour at Scaladays 2014
Specs2 whirlwind tour at Scaladays 2014Specs2 whirlwind tour at Scaladays 2014
Specs2 whirlwind tour at Scaladays 2014Eric Torreborre
 
Building real time Data Pipeline using Spark Streaming
Building real time Data Pipeline using Spark StreamingBuilding real time Data Pipeline using Spark Streaming
Building real time Data Pipeline using Spark Streamingdatamantra
 
Designing Payloads for Event-Driven Systems | Lorna Mitchell, Aiven
Designing Payloads for Event-Driven Systems | Lorna Mitchell, AivenDesigning Payloads for Event-Driven Systems | Lorna Mitchell, Aiven
Designing Payloads for Event-Driven Systems | Lorna Mitchell, AivenHostedbyConfluent
 
Revitalizing Enterprise Integration with Reactive Streams
Revitalizing Enterprise Integration with Reactive StreamsRevitalizing Enterprise Integration with Reactive Streams
Revitalizing Enterprise Integration with Reactive StreamsLightbend
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Reactivesummit
 

What's hot (20)

Building distributed processing system from scratch - Part 2
Building distributed processing system from scratch - Part 2Building distributed processing system from scratch - Part 2
Building distributed processing system from scratch - Part 2
 
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 Distributed Systems from Scratch - Part 1
Building Distributed Systems from Scratch - Part 1Building Distributed Systems from Scratch - Part 1
Building Distributed Systems from Scratch - Part 1
 
Introduction to Spark Streaming
Introduction to Spark StreamingIntroduction to Spark Streaming
Introduction to Spark Streaming
 
Introduction to Apache Spark 2.0
Introduction to Apache Spark 2.0Introduction to Apache Spark 2.0
Introduction to Apache Spark 2.0
 
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...
 
Structured Streaming with Kafka
Structured Streaming with KafkaStructured Streaming with Kafka
Structured Streaming with Kafka
 
Introduction to Datasource V2 API
Introduction to Datasource V2 APIIntroduction to Datasource V2 API
Introduction to Datasource V2 API
 
Serverless Event Streaming with Pulsar Functions
Serverless Event Streaming with Pulsar FunctionsServerless Event Streaming with Pulsar Functions
Serverless Event Streaming with Pulsar Functions
 
Migrating to spark 2.0
Migrating to spark 2.0Migrating to spark 2.0
Migrating to spark 2.0
 
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous ArchitecturesUnderstanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
 
Akka streams
Akka streamsAkka streams
Akka streams
 
Spark on Kubernetes
Spark on KubernetesSpark on Kubernetes
Spark on Kubernetes
 
Introduction to Structured streaming
Introduction to Structured streamingIntroduction to Structured streaming
Introduction to Structured streaming
 
Reactive database access with Slick3
Reactive database access with Slick3Reactive database access with Slick3
Reactive database access with Slick3
 
Specs2 whirlwind tour at Scaladays 2014
Specs2 whirlwind tour at Scaladays 2014Specs2 whirlwind tour at Scaladays 2014
Specs2 whirlwind tour at Scaladays 2014
 
Building real time Data Pipeline using Spark Streaming
Building real time Data Pipeline using Spark StreamingBuilding real time Data Pipeline using Spark Streaming
Building real time Data Pipeline using Spark Streaming
 
Designing Payloads for Event-Driven Systems | Lorna Mitchell, Aiven
Designing Payloads for Event-Driven Systems | Lorna Mitchell, AivenDesigning Payloads for Event-Driven Systems | Lorna Mitchell, Aiven
Designing Payloads for Event-Driven Systems | Lorna Mitchell, Aiven
 
Revitalizing Enterprise Integration with Reactive Streams
Revitalizing Enterprise Integration with Reactive StreamsRevitalizing Enterprise Integration with Reactive Streams
Revitalizing Enterprise Integration with Reactive Streams
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
 

Viewers also liked

Telco analytics at scale
Telco analytics at scaleTelco analytics at scale
Telco analytics at scaledatamantra
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickZalando Technology
 
An Introduction to Akka http
An Introduction to Akka httpAn Introduction to Akka http
An Introduction to Akka httpKnoldus Inc.
 
Platform for Data Scientists
Platform for Data ScientistsPlatform for Data Scientists
Platform for Data Scientistsdatamantra
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPRafal Gancarz
 
Interactive Data Analysis in Spark Streaming
Interactive Data Analysis in Spark StreamingInteractive Data Analysis in Spark Streaming
Interactive Data Analysis in Spark Streamingdatamantra
 
Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Evan Chan
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scaladatamantra
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneKonrad Malawski
 
Real time ETL processing using Spark streaming
Real time ETL processing using Spark streamingReal time ETL processing using Spark streaming
Real time ETL processing using Spark streamingdatamantra
 
Productionalizing a spark application
Productionalizing a spark applicationProductionalizing a spark application
Productionalizing a spark applicationdatamantra
 
Anatomy of spark catalyst
Anatomy of spark catalystAnatomy of spark catalyst
Anatomy of spark catalystdatamantra
 
Akka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsAkka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsNLJUG
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
 
Microservices - it's déjà vu all over again
Microservices  - it's déjà vu all over againMicroservices  - it's déjà vu all over again
Microservices - it's déjà vu all over againArnon Rotem-Gal-Oz
 

Viewers also liked (20)

Telco analytics at scale
Telco analytics at scaleTelco analytics at scale
Telco analytics at scale
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & Slick
 
An Introduction to Akka http
An Introduction to Akka httpAn Introduction to Akka http
An Introduction to Akka http
 
Platform for Data Scientists
Platform for Data ScientistsPlatform for Data Scientists
Platform for Data Scientists
 
Akka http 2
Akka http 2Akka http 2
Akka http 2
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTP
 
Interactive Data Analysis in Spark Streaming
Interactive Data Analysis in Spark StreamingInteractive Data Analysis in Spark Streaming
Interactive Data Analysis in Spark Streaming
 
Akka-http
Akka-httpAkka-http
Akka-http
 
Akka HTTP
Akka HTTPAkka HTTP
Akka HTTP
 
Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
 
Akka http
Akka httpAkka http
Akka http
 
Real time ETL processing using Spark streaming
Real time ETL processing using Spark streamingReal time ETL processing using Spark streaming
Real time ETL processing using Spark streaming
 
Productionalizing a spark application
Productionalizing a spark applicationProductionalizing a spark application
Productionalizing a spark application
 
Anatomy of spark catalyst
Anatomy of spark catalystAnatomy of spark catalyst
Anatomy of spark catalyst
 
Akka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsAkka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based Applications
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on Heroku
 
Discovery
DiscoveryDiscovery
Discovery
 
Microservices - it's déjà vu all over again
Microservices  - it's déjà vu all over againMicroservices  - it's déjà vu all over again
Microservices - it's déjà vu all over again
 

Similar to Akka HTTP Intro

Scala45 spray test
Scala45 spray testScala45 spray test
Scala45 spray testkopiczko
 
Sharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleSharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleGeoff Ballinger
 
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache KafkaExploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache KafkaLightbend
 
Building REST API using Akka HTTP with Scala
Building REST API using Akka HTTP with ScalaBuilding REST API using Akka HTTP with Scala
Building REST API using Akka HTTP with ScalaKnoldus Inc.
 
Akka streams - Umeå java usergroup
Akka streams - Umeå java usergroupAkka streams - Umeå java usergroup
Akka streams - Umeå java usergroupJohan Andrén
 
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Johan Andrén
 
RESTful SCA with Apache Tuscany
RESTful SCA with Apache TuscanyRESTful SCA with Apache Tuscany
RESTful SCA with Apache TuscanyRaymond Feng
 
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
 
Reactive streams processing using Akka Streams
Reactive streams processing using Akka StreamsReactive streams processing using Akka Streams
Reactive streams processing using Akka StreamsJohan Andrén
 
Scorex, the Modular Blockchain Framework
Scorex, the Modular Blockchain FrameworkScorex, the Modular Blockchain Framework
Scorex, the Modular Blockchain FrameworkAlex Chepurnoy
 
BigDataSpain 2016: Stream Processing Applications with Apache Apex
BigDataSpain 2016: Stream Processing Applications with Apache ApexBigDataSpain 2016: Stream Processing Applications with Apache Apex
BigDataSpain 2016: Stream Processing Applications with Apache ApexThomas Weise
 
Building RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RSBuilding RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RSLuciano Resende
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka StreamsKonrad Malawski
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsJohan Andrén
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & KafkaBack-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & KafkaAkara Sucharitakul
 
Streaming all the things with akka streams
Streaming all the things with akka streams   Streaming all the things with akka streams
Streaming all the things with akka streams Johan Andrén
 

Similar to Akka HTTP Intro (20)

Scala45 spray test
Scala45 spray testScala45 spray test
Scala45 spray test
 
Sharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's FinagleSharding and Load Balancing in Scala - Twitter's Finagle
Sharding and Load Balancing in Scala - Twitter's Finagle
 
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache KafkaExploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
 
Building REST API using Akka HTTP with Scala
Building REST API using Akka HTTP with ScalaBuilding REST API using Akka HTTP with Scala
Building REST API using Akka HTTP with Scala
 
Akka streams - Umeå java usergroup
Akka streams - Umeå java usergroupAkka streams - Umeå java usergroup
Akka streams - Umeå java usergroup
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
 
2 Asp Dot Net Ajax Extensions
2 Asp Dot Net Ajax Extensions2 Asp Dot Net Ajax Extensions
2 Asp Dot Net Ajax Extensions
 
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Reactive stream processing using Akka streams
Reactive stream processing using Akka streams
 
RESTful SCA with Apache Tuscany
RESTful SCA with Apache TuscanyRESTful SCA with Apache Tuscany
RESTful SCA with Apache Tuscany
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Rack
RackRack
Rack
 
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...
 
Reactive streams processing using Akka Streams
Reactive streams processing using Akka StreamsReactive streams processing using Akka Streams
Reactive streams processing using Akka Streams
 
Scorex, the Modular Blockchain Framework
Scorex, the Modular Blockchain FrameworkScorex, the Modular Blockchain Framework
Scorex, the Modular Blockchain Framework
 
BigDataSpain 2016: Stream Processing Applications with Apache Apex
BigDataSpain 2016: Stream Processing Applications with Apache ApexBigDataSpain 2016: Stream Processing Applications with Apache Apex
BigDataSpain 2016: Stream Processing Applications with Apache Apex
 
Building RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RSBuilding RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RS
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka Streams
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & KafkaBack-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
 
Streaming all the things with akka streams
Streaming all the things with akka streams   Streaming all the things with akka streams
Streaming all the things with akka streams
 

More from datamantra

Multi Source Data Analysis using Spark and Tellius
Multi Source Data Analysis using Spark and TelliusMulti Source Data Analysis using Spark and Tellius
Multi Source Data Analysis using Spark and Telliusdatamantra
 
State management in Structured Streaming
State management in Structured StreamingState management in Structured Streaming
State management in Structured Streamingdatamantra
 
Understanding transactional writes in datasource v2
Understanding transactional writes in  datasource v2Understanding transactional writes in  datasource v2
Understanding transactional writes in datasource v2datamantra
 
Exploratory Data Analysis in Spark
Exploratory Data Analysis in SparkExploratory Data Analysis in Spark
Exploratory Data Analysis in Sparkdatamantra
 
Core Services behind Spark Job Execution
Core Services behind Spark Job ExecutionCore Services behind Spark Job Execution
Core Services behind Spark Job Executiondatamantra
 
Optimizing S3 Write-heavy Spark workloads
Optimizing S3 Write-heavy Spark workloadsOptimizing S3 Write-heavy Spark workloads
Optimizing S3 Write-heavy Spark workloadsdatamantra
 
Understanding time in structured streaming
Understanding time in structured streamingUnderstanding time in structured streaming
Understanding time in structured streamingdatamantra
 
Spark stack for Model life-cycle management
Spark stack for Model life-cycle managementSpark stack for Model life-cycle management
Spark stack for Model life-cycle managementdatamantra
 
Productionalizing Spark ML
Productionalizing Spark MLProductionalizing Spark ML
Productionalizing Spark MLdatamantra
 
Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scaladatamantra
 
Understanding Implicits in Scala
Understanding Implicits in ScalaUnderstanding Implicits in Scala
Understanding Implicits in Scaladatamantra
 
Migrating to Spark 2.0 - Part 2
Migrating to Spark 2.0 - Part 2Migrating to Spark 2.0 - Part 2
Migrating to Spark 2.0 - Part 2datamantra
 
Scalable Spark deployment using Kubernetes
Scalable Spark deployment using KubernetesScalable Spark deployment using Kubernetes
Scalable Spark deployment using Kubernetesdatamantra
 
Introduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actorsIntroduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actorsdatamantra
 
Interactive workflow management using Azkaban
Interactive workflow management using AzkabanInteractive workflow management using Azkaban
Interactive workflow management using Azkabandatamantra
 
Anatomy of Spark SQL Catalyst - Part 2
Anatomy of Spark SQL Catalyst - Part 2Anatomy of Spark SQL Catalyst - Part 2
Anatomy of Spark SQL Catalyst - Part 2datamantra
 
Introduction to Spark 2.0 Dataset API
Introduction to Spark 2.0 Dataset APIIntroduction to Spark 2.0 Dataset API
Introduction to Spark 2.0 Dataset APIdatamantra
 
Introduction to Structured Streaming
Introduction to Structured StreamingIntroduction to Structured Streaming
Introduction to Structured Streamingdatamantra
 

More from datamantra (18)

Multi Source Data Analysis using Spark and Tellius
Multi Source Data Analysis using Spark and TelliusMulti Source Data Analysis using Spark and Tellius
Multi Source Data Analysis using Spark and Tellius
 
State management in Structured Streaming
State management in Structured StreamingState management in Structured Streaming
State management in Structured Streaming
 
Understanding transactional writes in datasource v2
Understanding transactional writes in  datasource v2Understanding transactional writes in  datasource v2
Understanding transactional writes in datasource v2
 
Exploratory Data Analysis in Spark
Exploratory Data Analysis in SparkExploratory Data Analysis in Spark
Exploratory Data Analysis in Spark
 
Core Services behind Spark Job Execution
Core Services behind Spark Job ExecutionCore Services behind Spark Job Execution
Core Services behind Spark Job Execution
 
Optimizing S3 Write-heavy Spark workloads
Optimizing S3 Write-heavy Spark workloadsOptimizing S3 Write-heavy Spark workloads
Optimizing S3 Write-heavy Spark workloads
 
Understanding time in structured streaming
Understanding time in structured streamingUnderstanding time in structured streaming
Understanding time in structured streaming
 
Spark stack for Model life-cycle management
Spark stack for Model life-cycle managementSpark stack for Model life-cycle management
Spark stack for Model life-cycle management
 
Productionalizing Spark ML
Productionalizing Spark MLProductionalizing Spark ML
Productionalizing Spark ML
 
Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scala
 
Understanding Implicits in Scala
Understanding Implicits in ScalaUnderstanding Implicits in Scala
Understanding Implicits in Scala
 
Migrating to Spark 2.0 - Part 2
Migrating to Spark 2.0 - Part 2Migrating to Spark 2.0 - Part 2
Migrating to Spark 2.0 - Part 2
 
Scalable Spark deployment using Kubernetes
Scalable Spark deployment using KubernetesScalable Spark deployment using Kubernetes
Scalable Spark deployment using Kubernetes
 
Introduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actorsIntroduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actors
 
Interactive workflow management using Azkaban
Interactive workflow management using AzkabanInteractive workflow management using Azkaban
Interactive workflow management using Azkaban
 
Anatomy of Spark SQL Catalyst - Part 2
Anatomy of Spark SQL Catalyst - Part 2Anatomy of Spark SQL Catalyst - Part 2
Anatomy of Spark SQL Catalyst - Part 2
 
Introduction to Spark 2.0 Dataset API
Introduction to Spark 2.0 Dataset APIIntroduction to Spark 2.0 Dataset API
Introduction to Spark 2.0 Dataset API
 
Introduction to Structured Streaming
Introduction to Structured StreamingIntroduction to Structured Streaming
Introduction to Structured Streaming
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

Akka HTTP Intro

  • 1. Introduction to Akka HTTP Building scalable rest service in Scala https://github.com/shashankgowdal/introduction-to-akkahttp
  • 2. ● Shashank L ● Senior Software engineer at Tellius ● Part time big data consultant and trainer at datamantra.io ● www.shashankgowda.com
  • 3. Agenda ● Motivation ● Akka, Reactive streams ● Akka Http ● Akka Http High level API ● Testing ● Additional functionality ● Working with files ● Websockets ● Akka Http with Spark
  • 4. Scala frameworks to build REST API ● Play/Lift ○ Full stack web framework ● Scalatra ○ Lightweight but requires a application container for deployment ● Spray ○ Lightweight and robust as it's asynchronous and built on top of Actors ● Akka HTTP ○ Next version of Spray framework
  • 5. Why Akka HTTP ● Its 2.0 version of Spray.io ● Internals of Spray have been rewritten to use Reactive streams ● Reactive streams idea gel well with earlier ideas of Spray ● Multiple level API
  • 6. Akka ● Toolkit and runtime for building highly concurrent, distributed, and fault tolerant applications on the JVM ● Uses message passing based concurrency model ● Written in Scala ● Scale up or out ● Program at higher level ● Distributable by design ● Message passing is built on top of AkkaActor model
  • 7. Akka actor ● Receives message and takes action to handle them ● Consists of ○ Behaviour ○ State ○ Mailbox
  • 8. Reactive streams ● Asynchronous ● Stream processing ● Back-pressured ● Interoperability ● Few Implementations ○ Akka Streams ○ RxJava ○ Play ○ Kafka ● Spark streaming with Kafka receiver
  • 9. Akka streams ● Akka’s implementation of Reactive streams ● DSL for building a complete stream ● Higher level abstraction over the actor model ● Stream inputs and outputs are typesafe ● Internally uses Actor to implement Reactive stream properties
  • 11. Source, Flow and Sink com.shashank.akkahttp.IntroductionToStream implicit val sys = ActorSystem("IntroductionToStream") implicit val mat:Materializer = ActorMaterializer() val source = Source(List(1, 2, 3)) val flow = Flow[Int].map(_.toString) val sink = Sink.foreach(println) val runnableGraph = source via flow to sink runnableGraph.run()
  • 12. HTTP server with Akka streams HTTPServer as a: Flow[HttpRequest, HttpResponse] Socket input Bytes ⇒ HttpRequest HttpRequest ⇒ HttpResponse HttpResponse ⇒ Bytes Socket Sink
  • 13. Akka Http server using Flow implicit val sys = ActorSystem("IntroductionToAkkaHttp") implicit val mat:Materializer = ActorMaterializer() val requestResponseFlow = Flow.fromFunction[HttpRequest, HttpResponse]( request => { println(request.toString) HttpResponse(StatusCodes.OK, entity = "Hello!") }) Http().bindAndHandle(requestResponseFlow, "localhost", 8080) com.shashank.akkahttp.basic.serving.StreamsServing
  • 14. Akka HTTP ● Part of Akka project ● HTTP toolkit (Client and Server) ● On top of akka-actor and akka-streams ● Multiple levels of abstraction - Open API ● Scalable, Max throughput, acceptable latency ● APIs in both Scala and Java
  • 15. Akka HTTP - Implementation ● Fully asynchronous and nonblocking ● Focused on higher level API ● Lightweight ● Modular ● Testable ● Based on spray.io ● Better streaming REST functionality support
  • 17. Akka HTTP structure Akka HTTP module akka-http akka-http-core akka-http-testkit akka-http- spray-json akka-http-xml
  • 18. Akka HTTP - Parts ● akka-http-core ○ low-level server & client side HTTP implementation ● akka-http ○ high-level API : DSL, (un)marshalling, (de)compression ● akka-http-testkit ○ Utilities for testing server-side implementation ● akka-http-spray-json ○ (de)serialization from/to JSON with spray-json ● akka-http-xml ○ (de)serialization from/to XML with scala-xml
  • 19. HTTP model ● Fully immutable, case-class based ● Abstraction for most HTTP things (Types!) ● Little logic inside ● Lots of predefined types - media type, status code, encodings etc ● Efficient parsing and rendering ● Clients/Connected services should obey the standard
  • 20. HTTP model - Examples 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`) case class HttpResponse(status: StatusCode = StatusCodes.OK, headers: immutable.Seq[HttpHeader] = Nil, entity: ResponseEntity = HttpEntity.Empty, protocol: HttpProtocol = HttpProtocols.`HTTP/1.1`) case class Uri(scheme: String, authority: Authority, path: Path, rawQueryString: Option[String], fragment: Option[String])
  • 21. HTTP model - Examples object ContentTypes { val `application/json` = ContentType(MediaTypes.`application/json`) val `application/octet-stream` = ContentType(MediaTypes.`application/octet-stream`) val `text/plain(UTF-8)` = MediaTypes.`text/plain` withCharset HttpCharsets.`UTF-8` val `text/html(UTF-8)` = MediaTypes.`text/html` withCharset HttpCharsets.`UTF-8` val `text/xml(UTF-8)` = MediaTypes.`text/xml` withCharset HttpCharsets.`UTF-8` val `text/csv(UTF-8)` = MediaTypes.`text/csv` withCharset HttpCharsets.`UTF-8` val NoContentType = ContentType(MediaTypes.NoMediaType) } val `US-ASCII` = register("US-ASCII")("iso-ir-6", "ANSI_X3.4-1968", "ANSI_X3.4-1986", "ISO_646.irv:1991", "ASCII", "ISO646-US", "us", "IBM367", "cp367", "csASCII") val `ISO-8859-1` = register("ISO-8859-1")("iso-ir-100", "ISO_8859-1", "latin1", "l1", "IBM819", "CP819", "csISOLatin1") val `UTF-8` = register("UTF-8")("UTF8") val `UTF-16` = register("UTF-16")("UTF16") val `UTF-16BE` = register("UTF-16BE")() val `UTF-16LE` = register("UTF-16LE")()
  • 22. HTTP server functional way ● Low level HTTP API ● Provided by akka-http-core-module implicit val sys = ActorSystem("IntroductionToAkkaHttp") implicit val mat:Materializer = ActorMaterializer() val handler :(HttpRequest => HttpResponse) = { case HttpRequest(HttpMethods.GET, Uri.Path("/ping"), _, _, _) => HttpResponse(StatusCodes.OK, entity = "pong!") case r => HttpResponse(status = StatusCodes.BadRequest) } Http().bindAndHandleSync(handler, "localhost", 8080) com.shashank.akkahttp.basic.serving.FunctionalServing
  • 23. Akka Http high level API
  • 24. HTTP Server Nice way! ● Low level API becomes uneasy to handle when we need large number of routes ● For this we should use higher level API by akka-http ● Route using Routing DSL implicit val sys = ActorSystem("IntroductionToAkkaHttp") implicit val mat:Materializer = ActorMaterializer() val routes: Route = ??? Http(sys).bindAndHandle(route, "localhost", 8090)
  • 25. Routing DSL ● Internal domain specific language for routing ● How most services are actually written ● Layer to the application ● Type safe but flexible ● Not just routing - behaviour definition ● Very composable ● Fun, powerful and looks clean
  • 26. Routing DSL - Example val route = path("welcome"){ get{ complete { "welcome to rest service" } } } ~ path("demo"){ get{ complete { "welcome to demonstration" } } } Http().bindAndHandle(route, "localhost", 8090) com.shashank.akkahttp.basic.routing.RoutingDSL
  • 27. Directives ● A Directive is a small building block used for creating routes. ● There are some predefined directives( get, post, complete etc.) ● We can also define our custom directives. ● Roles: extracting, transforming request or response, filtering, side-effecting ● ~136 predefined directives
  • 28. Rejections ● Produced by directives ● Travel down the routing structure ● EmptyRejection is thrown when no route completes ● Can be extended ● Can be cancelled ● Handling rejection = transforming it to response ● Ex. MethodRejection, AuthorizationFailedRejection, MissingCookieRejection, MissingQueryParamRejection
  • 29. Rejections ● ~ operator connects two routes in a way that allows a second route to get a go at a request if the first route "rejected" it. path("order") { get { complete("Received GET") } ~ post { complete("Received POST") } } com.shashank.akkahttp.basic.routing.Rejection
  • 30. Failures ● Are triggered by exceptions ● Travel up the routing structure ● Can be handled by handleExceptions directive or top-level ExceptionHandler ● Can be used to simplify the flow for validation purpose com.shashank.akkahttp.basic.routing.Failure
  • 32. ● Simple and straightforward ● Allows to assert responses returned for given requests ● Integrates well with Scalatest Get("/ping") ~> route ~> check{ status === OK entity.as[String] === "It Works!" } com.shashank.akkahttp.basic.routing.TestKit Testkit
  • 34. Query parameters def parameters(param: <ParamDef[T]>): Directive1[T] ● Mandatory parameters ● Optional parameters ● Parameters with required value ● Deserialized parameter ● Repeated parameter ● Deserialized parameter into Case class
  • 35. (Un)Marshalling ● Marshalling - high level → low (wire) level ● Unmarshalling - low (wire) level → high level ● Many predefined (un) marshallers are available ● Extensible ● JSON and XML supported ● Type-class approach - Implicit resolution
  • 36. Custom Http entity data ● Akka Http JSON support ● Support conversion to and from JVM objects to wire representation like JSON, XML etc ● SprayJsonSupport provides a FromEntityUnmarshaller[T] and ToEntityMarshaller[T] for every type T with Spray Json Reader/Writer com.shashank.akkahttp.basic.routing.CustomEntityWithJson
  • 37. Custom directive ● Configuration labelling ● Transforming existing directives ● Directive0, Directive1 ● Authorization ● Authentication com.shashank.akkahttp.basic.routing.CustomDirective
  • 39. File upload def uploadedFile(fieldName: String): Directive1[(FileInfo, File)] ● Streams the contents of a file uploaded as a multipart form into a temporary file on disk ● Cannot start processing the file unless it written completely to temporary file com.shashank.akkahttp.basic.routing.FileUpload
  • 40. File upload stream def fileUpload(fieldName: String): Directive1[(FileInfo, Source[ByteString, Any])] ● Simple access to the stream of bytes for a file uploaded as a multipart form together with metadata about the upload as extracted value. com.shashank.akkahttp.basic.routing.FileUploadStream
  • 42. Websocket ● WebSocket is a protocol that provides a bi-directional channel between browser and webserver ● Data is exchanged in messages whereby a message can either be binary data or unicode text
  • 43. Server side websocket in AkkaHttp ● Akka HTTP provides a stream-based implementation of the WebSocket protocol ● basic unit of data exchange in the WebSocket is a message i.e TextMessage or BinaryMessage ● Websocket handshake is managed and hidden from application layer ● A message handler is expected to be implemented as a Flow[Message, Message, Any] ● Testing Websocket using WSProbe com.shashank.akkahttp.basic.routing.Websocket
  • 44. Akka HTTP with Spark Spark Cluster Akka Http Rest server Client HDFS
  • 45. Pros and Cons ● Pros ○ Backed by Lightbend(Typesafe) ○ Integration layers ○ Microservices ○ Pure REST APIs ● Cons ○ Full fledged web applications (server side template generation) ○ Not mature enough ○ Easy to start, hard to master
  • 46. References ● Akka HTTP - A reactive web toolkit ● Akka HTTP - What, Why and How ● Introduction to Akka HTTP ● Akka HTTP documentation http://doc.akka.io/docs/akka/2.4.2/scala/http/ ● http://blog.madhukaraphatak.com/categories/akka-http/