Search code examples
akka-persistence

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


I'm new to akka and try to learn akka following the video tutorials here.

The author has explained the code but didn't explain anything about configuration at all.

My actor code is

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"
}

My src/resources/reference.conf is

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=

My main class is

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()

When I execute the main class, I'm encountering the below error -

[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$1(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)

I understand I need to configure the property akka.persistence.snaphot-store.local.class in reference.conf, but I'm not sure of the value.

The full code is in here.

Also, please help me if some more configuration is needed for this program other than this.


Solution

  • The problem in your configuration is that there is a typo (repeated two times) snaphot-store instead of snapshot-store. And you don't need to set a customized value for akka.persistence.snaphot-store.local.class.

    Here's the correct configuration:

    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