diff --git a/broker/broker.go b/broker/broker.go index 8effdd2..7e0125d 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -131,14 +131,13 @@ func (b *Broker) Start() { return } - go b.initRPCService() - go InitHTTPMoniter(b) //connet to router if b.config.Router != "" { go b.ConnectToDiscovery() go b.processClusterInfo() + go b.initRPCService() } //listen for websocket diff --git a/broker/config.go b/broker/config.go index af7255b..5edf164 100644 --- a/broker/config.go +++ b/broker/config.go @@ -20,6 +20,7 @@ type Config struct { Worker int `json:"workerNum"` Host string `json:"host"` Port string `json:"port"` + RpcPort string `json:"rpc"` Router string `json:"router"` TlsHost string `json:"tlsHost"` TlsPort string `json:"tlsPort"` @@ -72,6 +73,7 @@ func ConfigureConfig(args []string) (*Config, error) { fs.StringVar(&config.Port, "port", "1883", "Port to listen on.") fs.StringVar(&config.Port, "p", "1883", "Port to listen on.") fs.StringVar(&config.Host, "host", "0.0.0.0", "Network host to listen on") + fs.StringVar(&config.RpcPort, "rpc", "10011", "Port to listen on.") fs.StringVar(&config.Router, "r", "", "Router who maintenance cluster info") fs.StringVar(&config.Router, "router", "", "Router who maintenance cluster info") fs.StringVar(&config.WsPort, "ws", "", "port for ws to listen on") diff --git a/broker/info.go b/broker/info.go index 0c8f541..e5ac8fb 100644 --- a/broker/info.go +++ b/broker/info.go @@ -15,7 +15,7 @@ func (c *client) SendInfo() { if c.status == Disconnected { return } - url := c.info.localIP + ":10011" + url := c.info.localIP + ":" + c.broker.config.RpcPort infoMsg := NewInfo(c.broker.id, url, false) err := c.WriterPacket(infoMsg) diff --git a/broker/rpc.go b/broker/rpc.go index 9f86381..53af51d 100644 --- a/broker/rpc.go +++ b/broker/rpc.go @@ -14,7 +14,7 @@ import ( ) func (b *Broker) initRPCService() { - lis, err := net.Listen("tcp", ":10011") + lis, err := net.Listen("tcp", ":"+b.config.RpcPort) if err != nil { log.Error("failed to listen: ", zap.Error(err)) return diff --git a/broker/usage.go b/broker/usage.go index b1c7755..f0f3e37 100644 --- a/broker/usage.go +++ b/broker/usage.go @@ -17,7 +17,7 @@ Logging Options: Cluster Options: -r, --router Router who maintenance cluster info - -cp, --clusterport Cluster listen port for others + -rpc, Cluster listen port for others Common Options: -h, --help Show this message diff --git a/conf/hmq.config b/conf/hmq.config index a0badec..403b44e 100644 --- a/conf/hmq.config +++ b/conf/hmq.config @@ -3,6 +3,7 @@ "port": "1883", "host": "0.0.0.0", "debug": true, + "rpc": "10011", "router": "127.0.0.1:9888", "tlsPort": "8883", "tlsHost": "0.0.0.0",