1
0
mirror of https://github.com/ebosas/microservices.git synced 2025-06-06 22:16:11 +02:00

31 lines
679 B
Go
Raw Normal View History

2021-06-08 21:26:14 +03:00
package rabbit
import "github.com/streadway/amqp"
// Conn returns a Rabbit connecton. Also, a channel to be used
// in the main go routine.
type Conn struct {
Connection *amqp.Connection
Channel *amqp.Channel
}
// GetConn established a Rabbit connection.
func GetConn(rabbitURL string) (*Conn, error) {
conn, err := amqp.Dial(rabbitURL)
if err != nil {
return &Conn{}, err
}
ch, err := conn.Channel()
return &Conn{
Connection: conn,
Channel: ch,
}, err
}
// Close closes the Rabbit connection.
// All resources associated with the connection, including channels,
// will also be closed.
func (conn *Conn) Close() error {
return conn.Connection.Close()
}