import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
object AkkaMain {
class SimpleActor extends Actor with ActorLogging {
override def receive: Receive = {
case message => log.info(message.toString)
case (a, b) => log.warning(s"tuple {} and {}", a, b)
}
}
object SimpleActor {
def props() = Props(new SimpleActor())
}
def main(args: Array[String]): Unit = {
val actorSystem: ActorSystem = ActorSystem(name = "actorDemo")
val simpleActor = actorSystem.actorOf(SimpleActor.props(), "simpleActor")
simpleActor ! "Hi"
simpleActor ! ("A", 2)
}
}
결과
19:39:22.810 [actorDemo-akka.actor.default-dispatcher-5] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
19:39:22.998 [actorDemo-akka.actor.default-dispatcher-6] INFO com.github.windbird123.AkkaMain$SimpleActor - Hi
19:39:23.002 [actorDemo-akka.actor.default-dispatcher-6] INFO com.github.windbird123.AkkaMain$SimpleActor - (A,2)