rabbitmq/rabbitmq.go

39 lines
597 B
Go
Raw Permalink Normal View History

2021-08-09 03:45:44 +00:00
package rabbitmq
import (
"fmt"
"github.com/logrusorgru/aurora"
"github.com/streadway/amqp"
)
var (
connection *amqp.Connection
channel *amqp.Channel
)
// Connect ...
func Connect(uri string) error {
conn, err := amqp.Dial(uri)
if err != nil {
fmt.Println(aurora.Red("*** Connect to RabbitMQ failed: " + uri))
return err
}
fmt.Println(aurora.Green("*** CONNECTED TO RABBITMQ: " + uri))
// Set connection
connection = conn
// Set channel
channel, _ = connection.Channel()
return nil
}
// GetConnection ...
func GetConnection() *amqp.Connection {
return connection
}