"""Persistent, confirmed RabbitMQ messages contain identifiers only.""" import os from pathlib import Path import pika QUEUE = 'attachments.v1' def connect(): url = Path(os.environ['BROKER_URL_FILE']).read_text().strip() params = pika.URLParameters(url) params.heartbeat = 0 # one bounded image at a time; connection failure causes redelivery params.socket_timeout = 5 params.blocked_connection_timeout = 10 connection = pika.BlockingConnection(params) channel = connection.channel() channel.queue_declare(queue=QUEUE, durable=True) channel.confirm_delivery() return connection, channel