From 217fe20307a5b22fdc89fd8fc6ee84b1ecc178ff Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Thu, 15 Nov 2012 07:44:27 -0500 Subject: [PATCH] Kinda starting to implement the hello world producer --- .../sylvilagus/ch02/Producer.scala | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/sylvilagus/scala/src/main/scala/com/meatballhat/sylvilagus/ch02/Producer.scala b/sylvilagus/scala/src/main/scala/com/meatballhat/sylvilagus/ch02/Producer.scala index ab13e5d..d91adcf 100644 --- a/sylvilagus/scala/src/main/scala/com/meatballhat/sylvilagus/ch02/Producer.scala +++ b/sylvilagus/scala/src/main/scala/com/meatballhat/sylvilagus/ch02/Producer.scala @@ -1,5 +1,21 @@ -object Producer extends App { - println("OH HAI") -} +import com.rabbitmq.client._ -// vim: set ts=2 sw=2 et: +object Producer extends App { + if (args.length < 1) { + println("You must provide a message argument") + } else { + var messageBody = args(0) + + var factory = new ConnectionFactory() + factory.setUri("amqp://guest:guest@localhost:5672") + var connection = factory.newConnection() + var channel = connection.createChannel() + + channel.exchangeDeclare("hello-exchange", "direct", true) + channel.queueDeclare("hello-queue", true, false, false, null) + + println("Publishing ", messageBody) + channel.basicPublish("hello-exchange", "hola", null, + messageBody.toCharArray().map(_.toByte)) + } +}