add level 3

This commit is contained in:
Матвей
2026-11-07 15:00:53 +03:00
parent eafb825657
commit 7b6c10cde9
54 changed files with 1593 additions and 120 deletions
+10 -3
View File
@@ -1,6 +1,7 @@
"""Small durable RabbitMQ adapter; broker messages contain no attachment bytes."""
import json
import os
import ssl
from pathlib import Path
import pika
@@ -16,13 +17,19 @@ DLQ = "attachment.process.v1.dlq"
def broker_url() -> str:
path = os.environ.get("BROKER_URL_FILE")
value = Path(path).read_text(encoding="utf-8").strip() if path else os.environ.get("BROKER_URL", "")
if not value.startswith(("amqp://", "amqps://")):
raise ValueError("BROKER_URL или BROKER_URL_FILE должен содержать AMQP URL")
if not value.startswith("amqps://"):
raise ValueError("BROKER_URL или BROKER_URL_FILE должен содержать AMQPS URL")
return value
def _connection() -> pika.BlockingConnection:
connection = pika.BlockingConnection(pika.URLParameters(broker_url()))
url = broker_url()
parameters = pika.URLParameters(url)
ca_file = os.environ.get("BROKER_CA_FILE")
if not ca_file:
raise ValueError("BROKER_CA_FILE is required for verified broker TLS")
parameters.ssl_options = pika.SSLOptions(ssl.create_default_context(cafile=ca_file), parameters.host)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue=QUEUE, durable=True)
channel.queue_declare(queue=DLQ, durable=True)