Skip to content

Instantly share code, notes, and snippets.

@jboner
Created September 4, 2009 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jboner/180893 to your computer and use it in GitHub Desktop.
Save jboner/180893 to your computer and use it in GitHub Desktop.
AMQP module for Akka
import se.scalablesolutions.akka.serialization.Serializer
import se.scalablesolutions.akka.actor.Actor
import com.rabbitmq.client.ConnectionParameters
object ExampleSession {
import AMQP._
val SERIALIZER = Serializer.Java
val CONFIG = new ConnectionParameters
val HOSTNAME = "localhost"
val PORT = 5672
val IM = "im.whitehouse.gov"
val CHAT = "chat.whitehouse.gov"
def direct = {
val endpoint = AMQP.newEndpoint(CONFIG, HOSTNAME, PORT, IM, ExchangeType.Direct, SERIALIZER, None, 100)
endpoint ! MessageConsumer("@george_bush", "direct", new Actor() {
def receive: PartialFunction[Any, Unit] = {
case Message(payload, _, _, _, _) => log.info("@george_bush received message from: %s", payload)
}
})
val client = AMQP.newClient(CONFIG, HOSTNAME, PORT, IM, SERIALIZER, None, None, 100)
client ! Message("@jonas_boner: You sucked!!", "direct")
}
def fanout = {
val endpoint = AMQP.newEndpoint(CONFIG, HOSTNAME, PORT, CHAT, ExchangeType.Fanout, SERIALIZER, None, 100)
endpoint ! MessageConsumer("@george_bush", "", new Actor() {
def receive: PartialFunction[Any, Unit] = {
case Message(payload, _, _, _, _) => log.info("@george_bush received message from: %s", payload)
}
})
endpoint ! MessageConsumer("@barack_obama", "", new Actor() {
def receive: PartialFunction[Any, Unit] = {
case Message(payload, _, _, _, _) => log.info("@barack_obama received message from: %s", payload)
}
})
val client = AMQP.newClient(CONFIG, HOSTNAME, PORT, CHAT, SERIALIZER, None, None, 100)
client ! Message("@jonas_boner: I'm going surfing", "")
}
def main(args: Array[String]) = {
println("==== DIRECT ===")
direct
Thread.sleep(1000)
println("==== FANOUT ===")
fanout
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment