stompman 2.2.0__tar.gz → 3.1.0__tar.gz
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.
- {stompman-2.2.0 → stompman-3.1.0}/PKG-INFO +3 -3
- {stompman-2.2.0 → stompman-3.1.0}/stompman/client.py +16 -14
- {stompman-2.2.0 → stompman-3.1.0}/stompman/config.py +3 -4
- {stompman-2.2.0 → stompman-3.1.0}/stompman/connection.py +2 -8
- {stompman-2.2.0 → stompman-3.1.0}/stompman/connection_manager.py +0 -2
- {stompman-2.2.0 → stompman-3.1.0}/stompman/serde.py +1 -1
- {stompman-2.2.0 → stompman-3.1.0}/stompman/subscription.py +1 -1
- {stompman-2.2.0 → stompman-3.1.0}/.gitignore +0 -0
- {stompman-2.2.0 → stompman-3.1.0}/pyproject.toml +0 -0
- {stompman-2.2.0 → stompman-3.1.0}/stompman/__init__.py +0 -0
- {stompman-2.2.0 → stompman-3.1.0}/stompman/connection_lifespan.py +0 -0
- {stompman-2.2.0 → stompman-3.1.0}/stompman/errors.py +0 -0
- {stompman-2.2.0 → stompman-3.1.0}/stompman/frames.py +0 -0
- {stompman-2.2.0 → stompman-3.1.0}/stompman/py.typed +0 -0
- {stompman-2.2.0 → stompman-3.1.0}/stompman/transaction.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stompman
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.1.0
|
|
4
4
|
Summary: Python STOMP client with pleasant API
|
|
5
5
|
Project-URL: repository, https://github.com/community-of-python/stompman
|
|
6
6
|
Author-email: Lev Vereshchagin <mail@vrslev.com>
|
|
@@ -54,9 +54,9 @@ async with stompman.Client(
|
|
|
54
54
|
connect_timeout=2,
|
|
55
55
|
connection_confirmation_timeout=2,
|
|
56
56
|
disconnect_confirmation_timeout=2,
|
|
57
|
-
read_timeout=2,
|
|
58
57
|
write_retry_attempts=3,
|
|
59
58
|
check_server_alive_interval_factor=3,
|
|
59
|
+
max_concurrent_consumed_messages=10,
|
|
60
60
|
) as client:
|
|
61
61
|
...
|
|
62
62
|
```
|
|
@@ -160,7 +160,7 @@ Also, I want to pointed out that:
|
|
|
160
160
|
|
|
161
161
|
- Protocol parsing is inspired by [aiostomp](https://github.com/pedrokiefer/aiostomp/blob/3449dcb53f43e5956ccc7662bb5b7d76bc6ef36b/aiostomp/protocol.py) (meaning: consumed by me and refactored from).
|
|
162
162
|
- stompman is tested and used with [ActiveMQ Artemis](https://activemq.apache.org/components/artemis/) and [ActiveMQ Classic](https://activemq.apache.org/components/classic/).
|
|
163
|
-
- Caveat: a message sent by a Stomp client is converted into a JMS `TextMessage`/`BytesMessage` based on the `content-length` header (see the docs [here](https://activemq.apache.org/components/classic/documentation/stomp)). In order to send a `TextMessage`, `Client.send` needs to be invoked with `add_content_length` header set to `False`
|
|
163
|
+
- Caveat: a message sent by a Stomp client is converted into a JMS `TextMessage`/`BytesMessage` based on the `content-length` header (see the docs [here](https://activemq.apache.org/components/classic/documentation/stomp)). In order to send a `TextMessage`, `Client.send` needs to be invoked with `add_content_length` header set to `False`
|
|
164
164
|
- Specification says that headers in CONNECT and CONNECTED frames shouldn't be escaped for backwards compatibility. stompman escapes headers in CONNECT frame (outcoming), but does not unescape headers in CONNECTED (outcoming).
|
|
165
165
|
|
|
166
166
|
### FastStream STOMP broker
|
|
@@ -36,22 +36,23 @@ class Client:
|
|
|
36
36
|
connect_retry_attempts: int = 3
|
|
37
37
|
connect_retry_interval: int = 1
|
|
38
38
|
connect_timeout: int = 2
|
|
39
|
-
read_timeout: int = 2
|
|
40
39
|
read_max_chunk_size: int = 1024 * 1024
|
|
41
40
|
write_retry_attempts: int = 3
|
|
42
41
|
connection_confirmation_timeout: int = 2
|
|
43
42
|
disconnect_confirmation_timeout: int = 2
|
|
44
43
|
check_server_alive_interval_factor: int = 3
|
|
45
44
|
"""Client will check if server alive `server heartbeat interval` times `interval factor`"""
|
|
45
|
+
max_concurrent_consumed_messages: int = 10
|
|
46
46
|
|
|
47
47
|
connection_class: type[AbstractConnection] = Connection
|
|
48
48
|
|
|
49
49
|
_connection_manager: ConnectionManager = field(init=False)
|
|
50
|
-
_active_subscriptions: ActiveSubscriptions = field(default_factory=ActiveSubscriptions, init=False)
|
|
50
|
+
_active_subscriptions: ActiveSubscriptions = field(default_factory=ActiveSubscriptions, init=False, repr=False)
|
|
51
51
|
_active_transactions: set[Transaction] = field(default_factory=set, init=False)
|
|
52
52
|
_exit_stack: AsyncExitStack = field(default_factory=AsyncExitStack, init=False)
|
|
53
|
-
_listen_task: asyncio.Task[None] = field(init=False)
|
|
54
|
-
_task_group: asyncio.TaskGroup = field(init=False)
|
|
53
|
+
_listen_task: asyncio.Task[None] = field(init=False, repr=False)
|
|
54
|
+
_task_group: asyncio.TaskGroup = field(init=False, repr=False)
|
|
55
|
+
_message_frame_semaphore: asyncio.Semaphore = field(init=False, repr=False)
|
|
55
56
|
|
|
56
57
|
def __post_init__(self) -> None:
|
|
57
58
|
self._connection_manager = ConnectionManager(
|
|
@@ -69,12 +70,12 @@ class Client:
|
|
|
69
70
|
connect_retry_attempts=self.connect_retry_attempts,
|
|
70
71
|
connect_retry_interval=self.connect_retry_interval,
|
|
71
72
|
connect_timeout=self.connect_timeout,
|
|
72
|
-
read_timeout=self.read_timeout,
|
|
73
73
|
read_max_chunk_size=self.read_max_chunk_size,
|
|
74
74
|
write_retry_attempts=self.write_retry_attempts,
|
|
75
75
|
check_server_alive_interval_factor=self.check_server_alive_interval_factor,
|
|
76
76
|
ssl=self.ssl,
|
|
77
77
|
)
|
|
78
|
+
self._message_frame_semaphore = asyncio.Semaphore(self.max_concurrent_consumed_messages)
|
|
78
79
|
|
|
79
80
|
async def __aenter__(self) -> Self:
|
|
80
81
|
self._task_group = await self._exit_stack.enter_async_context(asyncio.TaskGroup())
|
|
@@ -98,16 +99,17 @@ class Client:
|
|
|
98
99
|
async for frame in self._connection_manager.read_frames_reconnecting():
|
|
99
100
|
match frame:
|
|
100
101
|
case MessageFrame():
|
|
101
|
-
if subscription := self._active_subscriptions.get_by_id(frame.headers["subscription"]):
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
102
|
+
if not (subscription := self._active_subscriptions.get_by_id(frame.headers["subscription"])):
|
|
103
|
+
continue
|
|
104
|
+
await self._message_frame_semaphore.acquire()
|
|
105
|
+
created_task = task_group.create_task(
|
|
106
|
+
subscription._run_handler(frame=frame) # noqa: SLF001
|
|
107
|
+
if isinstance(subscription, AutoAckSubscription)
|
|
108
|
+
else subscription.handler(
|
|
109
|
+
AckableMessageFrame(headers=frame.headers, body=frame.body, _subscription=subscription)
|
|
110
110
|
)
|
|
111
|
+
)
|
|
112
|
+
created_task.add_done_callback(lambda _: self._message_frame_semaphore.release())
|
|
111
113
|
case ErrorFrame():
|
|
112
114
|
if self.on_error_frame:
|
|
113
115
|
self.on_error_frame(frame)
|
|
@@ -36,7 +36,7 @@ class ConnectionParameters:
|
|
|
36
36
|
return unquote(self.passcode)
|
|
37
37
|
|
|
38
38
|
@classmethod
|
|
39
|
-
def from_pydantic_multihost_hosts(cls, hosts: list[MultiHostHostLike]) -> list[Self]:
|
|
39
|
+
def from_pydantic_multihost_hosts(cls, hosts: list[MultiHostHostLike]) -> list[Self]:
|
|
40
40
|
"""Create connection parameters from `pydantic_code.MultiHostUrl.hosts()`.
|
|
41
41
|
|
|
42
42
|
.. code-block:: python
|
|
@@ -76,9 +76,8 @@ class ConnectionParameters:
|
|
|
76
76
|
msg = "password is set, username must be set"
|
|
77
77
|
raise ValueError(msg)
|
|
78
78
|
elif password is None:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
raise ValueError(msg)
|
|
79
|
+
msg = "username is set, password must be set"
|
|
80
|
+
raise ValueError(msg)
|
|
82
81
|
else:
|
|
83
82
|
all_credentials.append((username, password))
|
|
84
83
|
|
|
@@ -24,7 +24,6 @@ class AbstractConnection(Protocol):
|
|
|
24
24
|
port: int,
|
|
25
25
|
timeout: int,
|
|
26
26
|
read_max_chunk_size: int,
|
|
27
|
-
read_timeout: int,
|
|
28
27
|
ssl: Literal[True] | SSLContext | None,
|
|
29
28
|
) -> Self | None: ...
|
|
30
29
|
async def close(self) -> None: ...
|
|
@@ -46,7 +45,6 @@ class Connection(AbstractConnection):
|
|
|
46
45
|
reader: asyncio.StreamReader
|
|
47
46
|
writer: asyncio.StreamWriter
|
|
48
47
|
read_max_chunk_size: int
|
|
49
|
-
read_timeout: int
|
|
50
48
|
ssl: Literal[True] | SSLContext | None
|
|
51
49
|
|
|
52
50
|
@classmethod
|
|
@@ -57,7 +55,6 @@ class Connection(AbstractConnection):
|
|
|
57
55
|
port: int,
|
|
58
56
|
timeout: int,
|
|
59
57
|
read_max_chunk_size: int,
|
|
60
|
-
read_timeout: int,
|
|
61
58
|
ssl: Literal[True] | SSLContext | None,
|
|
62
59
|
) -> Self | None:
|
|
63
60
|
try:
|
|
@@ -69,7 +66,6 @@ class Connection(AbstractConnection):
|
|
|
69
66
|
reader=reader,
|
|
70
67
|
writer=writer,
|
|
71
68
|
read_max_chunk_size=read_max_chunk_size,
|
|
72
|
-
read_timeout=read_timeout,
|
|
73
69
|
ssl=ssl,
|
|
74
70
|
)
|
|
75
71
|
|
|
@@ -99,10 +95,8 @@ class Connection(AbstractConnection):
|
|
|
99
95
|
parser = FrameParser()
|
|
100
96
|
|
|
101
97
|
while True:
|
|
102
|
-
with _reraise_connection_lost(ConnectionError
|
|
103
|
-
raw_frames = await
|
|
104
|
-
self._read_non_empty_bytes(self.read_max_chunk_size), timeout=self.read_timeout
|
|
105
|
-
)
|
|
98
|
+
with _reraise_connection_lost(ConnectionError):
|
|
99
|
+
raw_frames = await self._read_non_empty_bytes(self.read_max_chunk_size)
|
|
106
100
|
self.last_read_time = time.time()
|
|
107
101
|
|
|
108
102
|
for frame in cast("Iterator[AnyServerFrame]", parser.parse_frames_from_chunk(raw_frames)):
|
|
@@ -46,7 +46,6 @@ class ConnectionManager:
|
|
|
46
46
|
connect_retry_interval: int
|
|
47
47
|
connect_timeout: int
|
|
48
48
|
ssl: Literal[True] | SSLContext | None
|
|
49
|
-
read_timeout: int
|
|
50
49
|
read_max_chunk_size: int
|
|
51
50
|
write_retry_attempts: int
|
|
52
51
|
check_server_alive_interval_factor: int
|
|
@@ -113,7 +112,6 @@ class ConnectionManager:
|
|
|
113
112
|
port=server.port,
|
|
114
113
|
timeout=self.connect_timeout,
|
|
115
114
|
read_max_chunk_size=self.read_max_chunk_size,
|
|
116
|
-
read_timeout=self.read_timeout,
|
|
117
115
|
ssl=self.ssl,
|
|
118
116
|
):
|
|
119
117
|
return (connection, server)
|
|
@@ -74,7 +74,7 @@ class BaseSubscription:
|
|
|
74
74
|
)
|
|
75
75
|
|
|
76
76
|
async def _ack(self, frame: MessageFrame) -> None:
|
|
77
|
-
if self._active_subscriptions.contains_by_id(self.id) and (ack_id := frame.headers
|
|
77
|
+
if self._active_subscriptions.contains_by_id(self.id) and (ack_id := frame.headers.get("ack")):
|
|
78
78
|
await self._connection_manager.maybe_write_frame(
|
|
79
79
|
AckFrame(headers={"id": ack_id, "subscription": frame.headers["subscription"]})
|
|
80
80
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|