Open Nukta101 opened 3 months ago
I prefer to expose the packet identifier in the MqttApplicationMessage. If it is left 0 a new one will be created using the identifier provider. Additionally, I will add a new parameter to the client options which allows to setup the offset of the identifier values when connecting with the server. The client will also get a new property which exposes (read only) the latest used packet identifier so that you can store it after disconnecting and reuse it when connecting. What do you think?
Yes, that covers the use case. Thank you!
Describe the feature request
The scenario is to store the messages with packet identifier for QoS>0 on the filesystem before publishing them to the MQTT Broker. Storing the messages on the filesystem helps to survive the system/mqtt client crashes.
Currently the MQTTNet does not expose any method to set the PacketIdentifier directly in the MqttApplicationMessage and the PacketIdentifier is only available in the response of PublishAsync method.
In the reconnection scenario, Due to the Reset() method from MqttPacketIdentifierProvider being called in the ConnectAsync() the packet identifier is reset to 1, if there are messages already stored in the filesystem from the last connection that will then cause the packet id conflict.
Which project is your feature request related to?
Describe the solution you'd like
Following are possible solutions.
Another approach for the point 1 would be to make it possible to directly assign the packet identifier in the MqttApplicationMessage and create the interface for MqttPacketIdentifierProvider so user can provide custom packet identifier provider.