I am trying to use akka persistent actors and the jdbc plugin for the journal. However, my persistent actors do not receive/handle the incomming messages with the receiveCommand function. However, I do not get dead letter messages so I do not know what is going wrong.
application.conf file:
akka {
loglevel = DEBUG
actor {
#provider = cluster
}
persistence {
journal.plugin = "jdbc-journal"
snapshot-store.plugin = "jdbc-snapshot-store"
}
}
jdbc-journal {
slick = ${slick}
}
# the akka-persistence-snapshot-store in use
jdbc-snapshot-store {
slick = ${slick}
}
jdbc-read-journal {
slick = ${slick}
}
slick {
profile = "slick.jdbc.MySQLProfile$"
dataSourceClass = "slick.jdbc.DriverDataSource"
db {
dataSourceClass = "slick.jdbc.DriverDataSource"
driver = "com.mysql.cj.jdbc.Driver"
url = "jdbc:mysql://localhost:3306/squirrel_persistence"
user = "root"
password = ""
numThreads = 5
maxConnections = 5
minConnections = 1
}
}
code from actor:
class ExampleActor extends PersistentActor {
override def persistenceId = "sample-id-1"
var state = ExampleState()
def updateState(event: Evt): Unit = {
state = state.updated(event)
}
def numEvents =
state.size
override def receiveRecover: Receive = {
case evt: Evt => updateState(evt)
case SnapshotOffer(_, snapshot: ExampleState) => state = snapshot
}
val snapShotInterval = 1000
override def receiveCommand: Receive= {
case Cmd(data) => {
println("in the command code block")
persist(Evt(s"${data}-${numEvents}")) { event => {
updateState(event)
context.system.eventStream.publish(event)
if (lastSequenceNr % snapShotInterval == 0 && lastSequenceNr != 0)
saveSnapshot(state)
}
}
}
case "print"=>println(state)
}
}
test code:
class ShoppingCartSpec extends TestKit(ActorSystem("test-System"
,ConfigFactory.parseFile(new File("src/test/resources/application.conf")).resolve()
)) with AnyWordSpecLike with ImplicitSender {
"The persistent actor" should {
"Test Command" in {
val persistentActor = system.actorOf(Props[ExampleActor](),"persistentActor1")
Thread.sleep(2000)
println("before the send")
persistentActor ! Cmd("foo")
persistentActor ! Cmd("bar")
persistentActor ! Cmd("fizz")
persistentActor ! Cmd("buzz")
persistentActor ! "print"
Thread.sleep(10000)
println("after messages should be sent and received")
}
}
}
Is there something obvious I am missing ? thanks in advance!