1
父母子女在父母向孩子发送消息并且孩子以值1回应的父孩子中,但父母没有收到该值,因为消息“received”是1“不会打印到控制台。Akka父母未收到来自子女的消息
我的层次设置是否正确? :
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Props
class ChildActor extends Actor {
def receive = {
case receivedValue: Int => {
println(receivedValue);
context.parent ! 1
}
}
}
object ParentChild extends App {
val system = ActorSystem()
val parentActor = system.actorOf(Props[ParentActor])
class ParentActor extends Actor {
val childActor = system.actorOf(Props[ChildActor])
childActor ! 1
def receive = {
case v: Int => println("received is " + v);
}
}
}
你在哪里发送信息给Child actor? – curious
问题是小孩的演员其实并不是父母的孩子,演员不会成为小孩演员就是在父母身上创造一个引用,实际上你需要在父母的背景下创建一个引用。因此,不需要'system.actorOf(Props [ChildActor])''你需要执行'context.actorOf(Props [ChildActor])'。 – curious
@curious那个工作,如果投入回答不好接受 –