Skip to content

Commit

Permalink
[tutorial-5] akka-http work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielaSfregola committed Jan 11, 2016
1 parent 6d9b838 commit 5cf3b5c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
5 changes: 2 additions & 3 deletions tutorial-5/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ resolvers ++= Seq("Typesafe Repository" at "http://repo.typesafe.com/typesafe/re

libraryDependencies ++= {
val AkkaVersion = "2.3.9"
val SprayVersion = "1.3.2"
val AkkaHttpVersion = "2.0.1"
val Json4sVersion = "3.2.11"
Seq(
"io.spray" %% "spray-can" % SprayVersion,
"io.spray" %% "spray-routing" % SprayVersion,
"com.typesafe.akka" %% "akka-slf4j" % AkkaVersion,
"com.typesafe.akka" %% "akka-http-experimental" % AkkaHttpVersion,
"ch.qos.logback" % "logback-classic" % "1.1.2",
"org.json4s" %% "json4s-native" % Json4sVersion,
"org.json4s" %% "json4s-ext" % Json4sVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
package com.danielasfregola.quiz.management

import scala.concurrent.duration._
import akka.actor._
import akka.io.IO
import akka.pattern.ask
import akka.http.scaladsl.Http
import akka.stream.ActorMaterializer
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import spray.can.Http

import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory

object Main extends App {
val config = ConfigFactory.load()
val host = config.getString("http.host")
val port = config.getInt("http.port")

implicit val system = ActorSystem("quiz-management-service")
implicit val materializer = ActorMaterializer()


implicit val executionContext = system.dispatcher
implicit val timeout = Timeout(10 seconds)

val api = system.actorOf(Props(new RestInterface))

IO(Http).ask(Http.Bind(listener = api, interface = host, port = port))
.mapTo[Http.Event]
.map {
case Http.Bound(address) =>
println(s"REST interface bound to $address")
case Http.CommandFailed(cmd) =>
println("REST interface could not bind to " +
s"$host:$port, ${cmd.failureMessage}")
system.shutdown()
}
val api = ???

Http().bindAndHandle(handler = api, interface = host, port = port) map { binding =>
println(s"REST interface bound to ${binding.localAddress}") } recover { case ex =>
println(s"REST interface could not bind to $host:$port", ex.getMessage)
}
}

0 comments on commit 5cf3b5c

Please sign in to comment.