Beispiel #1
0
func (c *client) pushOfflineMsg(msg *define.Msg) (err error) {
	// The max cache size is 20
	if msg == nil && c.isOfflineClose {
		// Send
		err = c.queue.Flush()
	} else {
		// Wait
		if c.offlineNum > 20 || c.isOfflineClose {
			// Send
			pack := mqtt.GetPubPack(1, msg.Dup, msg.Msg_id, &msg.Topic, msg.Body)
			err = c.queue.WritePack(pack)
			// Clean the cache
			c.offlineNum = 0
		} else {
			c.offlineNum++
			pack := mqtt.GetPubPack(1, msg.Dup, msg.Msg_id, &msg.Topic, msg.Body)
			err = c.queue.WriteDelayPack(pack)
		}
	}
	return
}
Beispiel #2
0
func (c *client) pushMsg(msg *define.Msg) error {
	pack := mqtt.GetPubPack(1, msg.Dup, msg.Msg_id, &msg.Topic, msg.Body)
	// Write this pack
	err := c.queue.WritePack(pack)
	return err
}