Created
August 27, 2014 09:03
-
-
Save maiha/ddd4606461445be28930 to your computer and use it in GitHub Desktop.
DeadLetterWatcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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