akka typed actor 实例之hello
所属分类 akka
浏览量 715
Classic Actors
https://doc.akka.io/docs/akka/current/actors.html
Akka Classic pertains to the original Actor APIs, which have been improved by more type safe and guided Actor APIs.
Akka Classic is still fully supported and existing applications can continue to use the classic APIs.
It is also possible to use the new Actor APIs together with classic actors in the same ActorSystem
typed actor
https://doc.akka.io/docs/akka/current/typed/actors.html
package com.example
import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.{ActorRef, ActorSystem, Behavior}
final case class Msg(msg: String, sender: ActorRef[Msg])
object HelloTypedActor {
def apply(): Behavior[Msg] = Behaviors.receive { (context, message) =>
println("receive msg " + message.msg + ",sender=" + message.sender + ",self=" + context.self)
Behaviors.same
}
}
object HelloActorMain extends App {
val helloActor: ActorSystem[Msg] = ActorSystem(HelloTypedActor(), "helloTypedActor")
helloActor ! Msg("hello", null)
helloActor ! Msg("akka", null)
helloActor ! Msg("typed", null)
helloActor ! Msg("actor", null)
}
完整代码
https://gitee.com/dyyx/hellocode/blob/master/demo/scala/akka/akka-quickstart-scala-maven/src/main/java/com/example/HelloTypedActor.scala
akka actor demo
akka actor ask 模式 实例
上一篇
下一篇
scala模式匹配中的@
Scala foldLeft foldRight
play json库简介
akka typed actor 实例之 echo
scala技术栈新人学习指南
Scala 偏函数 例子1