pyinfra/scripts/mock_client.py
Matthias Bisping 5cd52928ce refactorig WIP
2022-02-16 15:49:38 +01:00

29 lines
976 B
Python

import json
from pyinfra.config import CONFIG
from pyinfra.minio import MinioHandle
from pyinfra.rabbitmq import make_channel, declare_queue, make_connection
def build_message_bodies():
minio_client = MinioHandle()
for dossier_id, pdf_name in minio_client.list_folders_and_files():
file_id = pdf_name.split(".")[0]
yield json.dumps({"dossierId": dossier_id, "fileId": file_id})
if __name__ == "__main__":
connection = make_connection()
channel = make_channel(connection)
declare_queue(channel, CONFIG.rabbitmq.queues.input)
declare_queue(channel, CONFIG.rabbitmq.queues.output)
for body in build_message_bodies():
channel.basic_publish("", CONFIG.rabbitmq.queues.input, body)
print(f" [x] Put {body} on {CONFIG.rabbitmq.queues.input}")
for method_frame, _, body in channel.consume(queue=CONFIG.rabbitmq.queues.output):
print(json.loads(body))
channel.basic_ack(method_frame.delivery_tag)