0
我嘗試了「你好,世界」的例子與MongoDB的支持阿卡的持久性,使用這個開源,https://github.com/scullxbones/akka-persistence-mongo/tree/master/rxmongo/src。以下是我的代碼。然而,當我運行應用程序,我問超時:演員問超時在阿卡持久性
akka.pattern.AskTimeoutException:2000毫秒]後://例子/用戶/ sampleActor#1876558089]演員[阿卡]請教關於超時。 Sender [null]發送類型爲「actors.Command」的消息。
import akka.actor.{ActorSystem, Props}
import akka.pattern.ask
import akka.persistence.{PersistentActor, RecoveryCompleted}
import akka.util.Timeout
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.language.postfixOps
object Main extends App {
implicit val timeout = Timeout(2 seconds)
val system = ActorSystem("example")
var actor = system.actorOf(SampleActor.props(), "sampleActor")
Await.result(actor ? Command("first"), Duration.Inf)
Await.result(actor ? Command("second"), Duration.Inf)
system.stop(actor)
system.terminate()
}
case class Command(value: String)
case class Event(value: String)
case class SampleState(counter: Int, lastValue: Option[String])
class SampleActor extends PersistentActor {
override def persistenceId = "id-1"
var state = SampleState(0, None)
def updateState(event: Event): Unit = {
state = state.copy(counter = state.counter + 1, lastValue = Some(event.value))
}
override val receiveCommand: Receive = {
case Command(value) =>
persist(Event(value))(updateState)
}
override def receiveRecover: Receive = {
case event: Event =>
updateState(event)
case RecoveryCompleted =>
println("Recovery completed")
}
}
object SampleActor {
def props(): Props = Props(new SampleActor())
}
這裏是我的application.conf:(!)(?)
contrib {
persistence {
mongodb {
mongo {
mongouri = "mongodb://localhost:27017/akka-persistence"
driver = "akka.contrib.persistence.mongodb.RxMongoPersistenceExtension"
}
rxmongo {
failover {
initialDelay = 750ms
retries = 10
growth = con
factor = 1.5
}
}
}
}
}
如果我使用tell,而不是問,什麼也沒有發生,數據庫沒有建立,也沒有命令持續存在。
謝謝!