Skip to content

Instantly share code, notes, and snippets.

@patriknw
Created July 5, 2013 06:33
Show Gist options
  • Save patriknw/5932409 to your computer and use it in GitHub Desktop.
Save patriknw/5932409 to your computer and use it in GitHub Desktop.
Pub/Sub Spotlight
class Publisher extends Actor {
import DistributedPubSubMediator.Publish
// activate the extension
val mediator = DistributedPubSubExtension(context.system).mediator
def receive = {
case in: String ⇒
val out = in.toUpperCase
mediator ! Publish("content", out)
}
}
class Subscriber extends Actor with ActorLogging {
import DistributedPubSubMediator.Subscribe
val mediator = DistributedPubSubExtension(context.system).mediator
// subscribe to the topic named "content"
mediator ! Subscribe("content", self)
def receive = {
case s: String => log.info("Got {}", s)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment