-
-
Save tjweir/864882 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.util.Logging | |
| object LoadBalancingTest extends Logging { | |
| val connection = AMQP.newConnection() | |
| val exchangeParameters = ExchangeParameters("my_direct_exchange", Direct) | |
| class JobConsumer(id: Int) extends Actor { | |
| def receive = { | |
| case Delivery(payload, _, _, _, _, _) => | |
| println("(" + id + ") received message: " + new String(payload)) | |
| } | |
| } | |
| def main(args: Array[String]) { | |
| // == Consumer | |
| val channelParameters = Some(ChannelParameters(prefetchSize = 1)) | |
| for (i <- 1 to 3) { | |
| val actor = Actor.actorOf(new JobConsumer(i)) | |
| AMQP.newConsumer(connection, ConsumerParameters("some.routing.key", | |
| actor, Some("my-job-queue"), Some(exchangeParameters), channelParameters = channelParameters)) | |
| } | |
| // == Producer | |
| val producer = AMQP.newProducer(connection, | |
| ProducerParameters(Some(exchangeParameters), Some("my-producer"))) | |
| for (i <- 1 to 30) { | |
| producer ! Message(("data (" + i + ")").getBytes, "some.routing.key") | |
| Thread.sleep(200) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment