src/main/scala/Example.scala
changeset 4 b25c02bd6b11
parent 2 04af787ba66f
equal deleted inserted replaced
3:e8daf3ff497d 4:b25c02bd6b11
     1 package couchdb.changes
     1 package couchdb.changes
     2 
     2 
     3 import akka.actor._
     3 import akka.actor._
     4 import spray.http.Uri
     4 import spray.http.Uri
     5 import com.typesafe.config.ConfigFactory
       
     6 
     5 
     7 object LoggingActor extends Actor with ActorLogging {
     6 object LoggingActor extends Actor with ActorLogging {
     8   log.info("Initializing LoggingActor")
     7   log.info("Initializing LoggingActor")
     9   def receive: Receive = {
     8   def receive: Receive = {
    10     case x => log.info("Received {}", x)
     9     case x => log.info("Received {}", x)
    11   }
    10   }
    12 }
    11 }
    13 
    12 
    14 object Example extends App with settings {
    13 case object Start
       
    14 
       
    15 object Example extends App {
    15 
    16 
    16   val system = ActorSystem()
    17   val system = ActorSystem()
    17   val stream = system.actorOf(Props(new ChangesStreamActor(
    18   val stream = system.actorOf(Props(new ChangesStreamActor(
    18     system.actorOf(Props(LoggingActor)))))
    19     system.actorOf(Props(LoggingActor)))))
    19 
    20 
    20   def config = ConfigFactory.load()
    21   stream ! Start
    21 
       
    22   stream ! Uri(s"${couchConf.url}/_changes").withQuery(
       
    23     "feed" -> "continuous"
       
    24   , "heartbeat" -> couchConf.heartbeat.toMillis.toString
       
    25   , "include_docs" -> "true"
       
    26   )
       
    27 
       
    28 }
    22 }
    29 
    23 
    30 import com.wacai.config.annotation._
    24 import com.wacai.config.annotation._
    31 import scala.concurrent.duration._
    25 import scala.concurrent.duration._
       
    26 
    32 @conf trait settings extends Configurable {
    27 @conf trait settings extends Configurable {
    33   val couchConf = new {
    28   val couchConf = new {
    34     val url = "http://localhost:5984/example"
    29     val url = "http://localhost:5984/example"
    35     val heartbeat = 5 seconds
    30     val heartbeat = 5 seconds
       
    31     val reconnect = 45 seconds
    36   }
    32   }
    37 }
    33 }
    38 
    34 
    39 // vim: set ts=2 sw=2 et:
    35 // vim: set ts=2 sw=2 et: