rb-commons 0.1.24__py3-none-any.whl → 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rb_commons/broker/__init__.py +0 -0
- rb_commons/broker/consumer.py +29 -0
- rb_commons/configs/config.py +4 -0
- rb_commons/configs/rabbitmq.py +26 -0
- {rb_commons-0.1.24.dist-info → rb_commons-0.2.2.dist-info}/METADATA +2 -1
- {rb_commons-0.1.24.dist-info → rb_commons-0.2.2.dist-info}/RECORD +8 -5
- {rb_commons-0.1.24.dist-info → rb_commons-0.2.2.dist-info}/WHEEL +0 -0
- {rb_commons-0.1.24.dist-info → rb_commons-0.2.2.dist-info}/top_level.txt +0 -0
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
from aio_pika import ExchangeType, IncomingMessage
|
2
|
+
from rb_commons.configs.rabbitmq import RabbitMQConnection
|
3
|
+
|
4
|
+
|
5
|
+
class BaseRabbitMQConsumer:
|
6
|
+
def __init__(self, exchange_name: str, queue_name: str, routing_key: str):
|
7
|
+
self.exchange_name = exchange_name
|
8
|
+
self.queue_name = queue_name
|
9
|
+
self.routing_key = routing_key
|
10
|
+
|
11
|
+
async def setup(self, channel):
|
12
|
+
exchange = await channel.declare_exchange(self.exchange_name, ExchangeType.DIRECT, durable=True)
|
13
|
+
queue = await channel.declare_queue(self.queue_name, durable=True)
|
14
|
+
await queue.bind(exchange, routing_key=self.routing_key)
|
15
|
+
return queue
|
16
|
+
|
17
|
+
async def consume(self):
|
18
|
+
async with RabbitMQConnection.get_channel() as channel:
|
19
|
+
queue = await self.setup(channel)
|
20
|
+
async with queue.iterator() as queue_iter:
|
21
|
+
async for message in queue_iter:
|
22
|
+
await self.process_message(message)
|
23
|
+
|
24
|
+
async def process_message(self, message: IncomingMessage):
|
25
|
+
async with message.process():
|
26
|
+
await self.handle_message(message.body.decode())
|
27
|
+
|
28
|
+
async def handle_message(self, body: str):
|
29
|
+
raise NotImplementedError("This method should be overridden by subclasses.")
|
rb_commons/configs/config.py
CHANGED
@@ -20,6 +20,10 @@ class CommonConfigs(BaseSettings):
|
|
20
20
|
POSTGRES_DB: Optional[str] = None
|
21
21
|
DB_ALEMBIC_URL: Optional[str] = None
|
22
22
|
|
23
|
+
# Broker
|
24
|
+
|
25
|
+
RABBITMQ_URL: Optional[str] = None
|
26
|
+
|
23
27
|
DIGITALOCEAN_STORAGE_BUCKET_NAME: Optional[str] = None
|
24
28
|
DIGITALOCEAN_S3_ENDPOINT_URL: Optional[str] = None
|
25
29
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
from contextlib import asynccontextmanager
|
2
|
+
from aio_pika import connect_robust, Message, ExchangeType
|
3
|
+
from rb_commons.configs.config import configs
|
4
|
+
|
5
|
+
class RabbitMQConnection:
|
6
|
+
_connection = None
|
7
|
+
_channel = None
|
8
|
+
|
9
|
+
@classmethod
|
10
|
+
@asynccontextmanager
|
11
|
+
async def get_channel(cls):
|
12
|
+
if not cls._connection:
|
13
|
+
cls._connection = await connect_robust(configs.RABBITMQ_URL)
|
14
|
+
cls._channel = await cls._connection.channel()
|
15
|
+
|
16
|
+
try:
|
17
|
+
yield cls._channel
|
18
|
+
finally:
|
19
|
+
pass
|
20
|
+
|
21
|
+
@classmethod
|
22
|
+
async def close(cls):
|
23
|
+
if cls._connection:
|
24
|
+
await cls._connection.close()
|
25
|
+
cls._connection = None
|
26
|
+
cls._channel = None
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: rb-commons
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2.2
|
4
4
|
Summary: Commons of project and simplified orm based on sqlalchemy.
|
5
5
|
Home-page: https://github.com/RoboSell-organization/rb-commons
|
6
6
|
Author: Abdulvoris
|
@@ -17,6 +17,7 @@ Requires-Dist: PyJWT==2.10.1
|
|
17
17
|
Requires-Dist: python-dotenv==1.0.1
|
18
18
|
Requires-Dist: SQLAlchemy==2.0.36
|
19
19
|
Requires-Dist: fastapi<0.120.0,>=0.115.6
|
20
|
+
Requires-Dist: aio-pika==9.5.5
|
20
21
|
Dynamic: author
|
21
22
|
Dynamic: author-email
|
22
23
|
Dynamic: classifier
|
@@ -1,7 +1,10 @@
|
|
1
1
|
rb_commons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
rb_commons/broker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
rb_commons/broker/consumer.py,sha256=84yLq8kJIGNYAH9_ySSTDpOMNL54NSs3cA8lNG8CTGY,1264
|
2
4
|
rb_commons/configs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
rb_commons/configs/config.py,sha256=
|
5
|
+
rb_commons/configs/config.py,sha256=zla62zy3UfjE2YpvSDwsfhP2Qsm0BbGsycngfyiVvE4,1617
|
4
6
|
rb_commons/configs/injections.py,sha256=6B1EOgIGnkWv3UrFaV9PRgG0-CJAbLu1UZ3kq-SjPVU,273
|
7
|
+
rb_commons/configs/rabbitmq.py,sha256=vUqa_PcZkPp1lX0B6HLSAXVMUcPR2_8-8cN-C7xFxRI,741
|
5
8
|
rb_commons/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
9
|
rb_commons/http/exceptions.py,sha256=EGRMr1cRgiJ9Q2tkfANbf0c6-zzXf1CD6J3cmCaT_FA,1885
|
7
10
|
rb_commons/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -13,7 +16,7 @@ rb_commons/schemes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
|
|
13
16
|
rb_commons/schemes/jwt.py,sha256=F66JJDhholuOPPzlKeoC6f1TL4gXg4oRUrV5yheNpyo,1675
|
14
17
|
rb_commons/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
18
|
rb_commons/utils/media.py,sha256=KNY_9SdRa3Rp7d3B1tZaXkhmzVa65RcS62BYwZP1bVM,332
|
16
|
-
rb_commons-0.
|
17
|
-
rb_commons-0.
|
18
|
-
rb_commons-0.
|
19
|
-
rb_commons-0.
|
19
|
+
rb_commons-0.2.2.dist-info/METADATA,sha256=_WLAr4eS8xznDVugZa1-aRQz4eKYo4_2Y12t8P7OH8c,6570
|
20
|
+
rb_commons-0.2.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
21
|
+
rb_commons-0.2.2.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
|
22
|
+
rb_commons-0.2.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|