This commit is contained in:
@ -35,6 +35,7 @@ if config.SENTRY_DSN:
|
||||
|
||||
|
||||
def setup_rabbit() -> None:
|
||||
logging.info("Connecting to RabbitMQ")
|
||||
credentials = pika.PlainCredentials(config.RABBIT_USERNAME, config.RABBIT_PASSWORD)
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host=config.RABBIT_HOSTNAME,
|
||||
credentials=credentials,
|
||||
@ -49,6 +50,7 @@ def setup_rabbit() -> None:
|
||||
exclusive=True).method.queue
|
||||
channel.queue_bind(exchange=config.RABBIT_EXCHANGE, queue=queue)
|
||||
channel.basic_consume(queue=queue, on_message_callback=on_message, auto_ack=True)
|
||||
logging.debug("Starting consumption")
|
||||
channel.start_consuming()
|
||||
|
||||
|
||||
@ -61,11 +63,13 @@ def on_message(channel, method_frame, header_frame, body):
|
||||
r.raise_for_status()
|
||||
if 'device_id' not in r.json():
|
||||
logging.error("Input-service response invalid")
|
||||
logging.info(f"Sending alert command to device {r.json()['device_id']}")
|
||||
mqtt.publish(subtopic=r.json()['device_id'],
|
||||
message=json.dumps({"command": "doAlert"}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.info("Guard service starting")
|
||||
mqtt = MQTT()
|
||||
mqtt.topic = config.MQTT_TOPIC
|
||||
mqtt.connect()
|
||||
|
Reference in New Issue
Block a user