Implementing the consumer side of the chapter 2 exercise
This commit is contained in:
parent
4be2593056
commit
420a979b98
@ -0,0 +1,25 @@
|
||||
package com.meatballhat.sylvilagus.ch02
|
||||
|
||||
import com.rabbitmq.client._
|
||||
|
||||
object HelloWorldConsumer extends App {
|
||||
val factory = new ConnectionFactory()
|
||||
factory.setUri("amqp://guest:guest@localhost:5672")
|
||||
val connection = factory.newConnection
|
||||
val channel = connection.createChannel
|
||||
|
||||
channel.exchangeDeclare("hello-exchange", "direct", true)
|
||||
channel.queueDeclare("hello-queue", false, false, false, null)
|
||||
|
||||
var consumer = new QueueingConsumer(channel)
|
||||
channel.basicConsume("hello-queue", true, consumer)
|
||||
|
||||
println("Waiting for messages...")
|
||||
|
||||
while (true) {
|
||||
new String(consumer.nextDelivery.getBody) match {
|
||||
case "quit" => println("Exiting..") ; connection.close ; exit
|
||||
case msg@_ => println("Received '%s'".format(msg))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user