catch bad messages in RabbitMQ
This commit is contained in:
parent
eafc489424
commit
d689381c9c
1 changed files with 19 additions and 8 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue