47 lines
971 B
Go
47 lines
971 B
Go
package sylvilagus
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
import (
|
|
"github.com/streadway/amqp"
|
|
)
|
|
|
|
var AMQP_URI = os.Getenv("SYLVILAGUS_AMQP_URI")
|
|
|
|
func init() {
|
|
if len(AMQP_URI) < 1 {
|
|
log.Fatal("SYLVILAGUS_AMQP_URI is not defined!")
|
|
}
|
|
}
|
|
|
|
func CreateHelloTopology(connection *amqp.Connection) (*amqp.Channel, error) {
|
|
channel, err := connection.Channel()
|
|
if err != nil {
|
|
log.Println("Failed to get channel!: ", err)
|
|
return nil, err
|
|
}
|
|
|
|
err = channel.ExchangeDeclare("hello-exchange", "direct", true, false, false, false, nil)
|
|
if err != nil {
|
|
log.Println("Failed to declare exchange!: ", err)
|
|
return nil, err
|
|
}
|
|
|
|
_, err = channel.QueueDeclare("hello-queue", false, false, false, false, nil)
|
|
if err != nil {
|
|
log.Println("Failed to declare queue!: ", err)
|
|
return nil, err
|
|
}
|
|
|
|
err = channel.QueueBind("hello-queue", "hola", "hello-exchange", false, nil)
|
|
if err != nil {
|
|
log.Println("Failed to bind to queue!: ", err)
|
|
return nil, err
|
|
}
|
|
|
|
return channel, nil
|
|
}
|