stompman 2.0.0__tar.gz → 2.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.
@@ -3,3 +3,5 @@
3
3
  .venv
4
4
  dist
5
5
  uv.lock
6
+ .vscode
7
+ __pycache__
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stompman
3
- Version: 2.0.0
3
+ Version: 2.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>
@@ -160,6 +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
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).
164
165
 
165
166
  ### FastStream STOMP broker
@@ -115,11 +115,22 @@ class Client:
115
115
  pass
116
116
 
117
117
  async def send(
118
- self, body: bytes, destination: str, *, content_type: str | None = None, headers: dict[str, str] | None = None
118
+ self,
119
+ body: bytes,
120
+ destination: str,
121
+ *,
122
+ content_type: str | None = None,
123
+ add_content_length: bool = True,
124
+ headers: dict[str, str] | None = None,
119
125
  ) -> None:
120
126
  await self._connection_manager.write_frame_reconnecting(
121
127
  SendFrame.build(
122
- body=body, destination=destination, transaction=None, content_type=content_type, headers=headers
128
+ body=body,
129
+ destination=destination,
130
+ transaction=None,
131
+ content_type=content_type,
132
+ add_content_length=add_content_length,
133
+ headers=headers,
123
134
  )
124
135
  )
125
136
 
@@ -175,4 +186,4 @@ class Client:
175
186
  def is_alive(self) -> bool:
176
187
  return (
177
188
  self._connection_manager._active_connection_state or False # noqa: SLF001
178
- ) and self._connection_manager._active_connection_state.is_alive() # noqa: SLF001
189
+ ) and self._connection_manager._active_connection_state.is_alive(self.check_server_alive_interval_factor) # noqa: SLF001
@@ -28,10 +28,13 @@ class ActiveConnectionState:
28
28
  lifespan: "AbstractConnectionLifespan"
29
29
  server_heartbeat: Heartbeat
30
30
 
31
- def is_alive(self) -> bool:
31
+ def is_alive(self, check_server_alive_interval_factor: int) -> bool:
32
32
  if not (last_read_time := self.connection.last_read_time):
33
33
  return True
34
- return (self.server_heartbeat.will_send_interval_ms / 1000) > (time.time() - last_read_time)
34
+
35
+ return (self.server_heartbeat.will_send_interval_ms / 1000 * check_server_alive_interval_factor) > (
36
+ time.time() - last_read_time
37
+ )
35
38
 
36
39
 
37
40
  @dataclass(kw_only=True, slots=True)
@@ -99,7 +102,7 @@ class ConnectionManager:
99
102
  await asyncio.sleep(receive_heartbeat_interval_seconds * self.check_server_alive_interval_factor)
100
103
  if not self._active_connection_state:
101
104
  continue
102
- if not self._active_connection_state.is_alive():
105
+ if not self._active_connection_state.is_alive(self.check_server_alive_interval_factor):
103
106
  self._active_connection_state = None
104
107
 
105
108
  async def _create_connection_to_one_server(
@@ -149,11 +149,13 @@ class SendFrame:
149
149
  destination: str,
150
150
  transaction: str | None,
151
151
  content_type: str | None,
152
+ add_content_length: bool,
152
153
  headers: dict[str, str] | None,
153
154
  ) -> Self:
154
155
  all_headers: SendHeaders = headers or {} # type: ignore[assignment]
155
156
  all_headers["destination"] = destination
156
- all_headers["content-length"] = str(len(body))
157
+ if add_content_length:
158
+ all_headers["content-length"] = str(len(body))
157
159
  if content_type is not None:
158
160
  all_headers["content-type"] = content_type
159
161
  if transaction is not None:
@@ -71,7 +71,6 @@ COMMANDS_TO_FRAMES: Final[dict[bytes, type[AnyClientFrame | AnyServerFrame]]] =
71
71
  }
72
72
  FRAMES_TO_COMMANDS: Final = {value: key for key, value in COMMANDS_TO_FRAMES.items()}
73
73
  FRAMES_WITH_BODY: Final = (SendFrame, MessageFrame, ErrorFrame)
74
- COMMANDS_BYTES_LISTS: Final = [list(iter_bytes(command)) for command in COMMANDS_TO_FRAMES]
75
74
 
76
75
 
77
76
  def dump_header(key: str, value: str) -> bytes:
@@ -34,10 +34,21 @@ class Transaction:
34
34
  self._active_transactions.remove(self)
35
35
 
36
36
  async def send(
37
- self, body: bytes, destination: str, *, content_type: str | None = None, headers: dict[str, str] | None = None
37
+ self,
38
+ body: bytes,
39
+ destination: str,
40
+ *,
41
+ content_type: str | None = None,
42
+ add_content_length: bool = True,
43
+ headers: dict[str, str] | None = None,
38
44
  ) -> None:
39
45
  frame = SendFrame.build(
40
- body=body, destination=destination, transaction=self.id, content_type=content_type, headers=headers
46
+ body=body,
47
+ destination=destination,
48
+ transaction=self.id,
49
+ content_type=content_type,
50
+ add_content_length=add_content_length,
51
+ headers=headers,
41
52
  )
42
53
  self.sent_frames.append(frame)
43
54
  await self._connection_manager.write_frame_reconnecting(frame)
File without changes
File without changes
File without changes
File without changes
File without changes