2017-01-10 2 views
0

이 오픈 소스를 사용하여 MongoDb에 의해 지원되는 akka-persistence와 함께 "hello-world"예제를 시도했습니다. https://github.com/scullxbones/akka-persistence-mongo/tree/master/rxmongo/src. 아래는 제 코드입니다. 그러나 응용 프로그램을 실행할 때 시간 초과를 묻는 메시지가 나타납니다.액터가 akka-persistence에서 타임 아웃을 요청합니다.

akka.pattern.AskTimeoutException : [2000 ms] 후에 [Actor [akka : // example/user/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 
      } 
     } 
     } 
    } 

    } 

, 어떤 명령은 없습니다 지속되었다.

감사합니다! 당신의 application.conf에서

답변

0

저널 및 스냅 샷 플러그인을 지정해야합니다 :

akka.persistence.journal.plugin = "akka-contrib-mongodb-persistence-journal" 
akka.persistence.snapshot-store.plugin = "akka-contrib-mongodb-persistence-snapshot" 

을 그리고 당신이 보낸 사람에게 응답해야하므로 수신이된다 :

override val receiveCommand: Receive = { 
    case Command(value) => 
    persist(Event(value)) { persistedEvent => 
     updateState(persistedEvent) 
     sender ! SomeResponse 
    } 
}