reserachers talk to agency with approval feedback
This commit is contained in:
parent
a7bfdab1f3
commit
b45f3d65b7
28
funding_agency.py
Normal file
28
funding_agency.py
Normal file
@ -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()
|
||||||
27
researcher.py
Normal file
27
researcher.py
Normal file
@ -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()
|
||||||
Loading…
x
Reference in New Issue
Block a user