|
123456789101112131415161718192021222324252627282930313233343536373839 |
- package rabbit
-
- import (
- "fmt"
- "time"
- )
-
- var Cfg MQCfg
-
- //Mq配置结构体
- type MQCfg struct {
- Host string `json:"host"`
- Port string `json:"port"`
- User string `json:"user"`
- Pwd string `json:"pwd"`
- Uri string `json:"uri"`
- Pool *Pool `json:"pool"`
- }
-
- func Init(host, port, user, pwd string) error {
- Cfg.Host = host
- Cfg.Port = port
- Cfg.User = user
- Cfg.Pwd = pwd
- Cfg.Uri = fmt.Sprintf("amqp://%s:%s@%s:%s/", user, pwd, host, port)
- var conf = Config{
- Host: Cfg.Uri,
- MinConn: 10,
- MaxConn: 50,
- MaxChannelPerConn: 10,
- MaxLifetime: time.Duration(3600),
- }
- pool, err := NewPool(&conf) // 建立连接池
- if err != nil {
- return err
- }
- Cfg.Pool = pool
- return nil
- }
|