Created
June 10, 2018 13:52
-
-
Save adamw/552501a6f4b10271facc130373c57709 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class ConsumeQueueActor(connector: QueueConnector[Future]) | |
extends Actor with ActorLogging { | |
import context.dispatcher | |
private var currentQueue: Option[Queue[Future]] = None | |
// ... | |
override def receive: Receive = { | |
case queue: Queue[Future] => | |
if (currentQueue.isEmpty) { | |
log.info("[queue-start] connected") | |
currentQueue = Some(queue) | |
} | |
log.info("[queue] receiving message") | |
queue | |
.read() | |
.pipeTo(self) // forward message to self | |
.andThen { case Success(_) => self ! queue } // receive next message | |
case msg: String => | |
context.parent ! Received(msg) | |
case Failure(e) => | |
log.info(s"[queue] failure: ${e.getMessage}") | |
throw e | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment