Created
March 4, 2011 13:14
-
-
Save stephanos/854596 to your computer and use it in GitHub Desktop.
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 akka.amqp.AMQP._ | |
import akka.amqp._ | |
import akka.actor._ | |
import akka.dispatch._ | |
import akka.util.Logging | |
object AMQPTest extends Logging { | |
val connection = AMQP.newConnection() | |
val exchangeParameters = ExchangeParameters("my_direct_exchange", Direct) | |
class JobConsumer extends Actor { | |
def receive = { | |
case Delivery(payload, _, _, _, _, _) => | |
println("Received message: " + new String(payload)) | |
Thread.sleep(5000) | |
} | |
} | |
def newDispatcher(name: String, poolSize: Int) = | |
Dispatchers.newExecutorBasedEventDrivenWorkStealingDispatcher(name) | |
.withNewThreadPoolWithLinkedBlockingQueueWithUnboundedCapacity | |
.setCorePoolSize(poolSize) | |
.setMaxPoolSize(poolSize) | |
.build | |
def main(args: Array[String]) { | |
// == Consumer | |
val actor = Actor.actorOf(classOf[JobConsumer]) | |
actor.dispatcher = newDispatcher("my-dispatcher", 3) | |
AMQP.newConsumer(connection, ConsumerParameters("some.routing.key", | |
actor, None, Some(exchangeParameters))) | |
// == Producer | |
val producer = AMQP.newProducer(connection, | |
ProducerParameters(Some(exchangeParameters), Some("my-producer"))) | |
producer ! Message("data".getBytes, "some.routing.key") | |
producer ! Message("data".getBytes, "some.routing.key") | |
producer ! Message("data".getBytes, "some.routing.key") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment