2012-11-15 02:16:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
import (
|
2012-12-01 23:41:06 +00:00
|
|
|
"github.com/meatballhat/box-o-sand/sylvilagus/go/sylvilagus"
|
2012-11-15 02:16:00 +00:00
|
|
|
"github.com/streadway/amqp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2012-11-17 13:10:11 +00:00
|
|
|
connection, err := amqp.Dial(sylvilagus.AMQP_URI)
|
2012-11-15 02:16:00 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Failed to connect!: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer connection.Close()
|
|
|
|
|
2012-11-15 05:05:44 +00:00
|
|
|
channel, err := sylvilagus.CreateHelloTopology(connection)
|
2012-11-15 02:16:00 +00:00
|
|
|
if err != nil {
|
2012-11-15 05:05:44 +00:00
|
|
|
log.Fatal("Failed to build topology!: ", err)
|
2012-11-15 02:16:00 +00:00
|
|
|
}
|
2012-11-15 03:27:46 +00:00
|
|
|
|
|
|
|
hellos, err := channel.Consume("hello-queue", "hello-consumer", false, false, false, false, nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Failed to start consuming!:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
quit := make(chan bool)
|
|
|
|
|
2012-11-15 04:47:08 +00:00
|
|
|
go func(quit chan bool) {
|
|
|
|
log.Println("Consuming...")
|
2012-11-15 03:27:46 +00:00
|
|
|
for hello := range hellos {
|
2012-11-15 04:47:08 +00:00
|
|
|
log.Printf("hello -> %v\n", string(hello.Body))
|
2012-11-15 03:27:46 +00:00
|
|
|
hello.Ack(false)
|
2012-11-15 04:47:08 +00:00
|
|
|
if string(hello.Body) == "quit" {
|
|
|
|
quit <- true
|
|
|
|
return
|
|
|
|
}
|
2012-11-15 03:27:46 +00:00
|
|
|
}
|
2012-11-15 04:47:08 +00:00
|
|
|
}(quit)
|
2012-11-15 03:27:46 +00:00
|
|
|
|
|
|
|
<-quit
|
2012-11-15 02:16:00 +00:00
|
|
|
}
|