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)) + } +}