| 2 | from send import email |
| 3 | |
| 4 | def main(): |
| 5 | # rabbitmq connection |
| 6 | connection = pika.BlockingConnection(pika.ConnectionParameters(host="rabbitmq",heartbeat=0)) |
| 7 | channel = connection.channel() |
| 8 | |
| 9 | def callback(ch, method, properties, body): |
| 10 | err = email.notification(body) |
| 11 | if err: |
| 12 | ch.basic_nack(delivery_tag=method.delivery_tag) |
| 13 | else: |
| 14 | ch.basic_ack(delivery_tag=method.delivery_tag) |
| 15 | |
| 16 | channel.basic_consume( |
| 17 | queue=os.environ.get("MP3_QUEUE"), on_message_callback=callback |
| 18 | ) |
| 19 | |
| 20 | print("Waiting for messages. To exit press CTRL+C") |
| 21 | |
| 22 | channel.start_consuming() |
| 23 | |
| 24 | if __name__ == "__main__": |
| 25 | try: |