我已经实现了以下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收到"信息。我做错了什么?
答案 0 :(得分:1)
也许只是恢复并没有开始。试试地点:
StringEscapeUtils