diff --git a/broker/broker.go b/broker/broker.go index 0571ade..47fb221 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -65,21 +65,32 @@ func (b *Broker) Start() { log.Error("broker is null") return } + //listen clinet over tcp if b.config.Port != "" { go b.StartClientListening(false) } + + //listen for cluster if b.config.Cluster.Port != "" { go b.StartClusterListening() } + + //listen for websocket if b.config.WsPort != "" { go b.StartWebsocketListening() } + + //listen client over tls if b.config.TlsPort != "" { go b.StartClientListening(true) } + + //connect on other node in cluster if len(b.config.Cluster.Routes) > 0 { b.ConnectToRouters() } + + //system montior go StateMonitor() } @@ -93,7 +104,6 @@ func StateMonitor() { if v.UsedPercent > 75 { debug.FreeOSMemory() } - // fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent) } } } diff --git a/broker/client.go b/broker/client.go index 532f604..4615005 100644 --- a/broker/client.go +++ b/broker/client.go @@ -486,6 +486,11 @@ func (c *client) Close() { if c.info.willMsg != nil { b.PublishMessage(c.info.willMsg) } + + //do reconnect + if c.typ == REMOTE { + b.connectRouter(c.route.remoteUrl, "") + } } } diff --git a/broker/config.go b/broker/config.go index 31878f3..08c7245 100644 --- a/broker/config.go +++ b/broker/config.go @@ -11,7 +11,7 @@ import ( ) const ( - CONFIGFILE = "hmq.config" + CONFIGFILE = "conf/hmq.config" ) type Config struct { diff --git a/broker/info.go b/broker/info.go index f59c274..275bb94 100644 --- a/broker/info.go +++ b/broker/info.go @@ -34,6 +34,7 @@ func (c *client) StartPing() { err := c.WriterPacket(ping) if err != nil { log.Error("ping error: ", err) + c.Close() } } } diff --git a/hmq.config b/conf/hmq.config similarity index 100% rename from hmq.config rename to conf/hmq.config