box-o-sand/oldstuff/sylvilagus/go/sylvilagus/rpc.go
2015-06-22 13:15:42 -05:00

40 lines
903 B
Go

package sylvilagus
import (
"log"
"time"
)
import (
"github.com/streadway/amqp"
)
type Ping struct {
ClientName string `json:"client_name"`
Time time.Time `json:"time"`
}
func CreateRPCTopology(connection *amqp.Connection) (channel *amqp.Channel, err error) {
if channel, err = connection.Channel(); err != nil {
log.Println("Failed to get channel!: ", err)
return nil, err
}
if err = channel.ExchangeDeclare("rpc", "direct", true, false, false, false, nil); err != nil {
log.Println("Failed to declare exchange!: ", err)
return nil, err
}
if _, err = channel.QueueDeclare("ping", false, false, false, false, nil); err != nil {
log.Println("Failed to declare queue!: ", err)
return nil, err
}
if err = channel.QueueBind("ping", "ping", "rpc", false, nil); err != nil {
log.Println("Failed to bind to queue!: ", err)
return nil, err
}
return channel, nil
}