问题
I'm working with the paho-mqtt client and wondering if anybody of you can help me subscribing and publishing messages parallel.
My Setup: I've got a couple of sensors writing data into an InfluxDB. Using subscriptions with some parameters (time, start of recording) I can afterwards get the sensordata out of the InfluxDB. I've wrote a script which subscribes to all sensors/# and hands me a list of all avalible sensors in my system, which leads me directly to my question:
My Problem: Now I've got an list of all my avalible sensors: topics_list:
1. sensors/device1/temperature
2. sensors/device2/gyroscope
3. sensors/device1/gyroscope
also I've got a list containing the correct paramters for my InfluxDB query: list_request
1. {"response":"sensors/device1/temperature","start":"2020-07T13:27:53Z","duration":"80s","interval":"1s"}
2. {"response":"sensors/device2/gyroscope","start":"2020-07T13:27:53Z","duration":"80s","interval":"1s"}
3. {"response":"sensors/device1/gyroscope","start":"2020-07T13:27:53Z","duration":"80s","interval":"1s"}
Now the workflow I've read about and used since now would be the following:
for i in topics_list: <br>
1. connect client
2. subscribe topic i
3. publish message i
I'm wondering if anybody of you now how to initialise, connect, publish and subscribe in a parallel manner and doing so increase the performance.
来源:https://stackoverflow.com/questions/60724535/how-to-subscribe-and-publish-parallel-in-paho-mqtt-python