diff --git a/funding_agency.py b/funding_agency.py new file mode 100644 index 0000000..50d2ed3 --- /dev/null +++ b/funding_agency.py @@ -0,0 +1,28 @@ +import pika + +connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials("user", "password"))) + +channel = connection.channel() + +channel.queue_declare(queue='research_proposals') + +print("Waiting for 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=str(properties.reply_to), + body=f"{acronym} approved") + print(f"{acronym} approved") + else: + channel.basic_publish(exchange='', + routing_key=str(properties.reply_to), + body=f"{acronym} rejected") + print(f"{acronym} rejected") + +channel.basic_consume(queue='research_proposals', on_message_callback=process_proposal, auto_ack=True) + +channel.start_consuming() \ No newline at end of file diff --git a/researcher.py b/researcher.py new file mode 100644 index 0000000..cb65404 --- /dev/null +++ b/researcher.py @@ -0,0 +1,27 @@ +import pika + +connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials("user", "password"))) +channel = connection.channel() + +channel.queue_declare(queue='research_proposals') + +proposals = [ + {"acronym": "PROJ1", "title": "Project 1", "description": "Description 1", "amount": "300000"}, + {"acronym": "PROJ2", "title": "Project 2", "description": "Description 2", "amount": "400000"}, + {"acronym": "PROJ3", "title": "Project 3", "description": "Description 3", "amount": "250000"}, + {"acronym": "PROJ4", "title": "Project 4", "description": "Description 4", "amount": "100000"}, + {"acronym": "PROJ5", "title": "Project 5", "description": "Description 5", "amount": "900000"}, + {"acronym": "PROJ6", "title": "Project 6", "description": "Description 6", "amount": "420000"} +] + +for proposal in proposals: + result = channel.queue_declare(queue='', exclusive=True) + reply_to = result.method.queue + + channel.basic_publish(exchange='', + routing_key='research_proposals', + properties=pika.BasicProperties(reply_to=reply_to), + body=f"{proposal['acronym']},{proposal['title']},{proposal['description']},{proposal['amount']}") + print(f"Proposal {proposal['acronym']} sent") + +connection.close() \ No newline at end of file