pyinfra/scripts/mock_publish.py
2022-02-14 17:18:35 +01:00

31 lines
955 B
Python

import json
import pika
from mini_queue.utils.config import CONFIG
if __name__ == "__main__":
credentials = pika.PlainCredentials(CONFIG.rabbitmq.user, CONFIG.rabbitmq.password)
parameters = pika.ConnectionParameters(
host=CONFIG.rabbitmq.host,
port=CONFIG.rabbitmq.port,
heartbeat=CONFIG.rabbitmq.heartbeat,
credentials=credentials,
)
body = json.dumps({"fileId": "234", "dossierId": "3403"})
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue=CONFIG.rabbitmq.queues.input, durable=True)
channel.queue_declare(queue=CONFIG.rabbitmq.queues.output, durable=True)
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))
break