Don't create an MQTT client connection if there are no topics to subscribe.

If we open multiple connections from multiple MQTT-based backends to the
same host, with some of them having no topics subscribed, Paho-MQTT can
mess up which client is supposed to receive which message and we may end
up with lost messages on the platypush_bus_mqt/<host> topic.
This commit is contained in:
Fabio Manganiello 2021-02-15 22:02:58 +01:00
parent 77c6f699a0
commit ee7407a7cc

View file

@ -319,8 +319,8 @@ class MqttBackend(Backend):
def run(self):
super().run()
if self.host:
topics = [self.topic] if self.subscribe_default_topic else []
if self.host and self.subscribe_default_topic:
topics = [self.topic]
client = self._get_client(host=self.host, port=self.port, topics=topics, username=self.username,
password=self.password, client_id=self.client_id,
tls_cafile=self.tls_cafile, tls_certfile=self.tls_certfile,