emitter icon indicating copy to clipboard operation
emitter copied to clipboard

QoS support

Open zhaitianduo opened this issue 2 years ago • 2 comments

Hey great repo!

May I ask how is the MQTT Qos implemented in this repo. Does it support both Qos 1 and 2?

zhaitianduo avatar Dec 20 '22 06:12 zhaitianduo

It seems only support QoS 0.

// Send forwards the message to the underlying client.
func (c *Conn) Send(m *message.Message) (err error) {
	defer c.MeasureElapsed("send.pub", time.Now())
	packet := mqtt.Publish{
		Header:  mqtt.Header{QOS: 0},
		Topic:   m.Channel, // The channel for this message.
		Payload: m.Payload, // The payload for this message.
	}

	_, err = packet.EncodeTo(c.socket)
	return
}

qiulin avatar Nov 04 '23 03:11 qiulin

@kelindar - Maybe any plans on supporting QoS level 1 and/or 2? If not, what is the recommendation in order to get the Exactly Once message guarantee-like behavior? Thanks!

mkozjak avatar Feb 21 '24 10:02 mkozjak

Actually, Emitter supports QoS 1. But maybe not in the way you are expecting. The code that acknowledges the publication of a message is in conn.go

// Acknowledge the publication
if packet.Header.QOS > 0 {
	ack := mqtt.Puback{MessageID: packet.MessageID}
	if _, err := ack.EncodeTo(c.socket); err != nil {
		return err
	}
}

However, what is acknowledged is that the message has been integrated into Emitter. Not that it arrived to any client. There could be no client listening at this moment and for a long time, if ever. Although there are certainly more or less elegant ways to handle such cases in a pub/sub system, it didn't seem important for an AP platform like Emitter. The same goes for QoS 2, and it's actually even harder to enforce.

Emitter focusing on AP, I like to compare it to the UDP of pub/sub systems. If you want stronger guarantees you'll have to implement a protocol on top of Emitter.

In the current state of Emitter, I must admit I don't see how your client could receive the same message twice. But if you want to make sure, you can handle this quite easily on the client side by using a tombstone.

@qiulin @mkozjak @kelindar

Florimond avatar Mar 02 '24 22:03 Florimond