Skip to content

Instantly share code, notes, and snippets.

@lregnier
Last active May 30, 2017 18:05
Show Gist options
  • Save lregnier/fd931fe7e0f777f97574627b574ec996 to your computer and use it in GitHub Desktop.
Save lregnier/fd931fe7e0f777f97574627b574ec996 to your computer and use it in GitHub Desktop.
Akka Pool Router
import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
import akka.event.Logging
import akka.routing.RoundRobinPool
import scala.concurrent.Await
import scala.concurrent.duration._
object RouteeActor {
def props(): Props = Props[RouteeActor]
}
class RouteeActor extends Actor with ActorLogging {
log.info("Starting route actor: {}", self)
def receive = {
case msg => log.info("Message received: {}", msg)
}
}
object Main extends App {
implicit val system = ActorSystem("api-akka-http-system")
val log = Logging(system, getClass)
// Initialize router
val router = system.actorOf(RoundRobinPool(5).props(RouteeActor.props()), "router")
scala.sys.addShutdownHook{
log.info("Shutting down server and actor system")
system.terminate()
Await.result(system.whenTerminated, 30 seconds)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment