Skip to content

Instantly share code, notes, and snippets.

@maiha
Created August 27, 2014 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maiha/ddd4606461445be28930 to your computer and use it in GitHub Desktop.
Save maiha/ddd4606461445be28930 to your computer and use it in GitHub Desktop.
DeadLetterWatcher
import akka.actor._
import com.typesafe.scalalogging.slf4j.StrictLogging
/** DeadLetterを監視するactor
*/
object DeadLetterWatcher {
val actorName = "dead_letter_watcher"
def props(): Props = Props(new DeadLetterWatcher)
def apply(context: ActorRefFactory): ActorRef = context.actorOf(props(), actorName)
}
class DeadLetterWatcher extends Actor with StrictLogging {
override def preStart(): Unit = {
super.preStart()
context.system.eventStream.subscribe(self, classOf[DeadLetter])
}
override def postStop(): Unit = {
context.system.eventStream.unsubscribe(self, classOf[DeadLetter])
super.postStop()
}
override def receive: Receive = {
case DeadLetter(msg, from, to) =>
println(s"new dead letter: $msg $from $to")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment