Last active
May 30, 2017 18:05
-
-
Save lregnier/fd931fe7e0f777f97574627b574ec996 to your computer and use it in GitHub Desktop.
Akka Pool Router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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