eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.17k stars 723 forks source link

What is best practices for how to use MQTT with real-time data in python? #670

Closed pavlo-yashchuk closed 2 years ago

pavlo-yashchuk commented 2 years ago

Hi all My cameras detect a lot of objects and generate a lot of data For sending a lot of data I see two ways

  1. Serialize different python objects to JSON format and deserialize them on another side.
  2. Pickles python objects to byte array and unpickles them on another side. Which point is better or maybe you know a faster and better way?
fpagliughi commented 2 years ago

That depends on whether you think the applications on the receiving end will always be written in Python. If not - if you think you might ever want to use a different language in your system - then you should avoid pickling the data which is mainly a Python thing.

JSON is language neutral and can be read and processed by an application in any language. It's also very "readable", which might help with diagnostics as you can intercept messages and examine them very easily.

But even if JSON is not the best choice and you want something that serializes faster and more efficiently, there are several other language-neutral formats like Message Pack or BSON that can be used just as easily as JSON.

pavlo-yashchuk commented 2 years ago

@fpagliughi thanks it will always be written in Python