libretificacaotjcore 0.1.26__py3-none-any.whl → 0.1.28__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.
Potentially problematic release.
This version of libretificacaotjcore might be problematic. Click here for more details.
- libretificacaotjcore/services/rabbitmq_consumer.py +6 -5
- libretificacaotjcore/services/rabbitmq_publisher.py +31 -27
- {libretificacaotjcore-0.1.26.dist-info → libretificacaotjcore-0.1.28.dist-info}/METADATA +2 -1
- {libretificacaotjcore-0.1.26.dist-info → libretificacaotjcore-0.1.28.dist-info}/RECORD +6 -6
- {libretificacaotjcore-0.1.26.dist-info → libretificacaotjcore-0.1.28.dist-info}/WHEEL +0 -0
- {libretificacaotjcore-0.1.26.dist-info → libretificacaotjcore-0.1.28.dist-info}/top_level.txt +0 -0
|
@@ -5,11 +5,11 @@ import json
|
|
|
5
5
|
class RabbitMQConsumer:
|
|
6
6
|
def __init__(
|
|
7
7
|
self,
|
|
8
|
-
host,
|
|
9
|
-
queue,
|
|
10
|
-
username,
|
|
11
|
-
password,
|
|
12
|
-
vhost="/",
|
|
8
|
+
host: str,
|
|
9
|
+
queue: str,
|
|
10
|
+
username: str,
|
|
11
|
+
password: str,
|
|
12
|
+
vhost: str ="/",
|
|
13
13
|
):
|
|
14
14
|
self.host = host
|
|
15
15
|
self.queue = queue
|
|
@@ -18,6 +18,7 @@ class RabbitMQConsumer:
|
|
|
18
18
|
self.vhost = vhost
|
|
19
19
|
self.connection = None
|
|
20
20
|
self.channel = None
|
|
21
|
+
self.connect()
|
|
21
22
|
|
|
22
23
|
def connect(self):
|
|
23
24
|
credentials = pika.PlainCredentials(self.username, self.password)
|
|
@@ -1,52 +1,56 @@
|
|
|
1
|
-
import
|
|
1
|
+
import aio_pika
|
|
2
2
|
import json
|
|
3
|
+
from aio_pika.abc import AbstractRobustConnection, AbstractChannel, AbstractQueue
|
|
3
4
|
|
|
4
5
|
class RabbitMQPublisher:
|
|
5
6
|
def __init__(
|
|
6
7
|
self,
|
|
7
|
-
host,
|
|
8
|
-
queue,
|
|
9
|
-
username,
|
|
10
|
-
password,
|
|
11
|
-
vhost="/",
|
|
8
|
+
host: str,
|
|
9
|
+
queue: str,
|
|
10
|
+
username: str,
|
|
11
|
+
password: str,
|
|
12
|
+
vhost: str = "/",
|
|
12
13
|
):
|
|
13
14
|
self.host = host
|
|
14
15
|
self.queue = queue
|
|
15
16
|
self.username = username
|
|
16
17
|
self.password = password
|
|
17
18
|
self.vhost = vhost
|
|
18
|
-
self.connection = None
|
|
19
|
-
self.channel = None
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
self.connection: AbstractRobustConnection | None = None
|
|
21
|
+
self.channel: AbstractChannel | None = None
|
|
22
|
+
self.queue_obj: AbstractQueue | None = None
|
|
23
|
+
|
|
24
|
+
async def connect(self):
|
|
25
|
+
self.connection = await aio_pika.connect_robust(
|
|
24
26
|
host=self.host,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
login=self.username,
|
|
28
|
+
password=self.password,
|
|
29
|
+
virtualhost=self.vhost,
|
|
27
30
|
heartbeat=60,
|
|
28
|
-
blocked_connection_timeout=300,
|
|
29
31
|
)
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
self.channel = self.connection.channel()
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
self.channel = await self.connection.channel()
|
|
35
|
+
# garante que mensagens não são perdidas
|
|
36
|
+
self.queue_obj = await self.channel.declare_queue(
|
|
37
|
+
self.queue, durable=True
|
|
38
|
+
)
|
|
34
39
|
|
|
35
|
-
def publish(self, message: dict):
|
|
40
|
+
async def publish(self, message: dict):
|
|
36
41
|
if not self.channel:
|
|
37
42
|
raise RuntimeError("❌ Canal RabbitMQ não conectado. Chame connect() antes.")
|
|
38
43
|
|
|
39
|
-
body = json.dumps(message)
|
|
40
|
-
self.channel.
|
|
41
|
-
|
|
44
|
+
body = json.dumps(message).encode("utf-8")
|
|
45
|
+
await self.channel.default_exchange.publish(
|
|
46
|
+
aio_pika.Message(
|
|
47
|
+
body=body,
|
|
48
|
+
delivery_mode=aio_pika.DeliveryMode.PERSISTENT, # torna a msg persistente
|
|
49
|
+
),
|
|
42
50
|
routing_key=self.queue,
|
|
43
|
-
body=body,
|
|
44
|
-
properties=pika.BasicProperties(
|
|
45
|
-
delivery_mode=2 # torna a mensagem persistente
|
|
46
|
-
)
|
|
47
51
|
)
|
|
48
52
|
print(f"✅ Mensagem publicada na fila '{self.queue}': {message}")
|
|
49
53
|
|
|
50
|
-
def close(self):
|
|
54
|
+
async def close(self):
|
|
51
55
|
if self.connection:
|
|
52
|
-
self.connection.close()
|
|
56
|
+
await self.connection.close()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: libretificacaotjcore
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.28
|
|
4
4
|
Summary: Biblioteca para centralizar conexao com filas no rabbit e banco de dados no mongodb para os servicos de retificacao da TJ
|
|
5
5
|
Author-email: Jhonatan Azevedo <dev.azevedo@outlook.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/seu-usuario/libretificacaotjcore
|
|
@@ -21,6 +21,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
21
21
|
Classifier: Operating System :: OS Independent
|
|
22
22
|
Requires-Python: >=3.12
|
|
23
23
|
Description-Content-Type: text/markdown
|
|
24
|
+
Requires-Dist: aio-pika>=9.5.7
|
|
24
25
|
Requires-Dist: aiofiles>=24.1.0
|
|
25
26
|
Requires-Dist: boto3>=1.39.16
|
|
26
27
|
Requires-Dist: cryptography>=45.0.6
|
|
@@ -12,10 +12,10 @@ libretificacaotjcore/enums/e_eventos.py,sha256=EClyRpHtL21t_s1b_26bbBKpvd6QgOtIe
|
|
|
12
12
|
libretificacaotjcore/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
libretificacaotjcore/services/crypto_pass_service.py,sha256=9D0vyjan6f_8AfNxGkLpGdvyMpojsJq_AAySpv_zKMc,740
|
|
14
14
|
libretificacaotjcore/services/file_service.py,sha256=14CJokBbrsryQGmL0_unH2QKZpnteEAfxf5CPFdv6cE,2075
|
|
15
|
-
libretificacaotjcore/services/rabbitmq_consumer.py,sha256=
|
|
16
|
-
libretificacaotjcore/services/rabbitmq_publisher.py,sha256=
|
|
15
|
+
libretificacaotjcore/services/rabbitmq_consumer.py,sha256=XPbOvFR3HySfA1IROLPrsb4AmeHeq1Unthxt44vaqik,1760
|
|
16
|
+
libretificacaotjcore/services/rabbitmq_publisher.py,sha256=xsb9LmIuZizzq5lxnEEZKMK3U952KSQ2oqlTBZi2Lt8,1787
|
|
17
17
|
libretificacaotjcore/services/s3_service.py,sha256=HKR_jt2H3XdV1PCzo5R5bnhmoQ3I46Yn5IqAvVPhsjs,2946
|
|
18
|
-
libretificacaotjcore-0.1.
|
|
19
|
-
libretificacaotjcore-0.1.
|
|
20
|
-
libretificacaotjcore-0.1.
|
|
21
|
-
libretificacaotjcore-0.1.
|
|
18
|
+
libretificacaotjcore-0.1.28.dist-info/METADATA,sha256=3mqyRHsrlmQAWwPJsIJelBleid6MGyf-a6UL3crwexw,2534
|
|
19
|
+
libretificacaotjcore-0.1.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
20
|
+
libretificacaotjcore-0.1.28.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
|
|
21
|
+
libretificacaotjcore-0.1.28.dist-info/RECORD,,
|
|
File without changes
|
{libretificacaotjcore-0.1.26.dist-info → libretificacaotjcore-0.1.28.dist-info}/top_level.txt
RENAMED
|
File without changes
|