box-o-sand/sylvilagus/go/src/meatballhat.com/sylvilagus-chapter02-hello-world-consumer/main.go

34 lines
657 B
Go
Raw Normal View History

package main
import (
"log"
)
import (
"github.com/streadway/amqp"
)
func main() {
connection, err := amqp.Dial("amqp://guest:guest@localhost:5672")
if err != nil {
log.Fatal("Failed to connect!: ", err)
}
defer connection.Close()
channel, err := connection.Channel()
if err != nil {
log.Fatal("Failed to get channel!: ", err)
}
err = channel.ExchangeDeclare("hello-exchange", "direct", true, false, false, false, nil)
if err != nil {
log.Fatal("Failed to declare exchange!: ", err)
}
err = channel.QueueBind("hello-queue", "hola", "hello-exchange", false, nil)
if err != nil {
log.Fatal("Failed to bind to queue!: ", err)
}
}