Skip to content

Instantly share code, notes, and snippets.

@prassee
Created January 29, 2016 08:55
Show Gist options
  • Save prassee/10475e9eb9fadfdbedec to your computer and use it in GitHub Desktop.
Save prassee/10475e9eb9fadfdbedec to your computer and use it in GitHub Desktop.
a simple EventStream in Actor
import akka.actor._
case class Feed(name: String)
class FeedSubscriber extends Actor {
def receive = {
case feed: Feed => println(s"""feed received at ${feed} ${self.path}""")
}
}
object FeedStream extends App {
val as = ActorSystem("FeedAS")
val feedSub1 = as.actorOf(Props[FeedSubscriber], "fs1")
val feedSub2 = as.actorOf(Props[FeedSubscriber], "fs2")
as.eventStream.subscribe(feedSub1, classOf[Feed])
as.eventStream.subscribe(feedSub2, classOf[Feed])
def publishFeed(feed: Feed) = {
as.eventStream.publish(feed)
}
publishFeed(Feed("feed1"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment