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ミリ秒]後:[//例/ユーザー/ 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 
    } 
} 
関連する問題