Skip to content

Instantly share code, notes, and snippets.

@LukasGasior1
Last active August 29, 2015 14:25
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 LukasGasior1/b1e96a9f5ac09d0b50e5 to your computer and use it in GitHub Desktop.
Save LukasGasior1/b1e96a9f5ac09d0b50e5 to your computer and use it in GitHub Desktop.
class SubscriberActor(statsActor: ActorRef) extends ActorSubscriber {
override def receive = {
case OnNext(message: Message) =>
for {
eventType <- message.headers.get("type") if eventType == "DiceRolled"
content <- parseOpt(message.body.decodeString("UTF-8"))
JInt(rolledNumber) <- content \ "rolledNumber"
} statsActor ! StatsActor.IncRollsCount(rolledNumber.toInt)
case OnComplete =>
log.info("Game stream completed, shutting down system")
system.shutdown()
case OnError(cause) =>
log.error(cause, "Publisher error occurred, shutting down system")
system.shutdown()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment