插件 class 名称必须在配置 属性 [akka.persistence.snaphot-store.local.class] 中定义

Plugin class name must be defined in config property [akka.persistence.snaphot-store.local.class]

我是 akka 的新手,尝试按照视频教程学习 akka here

作者已经解释了代码,但根本没有解释配置。

我的演员代码是

import akka.actor._
import akka.persistence.{PersistentActor, SnapshotOffer}
import Counter._

object Counter {

  sealed trait Operation {
    val count: Int
  }

  case class Increment(override val count: Int) extends Operation
  case class Decrement(override val count: Int) extends Operation

  case class Cmd(op: Operation)
  case class Event(op: Operation)

  case class State(count: Int)
}


class Counter extends PersistentActor with ActorLogging {

  println(s"Starting...")

  var state: State = State(0)

  def updateState(evt: Event): Unit = {
    evt.op match {
      case Increment(count) =>
        state = State(state.count + count)
      case Decrement(count) =>
        state = State(state.count - count)
    }
  }

  override def receiveRecover: Receive = {
    case evt: Event =>
      updateState(evt)
    case SnapshotOffer(_, snaphot: State) =>
      state = snaphot
  }

  override def receiveCommand: Receive = {
    case cmd @ Cmd(op) =>
       println(s"counter received command $op")
       persist(Event(op)) { evt =>
         updateState(evt)
       }
    case "print" =>
      println(s"current state of the counter is $state")
  }

  override def persistenceId: String = "counter-example"
}

我的 src/resources/reference.conf 是

akka.persistence.journal.plugin="akka.persistence.journal.leveldb"
akka.persistence.snapshot-store.plugin="akka.persistence.snaphot-store.local"
akka.persistence.journal.leveldb.dir="target/sample/leveldb"
akka.persistence.snaphot-store.local.dir="target/sample/snapshots"
akka.persistence.journal.leveldb.native=off
#akka.persistence.snaphot-store.local.class=

我的主要 class 是

val system = ActorSystem("persistent")
val persistentActor = system.actorOf(Props[Counter], "counter")

persistentActor ! Increment(3)
persistentActor ! Increment(5)
persistentActor ! Decrement(2)

persistentActor ! "print"

Thread.sleep(5000L)

system.terminate()

当我执行主要 class 时,遇到以下错误 -

[ERROR] [01/13/2018 20:53:13.961] [persistent-akka.actor.default-dispatcher-5] [akka://persistent/user/counter] Plugin class name must be defined in config property [akka.persistence.snaphot-store.local.class]
akka.actor.ActorInitializationException: akka://persistent/user/counter: exception during creation
    at akka.actor.ActorInitializationException$.apply(Actor.scala:193)
    at akka.actor.ActorCell.create(ActorCell.scala:608)
    at akka.actor.ActorCell.invokeAll(ActorCell.scala:462)
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:484)
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282)
    at akka.dispatch.Mailbox.run(Mailbox.scala:223)
    at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
    at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.lang.IllegalArgumentException: Plugin class name must be defined in config property [akka.persistence.snaphot-store.local.class]
    at akka.persistence.Persistence.akka$persistence$Persistence$$createPlugin(Persistence.scala:296)

我了解我需要在 reference.conf 中配置 属性 akka.persistence.snaphot-store.local.class,但我不确定该值。

完整代码在here.

此外,如果此程序需要除此以外的更多配置,请帮助我。

您的配置中的问题是有一个错字(重复两次)snaphot-store 而不是 snapshot-store。而且您不需要为 akka.persistence.snaphot-store.local.class.

设置自定义值

正确配置如下:

akka.persistence.journal.plugin="akka.persistence.journal.leveldb"
akka.persistence.snapshot-store.plugin="akka.persistence.snapshot-store.local"
akka.persistence.journal.leveldb.dir="target/sample/leveldb"
akka.persistence.snapshot-store.local.dir="target/sample/snapshots"
akka.persistence.journal.leveldb.native=off