jararaca 0.2.37a10__py3-none-any.whl → 0.2.37a11__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 jararaca might be problematic. Click here for more details.
- jararaca/__init__.py +7 -0
- jararaca/messagebus/interceptors/aiopika_publisher_interceptor.py +66 -11
- {jararaca-0.2.37a10.dist-info → jararaca-0.2.37a11.dist-info}/METADATA +1 -1
- {jararaca-0.2.37a10.dist-info → jararaca-0.2.37a11.dist-info}/RECORD +8 -8
- pyproject.toml +1 -1
- {jararaca-0.2.37a10.dist-info → jararaca-0.2.37a11.dist-info}/LICENSE +0 -0
- {jararaca-0.2.37a10.dist-info → jararaca-0.2.37a11.dist-info}/WHEEL +0 -0
- {jararaca-0.2.37a10.dist-info → jararaca-0.2.37a11.dist-info}/entry_points.txt +0 -0
jararaca/__init__.py
CHANGED
|
@@ -59,6 +59,7 @@ if TYPE_CHECKING:
|
|
|
59
59
|
from .messagebus.decorators import MessageBusController, MessageHandler
|
|
60
60
|
from .messagebus.interceptors.aiopika_publisher_interceptor import (
|
|
61
61
|
AIOPikaConnectionFactory,
|
|
62
|
+
GenericPoolConfig,
|
|
62
63
|
MessageBusPublisherInterceptor,
|
|
63
64
|
)
|
|
64
65
|
from .messagebus.publisher import use_publisher
|
|
@@ -192,6 +193,7 @@ if TYPE_CHECKING:
|
|
|
192
193
|
"Put",
|
|
193
194
|
"Delete",
|
|
194
195
|
"use_publisher",
|
|
196
|
+
"GenericPoolConfig",
|
|
195
197
|
"AIOPikaConnectionFactory",
|
|
196
198
|
"MessageBusPublisherInterceptor",
|
|
197
199
|
"RedisWebSocketConnectionBackend",
|
|
@@ -221,6 +223,11 @@ _dynamic_imports: "dict[str, tuple[str, str, str | None]]" = {
|
|
|
221
223
|
"messagebus.bus_message_controller",
|
|
222
224
|
None,
|
|
223
225
|
),
|
|
226
|
+
"GenericPoolConfig": (
|
|
227
|
+
__SPEC_PARENT__,
|
|
228
|
+
"messagebus.interceptors.aiopika_publisher_interceptor",
|
|
229
|
+
None,
|
|
230
|
+
),
|
|
224
231
|
"ack": (__SPEC_PARENT__, "messagebus.bus_message_controller", None),
|
|
225
232
|
"nack": (__SPEC_PARENT__, "messagebus.bus_message_controller", None),
|
|
226
233
|
"reject": (__SPEC_PARENT__, "messagebus.bus_message_controller", None),
|
|
@@ -2,6 +2,7 @@ from contextlib import asynccontextmanager
|
|
|
2
2
|
from typing import Any, AsyncContextManager, AsyncGenerator, Protocol
|
|
3
3
|
|
|
4
4
|
import aio_pika
|
|
5
|
+
from aio_pika.abc import AbstractConnection
|
|
5
6
|
from pydantic import BaseModel
|
|
6
7
|
|
|
7
8
|
from jararaca.messagebus.publisher import MessagePublisher, provide_message_publisher
|
|
@@ -25,6 +26,10 @@ class MessageBusPublisherInterceptor(AppInterceptor):
|
|
|
25
26
|
|
|
26
27
|
@asynccontextmanager
|
|
27
28
|
async def intercept(self, app_context: AppContext) -> AsyncGenerator[None, None]:
|
|
29
|
+
if app_context.context_type == "websocket":
|
|
30
|
+
yield
|
|
31
|
+
return
|
|
32
|
+
|
|
28
33
|
async with self.connection_factory.provide_connection() as connection:
|
|
29
34
|
with provide_message_publisher(self.connection_name, connection):
|
|
30
35
|
yield
|
|
@@ -48,29 +53,79 @@ class AIOPikaMessagePublisher(MessagePublisher):
|
|
|
48
53
|
)
|
|
49
54
|
|
|
50
55
|
|
|
56
|
+
class GenericPoolConfig(BaseModel):
|
|
57
|
+
max_size: int
|
|
58
|
+
|
|
59
|
+
|
|
51
60
|
class AIOPikaConnectionFactory(MessageBusConnectionFactory):
|
|
52
61
|
|
|
53
62
|
def __init__(
|
|
54
63
|
self,
|
|
55
64
|
url: str,
|
|
56
65
|
exchange: str,
|
|
66
|
+
connection_pool_config: GenericPoolConfig | None = None,
|
|
67
|
+
channel_pool_config: GenericPoolConfig | None = None,
|
|
57
68
|
):
|
|
58
69
|
self.url = url
|
|
59
70
|
self.exchange = exchange
|
|
60
71
|
|
|
72
|
+
self.connection_pool: aio_pika.pool.Pool[AbstractConnection] | None = None
|
|
73
|
+
self.channel_pool: aio_pika.pool.Pool[aio_pika.abc.AbstractChannel] | None = (
|
|
74
|
+
None
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if connection_pool_config:
|
|
78
|
+
|
|
79
|
+
async def get_connection() -> AbstractConnection:
|
|
80
|
+
return await aio_pika.connect_robust(self.url)
|
|
81
|
+
|
|
82
|
+
self.connection_pool = aio_pika.pool.Pool[AbstractConnection](
|
|
83
|
+
get_connection,
|
|
84
|
+
max_size=connection_pool_config.max_size,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
if channel_pool_config:
|
|
88
|
+
|
|
89
|
+
async def get_channel() -> aio_pika.abc.AbstractChannel:
|
|
90
|
+
async with self.acquire_connection() as connection:
|
|
91
|
+
return await connection.channel(publisher_confirms=False)
|
|
92
|
+
|
|
93
|
+
self.channel_pool = aio_pika.pool.Pool[aio_pika.abc.AbstractChannel](
|
|
94
|
+
get_channel, max_size=channel_pool_config.max_size
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
@asynccontextmanager
|
|
98
|
+
async def acquire_connection(self) -> AsyncGenerator[AbstractConnection, Any]:
|
|
99
|
+
if not self.connection_pool:
|
|
100
|
+
async with await aio_pika.connect_robust(self.url) as connection:
|
|
101
|
+
yield connection
|
|
102
|
+
else:
|
|
103
|
+
|
|
104
|
+
async with self.connection_pool.acquire() as connection:
|
|
105
|
+
yield connection
|
|
106
|
+
|
|
107
|
+
@asynccontextmanager
|
|
108
|
+
async def acquire_channel(
|
|
109
|
+
self,
|
|
110
|
+
) -> AsyncGenerator[aio_pika.abc.AbstractChannel, Any]:
|
|
111
|
+
if not self.channel_pool:
|
|
112
|
+
async with self.acquire_connection() as connection:
|
|
113
|
+
yield await connection.channel(publisher_confirms=False)
|
|
114
|
+
else:
|
|
115
|
+
async with self.channel_pool.acquire() as channel:
|
|
116
|
+
yield channel
|
|
117
|
+
|
|
61
118
|
@asynccontextmanager
|
|
62
119
|
async def provide_connection(self) -> AsyncGenerator[AIOPikaMessagePublisher, Any]:
|
|
63
|
-
connection = await aio_pika.connect_robust(self.url)
|
|
64
|
-
async with connection:
|
|
65
|
-
async with connection.channel(publisher_confirms=False) as channel:
|
|
66
120
|
|
|
67
|
-
|
|
121
|
+
async with self.acquire_channel() as channel:
|
|
122
|
+
tx = channel.transaction()
|
|
68
123
|
|
|
69
|
-
|
|
124
|
+
await tx.select()
|
|
70
125
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
126
|
+
try:
|
|
127
|
+
yield AIOPikaMessagePublisher(channel, exchange_name=self.exchange)
|
|
128
|
+
await tx.commit()
|
|
129
|
+
except Exception as e:
|
|
130
|
+
await tx.rollback()
|
|
131
|
+
raise e
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
2
2
|
README.md,sha256=mte30I-ZEJJp-Oax-OganNgl6G9GaCZPL6JVFAvZGz4,7034
|
|
3
|
-
pyproject.toml,sha256=
|
|
4
|
-
jararaca/__init__.py,sha256=
|
|
3
|
+
pyproject.toml,sha256=6qmtrXrdw7bJZOL_-RGgWJtkCmz7b42Xbc-NwubeGTQ,1840
|
|
4
|
+
jararaca/__init__.py,sha256=VBrN25GHJ3gDG95CcJWe3dmGcA-X2agzOCIBbjzc1Iw,15312
|
|
5
5
|
jararaca/__main__.py,sha256=-O3vsB5lHdqNFjUtoELDF81IYFtR-DSiiFMzRaiSsv4,67
|
|
6
6
|
jararaca/cli.py,sha256=JKk4xrRbtX2fM8yYw794lbxvJFH73bWw3GGIvrpAkeE,5706
|
|
7
7
|
jararaca/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -15,7 +15,7 @@ jararaca/messagebus/__init__.py,sha256=Zdl74HcS9K0FW6XUt7bVvaHEyxL8pWsqqakeRENIn
|
|
|
15
15
|
jararaca/messagebus/bus_message_controller.py,sha256=Xd_qwnX5jUvgBTCarHR36fvtol9lPTsYp2IIGKyQQaE,1487
|
|
16
16
|
jararaca/messagebus/decorators.py,sha256=GHlaXRuHtrz6R0HgcG2gJybpGYtdts9meDVSRPwN74I,4245
|
|
17
17
|
jararaca/messagebus/interceptors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
-
jararaca/messagebus/interceptors/aiopika_publisher_interceptor.py,sha256=
|
|
18
|
+
jararaca/messagebus/interceptors/aiopika_publisher_interceptor.py,sha256=BPH5wOlj_CyHtJ7W4NWF2h0gYMwzOPNzFhGADk618N4,4373
|
|
19
19
|
jararaca/messagebus/publisher.py,sha256=5ay9Znwybqt981OOykdWkFisSvGiTeTpPXDFLMnaiqg,1109
|
|
20
20
|
jararaca/messagebus/types.py,sha256=iYLyLxWqOHkDadxyMqQPWy3itLNQfvD6oQe8jcq9nzo,887
|
|
21
21
|
jararaca/messagebus/worker.py,sha256=hKACTyrIMHcuaySpmI3UhDCja6va1gGkFRoZJ7kYfoA,13613
|
|
@@ -59,8 +59,8 @@ jararaca/tools/app_config/decorators.py,sha256=-ckkMZ1dswOmECdo1rFrZ15UAku--txaN
|
|
|
59
59
|
jararaca/tools/app_config/interceptor.py,sha256=nfFZiS80hrbnL7-XEYrwmp2rwaVYBqxvqu3Y-6o_ov4,2575
|
|
60
60
|
jararaca/tools/metadata.py,sha256=7nlCDYgItNybentPSSCc2MLqN7IpBd0VyQzfjfQycVI,1402
|
|
61
61
|
jararaca/tools/typescript/interface_parser.py,sha256=4SHt094P-QawMFHSyMCiujQf8Niw7xACIO1RHBM8-w4,29192
|
|
62
|
-
jararaca-0.2.
|
|
63
|
-
jararaca-0.2.
|
|
64
|
-
jararaca-0.2.
|
|
65
|
-
jararaca-0.2.
|
|
66
|
-
jararaca-0.2.
|
|
62
|
+
jararaca-0.2.37a11.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
63
|
+
jararaca-0.2.37a11.dist-info/METADATA,sha256=o0sSsRaTx6-ySotULbIhDQtza302CTjxCc9jdAJxbJ8,8555
|
|
64
|
+
jararaca-0.2.37a11.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
65
|
+
jararaca-0.2.37a11.dist-info/entry_points.txt,sha256=WIh3aIvz8LwUJZIDfs4EeH3VoFyCGEk7cWJurW38q0I,45
|
|
66
|
+
jararaca-0.2.37a11.dist-info/RECORD,,
|
pyproject.toml
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|