import json from pyinfra.config import CONFIG from pyinfra.storage.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"Put {body} on {CONFIG.rabbitmq.queues.input}") for method_frame, _, body in channel.consume(queue=CONFIG.rabbitmq.queues.output): print(f"Received {json.loads(body)}") channel.basic_ack(method_frame.delivery_tag)