PersistentActor 没有收到命令

PersistentActor doesn't receive command

我已经实现了以下 PersistedActor

import akka.actor._
import akka.persistence._

object TaskDispatcher {

  /**
   * Create Props for the actor
   */
  def props(): Props = Props(new TaskDispatcher())

  case class AddEndpoint(serverEndpoint: ActorRef, id: String)
}

class TaskDispatcher() extends PersistentActor with ActorLogging {
  import TaskDispatcher._

  override def persistenceId = "task-dispatcher-persistence-ID"

  // Actor State
  var endpoints: Map[String, ActorRef] = Map()


  def receiveRecover: Receive = {
    case AddEndpoint(serverEndpoint, id) =>
      endpoints += (id -> serverEndpoint)

  }

  def receiveCommand: Receive = {

    case AddEndpoint(serverEndpoint, id) =>
      log.info("AddEndpoint received")
      persistAsync(AddEndpoint(serverEndpoint, id)) { command =>
        endpoints += (id -> serverEndpoint)
      }
  }

}

我创建了一个 PersistedActor 的实例,并通过另一个 actor 向它发送了一条消息 AddEndpoint

val taskDispatcher =
    context.actorOf(Props[TaskDispatcher], "task-dispatcher")
taskDispatcher ! AddEndpoint(self, id)

之前我有这个演员的非持久化版本并且一切正常。现在演员没有收到 AddEndpoint 消息。我注意到它是因为日志不打印 "AddEndpoint received" 消息。我做错了什么?

也许只是恢复没有开始。尝试地点:

override def preStart() = {
  self ! Recover()
}