29 lines
1005 B
Python
29 lines
1005 B
Python
import json
|
|
|
|
from pyinfra.config import CONFIG
|
|
from pyinfra.rabbitmq import make_channel, declare_queue, make_connection
|
|
from pyinfra.storage.storages import get_s3_storage
|
|
|
|
|
|
def build_message_bodies():
|
|
storage = get_s3_storage()
|
|
for dossier_id, pdf_name in storage.list_bucket_files(CONFIG.test.bucket):
|
|
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)
|