rabbitmq.go 598 B

12345678910111213141516171819202122232425262728
  1. package initialize
  2. import (
  3. "mtp20access/global"
  4. "github.com/streadway/amqp"
  5. "go.uber.org/zap"
  6. )
  7. func RabbitMQ() *global.RabbitMQ {
  8. url := global.M2A_CONFIG.Rabbitmq.Url
  9. connection, err := amqp.Dial(url)
  10. if err != nil {
  11. global.M2A_LOG.Error("rabbitmq connect failed, err:", zap.Error(err))
  12. return nil
  13. }
  14. channel, err := connection.Channel()
  15. if err != nil {
  16. global.M2A_LOG.Error("rabbitmq open channel failed, err:", zap.Error(err))
  17. return nil
  18. }
  19. global.M2A_LOG.Info("rabbitmq connect successed.")
  20. return &global.RabbitMQ{
  21. Connection: connection,
  22. Channel: channel,
  23. }
  24. }