modify_message_pool

This commit is contained in:
zhouyuyan
2018-02-24 13:19:43 +08:00
parent 47500910e1
commit c0fea6a5ba
8 changed files with 134 additions and 126 deletions

View File

@@ -4,12 +4,10 @@ package broker
import (
"fmt"
"time"
simplejson "github.com/bitly/go-simplejson"
"github.com/eclipse/paho.mqtt.golang/packets"
"go.uber.org/zap"
simplejson "github.com/bitly/go-simplejson"
"time"
)
func (c *client) SendInfo() {
@@ -21,7 +19,7 @@ func (c *client) SendInfo() {
infoMsg := NewInfo(c.broker.id, url, false)
err := c.WriterPacket(infoMsg)
if err != nil {
brokerLog.Error("send info message error, ", zap.Error(err))
log.Error("send info message error, ", zap.Error(err))
return
}
}
@@ -34,7 +32,7 @@ func (c *client) StartPing() {
case <-timeTicker.C:
err := c.WriterPacket(ping)
if err != nil {
brokerLog.Error("ping error: ", zap.Error(err))
log.Error("ping error: ", zap.Error(err))
c.Close()
}
case _, ok := <-c.closed:
@@ -57,10 +55,10 @@ func (c *client) SendConnect() {
m.Keepalive = uint16(60)
err := c.WriterPacket(m)
if err != nil {
brokerLog.Error("send connect message error, ", zap.Error(err))
log.Error("send connect message error, ", zap.Error(err))
return
}
brokerLog.Info("send connect success")
log.Info("send connect success")
}
func NewInfo(sid, url string, isforword bool) *packets.PublishPacket {
@@ -69,7 +67,7 @@ func NewInfo(sid, url string, isforword bool) *packets.PublishPacket {
pub.TopicName = BrokerInfoTopic
pub.Retain = false
info := fmt.Sprintf(`{"brokerID":"%s","brokerUrl":"%s"}`, sid, url)
// brokerLog.Info("new info", string(info))
// log.Info("new info", string(info))
pub.Payload = []byte(info)
return pub
}
@@ -81,17 +79,17 @@ func (c *client) ProcessInfo(packet *packets.PublishPacket) {
return
}
brokerLog.Info("recv remoteInfo: ", zap.String("payload", string(packet.Payload)))
log.Info("recv remoteInfo: ", zap.String("payload", string(packet.Payload)))
js, err := simplejson.NewJson(packet.Payload)
if err != nil {
brokerLog.Warn("parse info message err", zap.Error(err))
log.Warn("parse info message err", zap.Error(err))
return
}
routes, err := js.Get("data").Map()
if routes == nil {
brokerLog.Error("receive info message error, ", zap.Error(err))
log.Error("receive info message error, ", zap.Error(err))
return
}