box-o-sand/oldstuff/sylvilagus/go/sylvilagus/rpc.go

40 lines
903 B
Go
Raw Normal View History

package sylvilagus
import (
"log"
2012-12-02 13:41:05 +00:00
"time"
)
import (
"github.com/streadway/amqp"
)
2012-12-02 13:41:05 +00:00
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
}