func (self *KiteQServer) Start() { self.remotingServer = server.NewRemotionServer(self.kc.server, self.kc.rc, func(rclient *client.RemotingClient, p *packet.Packet) { event := pipe.NewPacketEvent(rclient, p) err := self.pipeline.FireWork(event) if nil != err { log.ErrorLog("kite_server", "RemotingServer|onPacketRecieve|FAIL|%s|%t", err, packet.MarshalPacket(p)) } else { // log.Debug("RemotingServer|onPacketRecieve|SUCC|%s|%t\n", rclient.RemoteAddr(), packet) } }) err := self.remotingServer.ListenAndServer() if nil != err { log.Crashf("KiteQServer|RemotionServer|START|FAIL|%s|%s\n", err, self.kc.server) } else { log.InfoLog("kite_server", "KiteQServer|RemotionServer|START|SUCC|%s\n", self.kc.server) } //推送可发送的topic列表并且获取了对应topic下的订阅关系 succ := self.exchanger.PushQServer(self.kc.server, self.kc.topics) if !succ { log.Crashf("KiteQServer|PushQServer|FAIL|%s|%s\n", err, self.kc.topics) } else { log.InfoLog("kite_server", "KiteQServer|PushQServer|SUCC|%s\n", self.kc.topics) } //开启流量统计 self.startFlow() //开启recover self.recoverManager.Start() }
func (self *KiteQServer) Start() { self.remotingServer = server.NewRemotionServer(self.kc.so.bindHost, self.kc.rc, func(rclient *client.RemotingClient, p *packet.Packet) { event := pipe.NewPacketEvent(rclient, p) err := self.pipeline.FireWork(event) if nil != err { log.ErrorLog("kite_server", "RemotingServer|onPacketRecieve|FAIL|%s|%t", err, packet.MarshalPacket(p)) } else { // log.Debug("RemotingServer|onPacketRecieve|SUCC|%s|%t\n", rclient.RemoteAddr(), packet) } }) err := self.remotingServer.ListenAndServer() if nil != err { log.Crashf("KiteQServer|RemotionServer|START|FAIL|%s|%s\n", err, self.kc.so.bindHost) } else { log.InfoLog("kite_server", "KiteQServer|RemotionServer|START|SUCC|%s\n", self.kc.so.bindHost) } //推送可发送的topic列表并且获取了对应topic下的订阅关系 succ := self.exchanger.PushQServer(self.kc.so.bindHost, self.kc.so.topics) if !succ { log.Crashf("KiteQServer|PushQServer|FAIL|%s|%s\n", err, self.kc.so.topics) } else { log.InfoLog("kite_server", "KiteQServer|PushQServer|SUCC|%s\n", self.kc.so.topics) } //开启流量统计 self.startFlow() //开启recover self.recoverManager.Start() //启动DLQ的时间 self.startDLQ() //检查配置更新 if len(self.kc.so.configPath) > 0 { self.startCheckConf() } //启动pprof host, _, _ := net.SplitHostPort(self.kc.so.bindHost) go func() { if self.kc.so.pprofPort > 0 { http.HandleFunc("/stat", self.HandleStat) http.HandleFunc("/binds", self.HandleBindings) log.Error(http.ListenAndServe(host+":"+strconv.Itoa(self.kc.so.pprofPort), nil)) } }() }
//真正写入网络的流 func (self *Session) write0(tlv *packet.Packet) { p := packet.MarshalPacket(tlv) if nil == p || len(p) <= 0 { log.Error("Session|write0|MarshalPacket|FAIL|EMPTY PACKET|%s", tlv) //如果是同步写出 return } l := 0 tmp := p for { length, err := self.bw.Write(tmp) if nil != err { log.Error("Session|write0|conn|%s|FAIL|%s|%d/%d", self.remoteAddr, err, length, len(tmp)) //链接是关闭的 if err != io.ErrShortWrite { self.Close() return } //如果没有写够则再写一次 if err == io.ErrShortWrite { self.bw.Reset(self.conn) } } l += length //write finish if l == len(p) { break } tmp = p[l:] } // //flush self.bw.Flush() if nil != self.rc.FlowStat { self.rc.FlowStat.WriteFlow.Incr(1) self.rc.FlowStat.WriteBytesFlow.Incr(int32(len(p))) } }