hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
847 stars 158 forks source link

FR: File persistence of pending to be published messages #524

Open KeithLaiKB opened 2 years ago

KeithLaiKB commented 2 years ago

case

step1: publisher send 1,2,3,4,5 (total 5 messages) subscriber received 1,2,3,4,5 (total 5 messages)

step2: and then I close the program of the broker and wait for a while.

step3: then publisher keep going to send 6,7,8 (total 3 messages)

step4: shutdown the publisher program

step5: restart the broker, and subscriber auto reconnect to the broker

step6: restart the publisher and send 13, 14, 15 (total 3 messages)

howerver, subscriber couldn't receive the 6,7,8 (total 3 messages) in step3

Is there a MqttDefaultFilePersistence feature? it seems like it is just in-memory persistent.

cxshun commented 2 years ago

I think this is not a problem. mqtt only have retained message that store only the last message that publish to a topic that no one subscribe, this is the protocol that it designed to be. You can refer to this article

So on your step 3, you publish to a topic that currently no none subscribe(if you mean to), so message will be discard directly(only if you set the message to retained, but only last one)

PS:On your step2, you mean close publisher or broker?

KeithLaiKB commented 2 years ago

I think this is not a problem. mqtt only have retained message that store only the last message that publish to a topic that no one subscribe, this is the protocol that it designed to be. You can refer to this article

So on your step 3, you publish to a topic that currently no none subscribe(if you mean to), so message will be discard directly(only if you set the message to retained, but only last one)

PS:On your step2, you mean close publisher or broker?

yes in step2, just close the broker, and wait for a while. well, as for paho_mqtt case:

It provides you with MqttDefaultFilePersistence or MemoryPersistence.

When you choose to use MqttDefaultFilePersistence. in step3 because now the broker is off, 6,7,8 (total 3 messages)could not send to the broker, but the publisher could save the 6,7,8 (total 3 messages) in a file, when the broker restart, and restart the publisher, it could also send the 6,7,8 (total 3 messages) from the file to the broker.

I think this feature is really useful and provides the program with steady.

As for retained message, it seems that it just could send the new message 8 in 6,7,8 (total 3 messages), it could not meet the need of this requirement.

pglombardo commented 1 year ago

Hi all - I've marked this issue as a feature request for file persistence. Thanks for pointing this out!