为什么坚持方法永远行不通?

why persist method never works?

我一直在使用 persistenceActor,但是当我调用 persist() 方法时,回调 永远不会到达我 在终端中找不到任何错误


演员代码

   class MajorEventActor extends Timers with PersistentActor with ActorLogging{
    var currentSeqNr = 0;
    timers.startTimerWithFixedDelay("majorevent",FetchMajor,1 hour)
    override def receiveRecover: Receive = {
      case value:MajorEvent =>
          log.info("\u001b[31;1mrecovering major event")
          currentSeqNr = currentSeqNr + 1
    }
    override def receiveCommand: Receive = {   
      case FetchMajor =>
       log.info("start")
        getMajorEvent.onComplete{
          case Success(value) => //value is country
            log.info(s"$value")
            persist(value){e=>{
              log.info(s"$e")
              log.info("\u001b[32;1mvalue is persisted in levelDB")
              currentSeqNr = currentSeqNr + 1
            }}
            log.info("complete")
          case Failure(value) =>  println("\u001b[32;1merror from wikipedia")
        }
    }

    override def persistenceId: String = "majorevent"
  }

终端输出

[INFO] [05/03/2020 15:58:31.082] [main-akka.actor.default-dispatcher-4] [akka://main/user/event] start
[INFO] [05/03/2020 15:58:34.019] [main-akka.actor.default-dispatcher-5] [akka://main/user/event] MajorEvent(Major events of COVID19 pandemic in India in May,List(News(1 May,Nationwide lock-down further extended till 17 May), News(2 May,10,000 confirmed recoveries)))
[INFO] [05/03/2020 15:58:34.019] [main-akka.actor.default-dispatcher-5] [akka://main/user/event] complete

配置文件

  akka.persistence.journal.plugin = "akka.persistence.journal.leveldb"
akka.persistence.journal.leveldb.dir = "target/levelDB/journal"


akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.local"
akka.persistence.snapshot-store.local.dir = "target/levelDB/snapshots"
akka.actor.allow-java-serialization = on

主要class

val majorEvent = actor.actorOf(Props[MajorEventActor],"event")
   majorEvent ! FetchMajor

使用来自 akka.pattern

的 pipeTo 方法解决了问题