Created
September 4, 2009 13:57
-
-
Save jboner/180893 to your computer and use it in GitHub Desktop.
AMQP module for Akka
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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