2013-09-14 14:19:18 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package sample.persistence
|
|
|
|
|
|
|
|
|
|
import akka.actor._
|
|
|
|
|
import akka.persistence._
|
|
|
|
|
|
|
|
|
|
object ProcessorChannelExample extends App {
|
|
|
|
|
class ExampleProcessor extends Processor {
|
|
|
|
|
val channel = context.actorOf(Channel.props, "channel")
|
|
|
|
|
val destination = context.actorOf(Props[ExampleDestination])
|
|
|
|
|
|
|
|
|
|
def receive = {
|
2013-12-03 16:34:26 +01:00
|
|
|
case p @ Persistent(payload, _) =>
|
2013-09-14 14:19:18 +02:00
|
|
|
println(s"processed ${payload}")
|
2014-01-17 06:58:25 +01:00
|
|
|
channel ! Deliver(p.withPayload(s"processed ${payload}"), destination.path)
|
|
|
|
|
case reply: String =>
|
|
|
|
|
println(s"reply = ${reply}")
|
2013-09-14 14:19:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ExampleDestination extends Actor {
|
|
|
|
|
def receive = {
|
2013-12-03 16:34:26 +01:00
|
|
|
case p @ ConfirmablePersistent(payload, snr, _) =>
|
2013-09-14 14:19:18 +02:00
|
|
|
println(s"received ${payload}")
|
|
|
|
|
sender ! s"re: ${payload} (${snr})"
|
|
|
|
|
p.confirm()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val system = ActorSystem("example")
|
2013-09-26 09:14:43 +02:00
|
|
|
val processor = system.actorOf(Props(classOf[ExampleProcessor]), "processor-1")
|
2013-09-14 14:19:18 +02:00
|
|
|
|
2014-01-17 06:58:25 +01:00
|
|
|
processor ! Persistent("a")
|
|
|
|
|
processor ! Persistent("b")
|
2013-09-14 14:19:18 +02:00
|
|
|
|
|
|
|
|
Thread.sleep(1000)
|
|
|
|
|
system.shutdown()
|
|
|
|
|
}
|