你可以发一封信
Receptionist.Subscribe(Maker.makerKey)
发送给接待员的信息,如Akka文档中所述
Actor discovery
context.system.receptionist ! Receptionist.Subscribe(Maker.makerKey, listingResponseAdapter)
引用文件:
这允许它接收制造商
ActorRef
ClientIn
可能会收到其他消息,例如
Command
在这之前。它将需要处理这些案件,也许需要
stashing
或删除命令,直到
Maker
首先,通过
ActorRef公司
到
ClientIn.apply
val maker = context.spawn(Maker(), "mmaker")
val clientIn = context.spawn(ClientIn(maker), "ClientIn")
然后,在
客户端
def apply(maker: ActorRef[Maker.MMCommand]): Behavior[ClientInCommand] = {
Behaviors.setup { context =>
context.log.info(s"ClientIn starting...${context.self}")
Behaviors.receiveMessage[ClientInCommand] {
case Watch(symbol) =>
context.log.info(s"ClientIn watch message received..$symbol")
Behaviors.same
case Command(value) =>
context.log.info(s"ClientInCommand.Command with value:$value")
maker ! Maker.ReceiveCommand(value)
Behaviors.same
}
}
}
请注意
ActorRef公司
spawn
即使参与者尚未完全初始化,也能够立即接收消息。