-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
52 lines (43 loc) · 1.7 KB
/
config.py
File metadata and controls
52 lines (43 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""AMQP configuration classes and enums"""
from dataclasses import dataclass, field
from enum import Enum
from typing import Any
class AmqpBindingType(Enum):
"""Types of AMQP bindings supported"""
QUEUE = "queue"
ROUTING_KEY = "routingKey"
EXCHANGE = "exchange"
REPLY = "reply"
@dataclass
class AmqpConfig:
"""Resolved AMQP configuration from AsyncAPI bindings and precedence rules"""
queue_name: str
exchange_name: str = ""
exchange_type: str = "direct"
routing_key: str = ""
binding_type: AmqpBindingType = AmqpBindingType.QUEUE
queue_properties: dict[str, Any] = field(default_factory=lambda: {})
binding_arguments: dict[str, Any] = field(default_factory=lambda: {})
arguments: dict[str, Any] = field(default_factory=lambda: {})
def to_producer_args(self) -> dict[str, Any]:
"""Convert to AmqpProducer constructor arguments"""
return {
"queue_name": self.queue_name,
"exchange_name": self.exchange_name,
"exchange_type": self.exchange_type,
"routing_key": self.routing_key,
"queue_properties": self.queue_properties,
"arguments": self.arguments,
}
def to_consumer_args(self) -> dict[str, Any]:
"""Convert to AmqpConsumer constructor arguments"""
return {
"queue_name": self.queue_name,
"exchange_name": self.exchange_name,
"exchange_type": self.exchange_type,
"routing_key": self.routing_key,
"binding_type": self.binding_type,
"queue_properties": self.queue_properties,
"binding_arguments": self.binding_arguments,
"arguments": self.arguments,
}