mirror of
https://github.com/fhmq/hmq.git
synced 2026-04-26 19:48:34 +00:00
modify cluster logic
This commit is contained in:
@@ -65,21 +65,32 @@ func (b *Broker) Start() {
|
|||||||
log.Error("broker is null")
|
log.Error("broker is null")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//listen clinet over tcp
|
||||||
if b.config.Port != "" {
|
if b.config.Port != "" {
|
||||||
go b.StartClientListening(false)
|
go b.StartClientListening(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//listen for cluster
|
||||||
if b.config.Cluster.Port != "" {
|
if b.config.Cluster.Port != "" {
|
||||||
go b.StartClusterListening()
|
go b.StartClusterListening()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//listen for websocket
|
||||||
if b.config.WsPort != "" {
|
if b.config.WsPort != "" {
|
||||||
go b.StartWebsocketListening()
|
go b.StartWebsocketListening()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//listen client over tls
|
||||||
if b.config.TlsPort != "" {
|
if b.config.TlsPort != "" {
|
||||||
go b.StartClientListening(true)
|
go b.StartClientListening(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//connect on other node in cluster
|
||||||
if len(b.config.Cluster.Routes) > 0 {
|
if len(b.config.Cluster.Routes) > 0 {
|
||||||
b.ConnectToRouters()
|
b.ConnectToRouters()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//system montior
|
||||||
go StateMonitor()
|
go StateMonitor()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -93,7 +104,6 @@ func StateMonitor() {
|
|||||||
if v.UsedPercent > 75 {
|
if v.UsedPercent > 75 {
|
||||||
debug.FreeOSMemory()
|
debug.FreeOSMemory()
|
||||||
}
|
}
|
||||||
// fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -486,6 +486,11 @@ func (c *client) Close() {
|
|||||||
if c.info.willMsg != nil {
|
if c.info.willMsg != nil {
|
||||||
b.PublishMessage(c.info.willMsg)
|
b.PublishMessage(c.info.willMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//do reconnect
|
||||||
|
if c.typ == REMOTE {
|
||||||
|
b.connectRouter(c.route.remoteUrl, "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CONFIGFILE = "hmq.config"
|
CONFIGFILE = "conf/hmq.config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ func (c *client) StartPing() {
|
|||||||
err := c.WriterPacket(ping)
|
err := c.WriterPacket(ping)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("ping error: ", err)
|
log.Error("ping error: ", err)
|
||||||
|
c.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user