rabbitmq 操作库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839
  1. package rabbit
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. var Cfg MQCfg
  7. //Mq配置结构体
  8. type MQCfg struct {
  9. Host string `json:"host"`
  10. Port string `json:"port"`
  11. User string `json:"user"`
  12. Pwd string `json:"pwd"`
  13. Uri string `json:"uri"`
  14. Pool *Pool `json:"pool"`
  15. }
  16. func Init(host, port, user, pwd string) error {
  17. Cfg.Host = host
  18. Cfg.Port = port
  19. Cfg.User = user
  20. Cfg.Pwd = pwd
  21. Cfg.Uri = fmt.Sprintf("amqp://%s:%s@%s:%s/", user, pwd, host, port)
  22. var conf = Config{
  23. Host: Cfg.Uri,
  24. MinConn: 10,
  25. MaxConn: 50,
  26. MaxChannelPerConn: 10,
  27. MaxLifetime: time.Duration(3600),
  28. }
  29. pool, err := NewPool(&conf) // 建立连接池
  30. if err != nil {
  31. return err
  32. }
  33. Cfg.Pool = pool
  34. return nil
  35. }