From 8c208c00286d6edcc941d88abda24fc0fc8e86f2 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 12 Jun 2018 09:20:17 +0200 Subject: [PATCH] Use the Redis backend to dispatch messages to the core bus if available --- platypush/backend/mqtt.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/platypush/backend/mqtt.py b/platypush/backend/mqtt.py index baf6ac25b..126ac7d4e 100644 --- a/platypush/backend/mqtt.py +++ b/platypush/backend/mqtt.py @@ -5,6 +5,7 @@ import paho.mqtt.publish as publisher from platypush.backend import Backend from platypush.message import Message +from platypush.context import get_backend class MqttBackend(Backend): @@ -26,6 +27,11 @@ class MqttBackend(Backend): self.port = port self.topic = '{}/{}'.format(topic, self.device_id) + try: + self.redis = get_backend('redis') + except: + self.redis = None + def send_message(self, msg): publisher.single(self.topic, str(msg), hostname=self.host, port=self.port) @@ -43,7 +49,11 @@ class MqttBackend(Backend): pass self.logger.info('Received message on the MQTT backend: {}'.format(msg)) - self.bus.post(msg) + + if self.redis: + self.redis.send_message(msg) + else: + self.bus.post(msg) super().run() client = mqtt.Client()