Skip to content

Instantly share code, notes, and snippets.

@photex
Created November 12, 2012 21:19
Show Gist options
  • Save photex/4061969 to your computer and use it in GitHub Desktop.
Save photex/4061969 to your computer and use it in GitHub Desktop.
import play.api._
import play.api.libs.concurrent.Akka
import akka.actor.Props
import akka.routing.SmallestMailboxRouter
import com.typesafe.config.ConfigFactory
// whatever your package name is and whatever interested actors you want to target
import myapplication.amqp.{RabbitMQConnection, MsgConsumer}
import myapplication.actors.EventFilter
import play.api.Play.current
object Global extends GlobalSettings {
val config = ConfigFactory.load()
val broker_url = config.getString("myapplication.rabbitmq.broker")
val connection = new RabbitMQConnection(broker_url)
val channel = connection.createChannel
override def onStart(app: Application) {
channel.basicQos(1)
Logger.info("Starting the EventFilter.")
// Our primary event_filter
val event_filter = Akka.system.actorOf(
Props[EventFilter].withRouter(SmallestMailboxRouter(nrOfInstances=4)),
name="EventFilter"
)
Logger.debug("Initializing a MsgConsumer for the EventFilter")
channel.basicConsume(
config.getString("myapplication.rabbitmq.nodes.event_filter.consumer_queue"),
false, // do not auto ack
"event_filter", // tagging the consumer is important if you want to stop it later
new MsgConsumer(channel, event_filter)
)
}
override def onStop(app: Application) {
Logger.info("Canceling the EventFilter MsgConsumer.")
channel.basicCancel("event_filter")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment