Skip to content

Instantly share code, notes, and snippets.

@peterbourgon
Created May 28, 2012 10:10
Show Gist options
  • Save peterbourgon/ac3e5ffe0f279668a005 to your computer and use it in GitHub Desktop.
Save peterbourgon/ac3e5ffe0f279668a005 to your computer and use it in GitHub Desktop.
conn, err := net.Dial("tcp", rabbitEndpoint)
if err != nil {
return nil, fmt.Errorf("Dial: %s", err)
}
connection, err := amqp.NewConnection(
conn,
&amqp.PlainAuth{
Username: user,
Password: pass,
},
"/",
)
if err != nil {
return nil, fmt.Errorf("Connection: %s", err)
}
Debugf("%s-%s: got Connection, getting Channel", w.Action, w.Kind)
channel, err := connection.Channel()
if err != nil {
return nil, fmt.Errorf("Channel: %s", err)
}
Debugf("%s-%s: got Channel, declaring Exchange", w.Action, w.Kind)
noArgs := amqp.Table{}
exchange := channel.E(w.ExchangeName)
if err := exchange.Declare(
amqp.UntilUnused, // lifetime = auto-delete
"direct", // type
false, // internal
false, // noWait
noArgs, // arguments
); err != nil {
closeChannel(w.Channel)
return nil, fmt.Errorf("Exchange Declare: %s", err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment