go-api-pkg/rabbitmq/connect.go

27 lines
428 B
Go

package rabbitmq
import (
"log"
amqp "github.com/rabbitmq/amqp091-go"
)
func Open(url string) (*amqp.Connection, *amqp.Channel, error) {
conn, err := amqp.Dial(url)
if err != nil {
return nil, nil, err
}
ch, err := conn.Channel()
if err != nil {
log.Printf("Failed to open a channel: %v\n", err)
return nil, nil, err
}
return conn, ch, nil
}
func Close(conn *amqp.Connection) error {
return conn.Close()
}