MessageExpiryInterval MQTT v5 support
Hello,
I am currently using Paho MQTT in order to test some real time applications where data should (almost) not be stored within the broker (or at least no more than a few seconds).
I have seen on MQTT's documentation that v5 could help me doing this through the usage of Message Expiry Interval.
I tried a few things based on the examples available in the tests section for Session Expiry Interval and Publish Properties. but did not manage to get the expected bahaviour.
For example the below code does not seem to work:
publish_properties = Properties(PacketTypes.PUBLISH)
publish_properties.MessageExpiryInterval = 1
client = mqtt.Client(protocol=mqtt.MQTTv5)
client.connect(IP, PORT, properties=publish_properties)
client.publish(
topic,
payload,
retain=False,
properties=publish_properties,
)
Is the MessageExpiryInterval feature implemented within Paho?
Thanks!
Running into a similar problem trying to replicate the V311 clean session behavior. Using the Properties.writeProperty() function didn't get me anywhere.
I can also report that this doesn't work:
properties = Properties(PacketTypes.CONNECT)
properties.UserProperty = ('Message Expiry Interval', 30)
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 1088, in reconnect
return self._send_connect(self._keepalive)
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 2752, in _send_connect
packed_connect_properties = self._connect_properties.pack()
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/properties.py", line 376, in pack
buffer += self.writeProperty(identifier,
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/properties.py", line 363, in writeProperty
buffer += writeUTF(value[0]) + writeUTF(value[1])
File "/usr/local/lib/python3.9/site-packages/paho/mqtt/properties.py", line 58, in writeUTF
data = data if type(data) == type(b"") else bytes(data, "utf-8")
TypeError: encoding without a string argument
for me it works as expected. Maybe because you forgot to set the retain flag?
properties=Properties(PacketTypes.PUBLISH)
properties.MessageExpiryInterval=5 # retain messages for x seconds
ret = self.__mqtt_client.publish(restricted_data, payload, retain=1, qos=0, properties=properties)
I'm going to close this based on the comment from @call-me-matt above (note that Message Expiry Interval only applies to PUBLISH and Will Properties). If users are still having issues then please feel free to reopen this issue.
Note: This is part of an exercise to clean up old issues so that the project can move forwards. Due to the number of issues being worked through mistakes will be made; please feel free to reopen this issue (or comment) if you believe it's been closed in error.