catch bad messages in RabbitMQ

This commit is contained in:
Matěj Divecký 2020-09-28 22:32:17 +02:00
parent eafc489424
commit d689381c9c

View file

@ -37,19 +37,30 @@ def send_message(text, sender, destination):
return True
else:
print('Sender not in registrations.json')
print('Sender not in registrations.json.')
return False
def callback(ch, method, properties, body):
try:
body = json.loads(body)
if len(body) == 3:
text = body[0]
sender = body[1]
destination = body[2]
if send_message(text, sender, destination):
print("Message sent succesfully")
else:
print("Sending message failed")
else:
print("Sending message failed")
channel.basic_ack(delivery_tag=method.delivery_tag)
return True
except:
channel.basic_ack(delivery_tag=method.delivery_tag)
pass
channel.basic_consume('signal-send', callback, auto_ack=False)