Commit
·
0bfda05
1
Parent(s):
aa26750
- config.py +11 -2
- rabbit_repo.py +3 -3
config.py
CHANGED
|
@@ -11,8 +11,17 @@ APPSETTINGS_PATH = os.environ.get("APPSETTINGS_JSON", "appsettings.json")
|
|
| 11 |
class Settings:
|
| 12 |
"""Settings object with attribute access."""
|
| 13 |
def __init__(self, data: dict):
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def _load_json(path):
|
|
|
|
| 11 |
class Settings:
|
| 12 |
"""Settings object with attribute access."""
|
| 13 |
def __init__(self, data: dict):
|
| 14 |
+
self._data = data
|
| 15 |
+
|
| 16 |
+
@property
|
| 17 |
+
def EXCHANGE_TYPES(self):
|
| 18 |
+
# Prefer nested config, fallback to root
|
| 19 |
+
rabbitmq = self._data.get("RabbitMQ", {})
|
| 20 |
+
return rabbitmq.get("ExchangeTypes", self._data.get("EXCHANGE_TYPES", {}))
|
| 21 |
+
|
| 22 |
+
@property
|
| 23 |
+
def RABBIT_EXCHANGE_TYPE(self):
|
| 24 |
+
return self._data.get("RabbitExhangeType", "direct")
|
| 25 |
|
| 26 |
|
| 27 |
def _load_json(path):
|
rabbit_repo.py
CHANGED
|
@@ -13,14 +13,14 @@ from utils import to_json, json_compress_str
|
|
| 13 |
class RabbitRepo(RabbitBase):
|
| 14 |
def __init__(self, external_source: str):
|
| 15 |
super().__init__(exchange_type_resolver=self._resolve_type)
|
| 16 |
-
self._source = external_source
|
| 17 |
|
| 18 |
def _resolve_type(self, exch: str) -> str:
|
| 19 |
-
#
|
| 20 |
matches = [k for k in settings.EXCHANGE_TYPES.keys() if exch.lower().startswith(k.lower())]
|
| 21 |
if matches:
|
| 22 |
return settings.EXCHANGE_TYPES[max(matches, key=len)]
|
| 23 |
-
return
|
| 24 |
|
| 25 |
async def publish(self, exchange: str, obj: Any, routing_key: str = "") -> None:
|
| 26 |
ex = await self.ensure_exchange(exchange)
|
|
|
|
| 13 |
class RabbitRepo(RabbitBase):
|
| 14 |
def __init__(self, external_source: str):
|
| 15 |
super().__init__(exchange_type_resolver=self._resolve_type)
|
| 16 |
+
self._source = external_source
|
| 17 |
|
| 18 |
def _resolve_type(self, exch: str) -> str:
|
| 19 |
+
# Outbound: Use EXCHANGE_TYPES if present, else default to 'fanout'
|
| 20 |
matches = [k for k in settings.EXCHANGE_TYPES.keys() if exch.lower().startswith(k.lower())]
|
| 21 |
if matches:
|
| 22 |
return settings.EXCHANGE_TYPES[max(matches, key=len)]
|
| 23 |
+
return "fanout" # Default for outbound
|
| 24 |
|
| 25 |
async def publish(self, exchange: str, obj: Any, routing_key: str = "") -> None:
|
| 26 |
ex = await self.ensure_exchange(exchange)
|