import pika from functions import log connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials("user", "password"))) channel = connection.channel() channel.queue_declare(queue='research_proposals') def process_proposal(ch, method, properties, body): proposal = body.decode() acronym, title, description, amount = proposal.split(',') if 200000 <= int(amount) <= 500000: channel.basic_publish(exchange='', routing_key=properties.reply_to, properties=pika.BasicProperties(correlation_id=properties.correlation_id), body="approved") project_info=f"{acronym},{title},{description},{amount}" channel.basic_publish(exchange='', routing_key='approved_projects', body=project_info) log(f"{acronym} approved") else: channel.basic_publish(exchange='', routing_key=properties.reply_to, properties=pika.BasicProperties(correlation_id=properties.correlation_id), body="rejected") log(f"{acronym} rejected") channel.basic_consume(queue='research_proposals', on_message_callback=process_proposal, auto_ack=True) try: channel.start_consuming() except KeyboardInterrupt: channel.stop_consuming() connection.close()