| | |
| | | "context" |
| | | "errors" |
| | | "fmt" |
| | | "github.com/shirou/gopsutil/net" |
| | | "sync" |
| | | "sync/atomic" |
| | | ) |
| | |
| | | }) |
| | | } |
| | | |
| | | func (c *consumerManager) ping() bool { |
| | | connections, err := net.Connections("inet") |
| | | if err != nil { |
| | | fmt.Println("Error:", err) |
| | | return false |
| | | } |
| | | for _, conn := range connections { |
| | | fmt.Println("net.Connections:", conn) |
| | | ipPort := fmt.Sprintf("%s:%s", conn.Laddr.IP, conn.Laddr.Port) |
| | | fmt.Println("net.Connections ipPort", ipPort) |
| | | if ipPort == conf.Conf.NsqConf.NsqdAddr && conn.Status == "ESTABLISHED" { |
| | | return true |
| | | } |
| | | } |
| | | return false |
| | | } |
| | | |
| | | func Init() error { |
| | | return defaultConsumerManager.init() |
| | | } |
| | | |
| | | func Ping() bool { |
| | | return defaultConsumerManager.ping() |
| | | } |
| | | |
| | | func Stop() { |
| | | defaultConsumerManager.stop() |
| | | StopProducer() |