libretificacaotjcore 0.1.36__py3-none-any.whl → 0.1.39__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 +28 -31
- {libretificacaotjcore-0.1.36.dist-info → libretificacaotjcore-0.1.39.dist-info}/METADATA +1 -1
- {libretificacaotjcore-0.1.36.dist-info → libretificacaotjcore-0.1.39.dist-info}/RECORD +5 -5
- {libretificacaotjcore-0.1.36.dist-info → libretificacaotjcore-0.1.39.dist-info}/WHEEL +0 -0
- {libretificacaotjcore-0.1.36.dist-info → libretificacaotjcore-0.1.39.dist-info}/top_level.txt +0 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import aio_pika
|
|
2
2
|
import json
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
class RabbitMQConsumer:
|
|
6
5
|
def __init__(
|
|
7
6
|
self,
|
|
7
|
+
*,
|
|
8
8
|
host: str,
|
|
9
9
|
queue: str,
|
|
10
10
|
username: str,
|
|
11
11
|
password: str,
|
|
12
|
-
vhost: str ="/",
|
|
12
|
+
vhost: str = "/",
|
|
13
13
|
):
|
|
14
14
|
self.host = host
|
|
15
15
|
self.queue = queue
|
|
@@ -18,39 +18,36 @@ class RabbitMQConsumer:
|
|
|
18
18
|
self.vhost = vhost
|
|
19
19
|
self.connection = None
|
|
20
20
|
self.channel = None
|
|
21
|
-
self.connect()
|
|
22
21
|
|
|
23
|
-
def connect(self):
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
heartbeat=
|
|
30
|
-
blocked_connection_timeout=300,
|
|
22
|
+
async def connect(self):
|
|
23
|
+
self.connection = await aio_pika.connect_robust(
|
|
24
|
+
host=self.host,
|
|
25
|
+
login=self.username,
|
|
26
|
+
password=self.password,
|
|
27
|
+
virtualhost=self.vhost,
|
|
28
|
+
heartbeat=600,
|
|
31
29
|
)
|
|
32
|
-
|
|
33
|
-
self.
|
|
34
|
-
self.channel =
|
|
35
|
-
self.channel.queue_declare(queue=self.queue, durable=True)
|
|
30
|
+
self.channel = await self.connection.channel()
|
|
31
|
+
await self.channel.set_qos(prefetch_count=1)
|
|
32
|
+
await self.channel.declare_queue(self.queue, durable=True)
|
|
36
33
|
|
|
37
|
-
def start_consuming(self, callback):
|
|
38
|
-
def on_message(ch, method, properties, body):
|
|
39
|
-
mensagem = json.loads(body)
|
|
40
|
-
callback(mensagem)
|
|
41
|
-
ch.basic_ack(delivery_tag=method.delivery_tag)
|
|
42
|
-
self.close()
|
|
43
|
-
|
|
34
|
+
async def start_consuming(self, *, callback):
|
|
44
35
|
if not self.channel:
|
|
45
36
|
raise RuntimeError("❌ Canal RabbitMQ não conectado. Chame connect() antes.")
|
|
46
37
|
|
|
47
|
-
self.channel.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
queue = await self.channel.get_queue(self.queue)
|
|
39
|
+
|
|
40
|
+
async with queue.iterator() as queue_iter:
|
|
41
|
+
async for message in queue_iter:
|
|
42
|
+
async with message.process():
|
|
43
|
+
try:
|
|
44
|
+
mensagem = json.loads(message.body.decode())
|
|
45
|
+
await callback(mensagem)
|
|
46
|
+
except Exception as e:
|
|
47
|
+
print(f"Erro ao processar mensagem: {e}")\
|
|
48
|
+
|
|
49
|
+
await self.close()
|
|
53
50
|
|
|
54
|
-
def close(self):
|
|
51
|
+
async def close(self):
|
|
55
52
|
if self.connection:
|
|
56
|
-
self.connection.close()
|
|
53
|
+
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.39
|
|
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
|
|
@@ -13,11 +13,11 @@ libretificacaotjcore/enums/e_fase_retificacao.py,sha256=g7xVlIMKpo9QUDnOdwYzsx8o
|
|
|
13
13
|
libretificacaotjcore/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
14
|
libretificacaotjcore/services/crypto_pass_service.py,sha256=9D0vyjan6f_8AfNxGkLpGdvyMpojsJq_AAySpv_zKMc,740
|
|
15
15
|
libretificacaotjcore/services/file_service.py,sha256=14CJokBbrsryQGmL0_unH2QKZpnteEAfxf5CPFdv6cE,2075
|
|
16
|
-
libretificacaotjcore/services/rabbitmq_consumer.py,sha256=
|
|
16
|
+
libretificacaotjcore/services/rabbitmq_consumer.py,sha256=aw2NaPkuF1AewJh2dQetTsZVvFlimjw96o5r-jnu86A,1687
|
|
17
17
|
libretificacaotjcore/services/rabbitmq_publisher.py,sha256=xsb9LmIuZizzq5lxnEEZKMK3U952KSQ2oqlTBZi2Lt8,1787
|
|
18
18
|
libretificacaotjcore/services/request_servico_api.py,sha256=G7vnmvOfwrCGL-Jy_5tCKG-l5E00OCkJfkuoa5Y6sHo,613
|
|
19
19
|
libretificacaotjcore/services/s3_service.py,sha256=HKR_jt2H3XdV1PCzo5R5bnhmoQ3I46Yn5IqAvVPhsjs,2946
|
|
20
|
-
libretificacaotjcore-0.1.
|
|
21
|
-
libretificacaotjcore-0.1.
|
|
22
|
-
libretificacaotjcore-0.1.
|
|
23
|
-
libretificacaotjcore-0.1.
|
|
20
|
+
libretificacaotjcore-0.1.39.dist-info/METADATA,sha256=DkNnpyxrvUU7Co7tsQGd149VPHS9sv3M3C3UtOckiHE,2564
|
|
21
|
+
libretificacaotjcore-0.1.39.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
22
|
+
libretificacaotjcore-0.1.39.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
|
|
23
|
+
libretificacaotjcore-0.1.39.dist-info/RECORD,,
|
|
File without changes
|
{libretificacaotjcore-0.1.36.dist-info → libretificacaotjcore-0.1.39.dist-info}/top_level.txt
RENAMED
|
File without changes
|