41 lines
1.9 KiB
Python
41 lines
1.9 KiB
Python
import pika
|
|
import uuid
|
|
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials("user", "password")))
|
|
channel = connection.channel()
|
|
|
|
channel.queue_declare(queue='research_proposals')
|
|
|
|
|
|
def process_response(ch, method, properties, body):
|
|
if corr_id == properties.correlation_id:
|
|
print(body)
|
|
else:
|
|
print("response failed")
|
|
|
|
proposals = [
|
|
{"acronym": "PRT1", "title": "Phantom Blood", "description": "Johnathen", "amount": "300000"},
|
|
{"acronym": "PRT2", "title": "Battle Tendency", "description": "Joseph", "amount": "400000"},
|
|
{"acronym": "PRT3", "title": "Stardust Crusaders", "description": "Jotaro", "amount": "250000"},
|
|
{"acronym": "PRT4", "title": "Diamond is Unbreakable", "description": "Josuke", "amount": "100000"},
|
|
{"acronym": "PRT5", "title": "Golden Wind", "description": "Giorno", "amount": "900000"},
|
|
{"acronym": "PRT6", "title": "Stone Ocean", "description": "Jolyne", "amount": "420000"},
|
|
{"acronym": "PRT7", "title": "Steel Ball Run", "description": "Johnny", "amount": "100000"},
|
|
{"acronym": "PRT8", "title": "Jojolion", "description": "Josuke", "amount": "900000"},
|
|
{"acronym": "PRT9", "title": "Jojolands", "description": "Jodio", "amount": "450000"}
|
|
]
|
|
|
|
corr_id = str(uuid.uuid4())
|
|
|
|
for proposal in proposals:
|
|
|
|
response_queue = channel.queue_declare(queue='', exclusive=True).method.queue
|
|
|
|
channel.basic_publish(exchange='',
|
|
routing_key='research_proposals',
|
|
properties=pika.BasicProperties(reply_to=response_queue, correlation_id=corr_id),
|
|
body=f"{proposal['acronym']},{proposal['title']},{proposal['description']},{proposal['amount']}")
|
|
print(f"Proposal {proposal['acronym']} sent")
|
|
channel.basic_consume(queue=response_queue, on_message_callback=process_response)
|
|
|
|
connection.close() |