像产卵演员问题
Akka spawn actor issue
我正在努力实现“演员面料”。应用程序包含 fabric-actor,它必须按需生成子 actors。
我尝试实现如下:
object BranchCreator {
final case class CreateBranche(name: String)
def apply(): Behavior[CreateBranche] = {
Behaviors.receiveMessage { (context, message) =>
context.spawn(new Branch(), message.name)
}
}
}
但是 spawn 方法不适用于上下文。只有“名称”和“复制”可用于上下文。
使用Behaviors.receive
代替Behaviors.receiveMessage
根据 Behaviors.receiveMessage 的文档:
Simplified version of Behaviors.Receive with only a single argument - the message to be handled. Useful for when the context is already accessible by other means, like being wrapped in an setup or similar.
[cut]
我正在努力实现“演员面料”。应用程序包含 fabric-actor,它必须按需生成子 actors。
我尝试实现如下:
object BranchCreator {
final case class CreateBranche(name: String)
def apply(): Behavior[CreateBranche] = {
Behaviors.receiveMessage { (context, message) =>
context.spawn(new Branch(), message.name)
}
}
}
但是 spawn 方法不适用于上下文。只有“名称”和“复制”可用于上下文。
使用Behaviors.receive
代替Behaviors.receiveMessage
根据 Behaviors.receiveMessage 的文档:
Simplified version of Behaviors.Receive with only a single argument - the message to be handled. Useful for when the context is already accessible by other means, like being wrapped in an setup or similar. [cut]