learning scala akka tell pattern(二)

package com.example
import akka.actor._
object Tutorial_02_Tell_Pattern extends  App {
    println("Step 1: Create an actory system")
    val system = ActorSystem("DonutStoreActorSystem")

    val donutInActor = system.actorOf(Props[DonutInActor], name = "DonutInfoActor")

    import  DonutStoreProtocal._
    donutInActor ! Info("panzidong running!")

    val isTerminated = system.terminate()

    object DonutStoreProtocal {
      case class Info(name: String)
    }

    class DonutInActor extends Actor with ActorLogging{
      import  Tutorial_02_Tell_Pattern.DonutStoreProtocal._

      override def receive: Receive = {
        case Info(name) =>{
          log.info(s"Found $name dount")
        }
      }
    }

}

result:

 

Step 1: Create an actory system
[INFO] [08/23/2019 16:14:12.079] [DonutStoreActorSystem-akka.actor.default-dispatcher-3] [akka://DonutStoreActorSystem/user/DonutInfoActor] Found panzidong running! dount

 

posted @ 2019-08-23 16:17  嵌入式实操  阅读(148)  评论(0编辑  收藏  举报