package initialize import ( "mtp20access/global" "github.com/streadway/amqp" "go.uber.org/zap" ) func RabbitMQ() *global.RabbitMQ { url := global.M2A_CONFIG.Rabbitmq.Url connection, err := amqp.Dial(url) if err != nil { global.M2A_LOG.Error("rabbitmq connect failed, err:", zap.Error(err)) return nil } channel, err := connection.Channel() if err != nil { global.M2A_LOG.Error("rabbitmq open channel failed, err:", zap.Error(err)) return nil } global.M2A_LOG.Info("rabbitmq connect successed.") return &global.RabbitMQ{ Connection: connection, Channel: channel, } }