Example #1
0
func (self *DummyPlug) WriteMessageQueue(request mqtt.Message) {
	switch request.GetType() {
	case mqtt.PACKET_TYPE_CONNECT:
	case mqtt.PACKET_TYPE_CONNACK:
	case mqtt.PACKET_TYPE_PUBLISH:
		self.message <- request
	case mqtt.PACKET_TYPE_DISCONNECT:
		self.message <- request
	case mqtt.PACKET_TYPE_SUBSCRIBE:
	case mqtt.PACKET_TYPE_SUBACK:
	case mqtt.PACKET_TYPE_UNSUBSCRIBE:
	case mqtt.PACKET_TYPE_UNSUBACK:
	case mqtt.PACKET_TYPE_PINGRESP:
	case mqtt.PACKET_TYPE_PINGREQ:
	case mqtt.PACKET_TYPE_PUBACK:
		self.message <- request
	case mqtt.PACKET_TYPE_PUBREC:
		self.message <- request
	case mqtt.PACKET_TYPE_PUBREL:
		self.message <- request
	case mqtt.PACKET_TYPE_PUBCOMP:
		self.message <- request
	default:
		return
	}
}
Example #2
0
// Without lock
func (self *MmuxConnection) writeMessageQueue(request mqtt.Message) {
	// TODO: これそもそもmuxがあったらもうdummyか普通のか、ぐらいなような気が
	_, is_dummy := (*self.Connection).(*DummyPlug)
	if self.Connection == nil {
		// already disconnected
		return
	} else if is_dummy {
		if request.GetType() == mqtt.PACKET_TYPE_PUBLISH {
			self.OfflineQueue = append(self.OfflineQueue, request)
		}
	}

	(*self.Connection).WriteMessageQueue(request)
}
Example #3
0
func (self *MyConnection) writeMessage(msg codec.Message) error {
	self.logger.Debug("Write Message [%s]: %+v", msg.GetTypeAsString(), msg)
	var e error
	self.Mutex.Lock()

	self.Last = time.Now()
	if self.balancer != nil && self.balancer.PerSec > 0 {
		self.balancer.Execute(func() {
			_, e = codec.WriteMessageTo(msg, self.Writer)
		})
	} else {
		_, e = codec.WriteMessageTo(msg, self.Writer)
	}

	if e != nil {
		self.Mutex.Unlock()
		return e
	}

	self.Last = time.Now()
	self.kickFlusher()
	self.Mutex.Unlock()
	return nil
}