Skip to content

Instantly share code, notes, and snippets.

@ericwush
Last active July 9, 2017 07:05
Show Gist options
  • Save ericwush/d703eda7bf2288d03c22f31581b48988 to your computer and use it in GitHub Desktop.
Save ericwush/d703eda7bf2288d03c22f31581b48988 to your computer and use it in GitHub Desktop.
import akka.actor.{Actor, ActorRef, Props}
import com.redis.{Publish, Publisher}
import Models.RedisPublishMessage
object RedisPubActor {
def props(redis: Redis): Props = {
val publisherProps = Props(new Publisher(redis.client))
Props(new RedisPubActor(publisherProps))
}
}
class RedisPubActor(publisherProps: Props) extends Actor {
private val publisher: ActorRef = context.actorOf(publisherProps)
def receive: Receive = {
case RedisPublishMessage(ch, msg) => publish(ch, msg)
}
private def publish(channel: String, message: String) = {
publisher ! Publish(channel, message)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment