Skip to content

Commit 543e806

Browse files
authored
Implement reconnects on writing and reading frames (#45)
1 parent 95f2990 commit 543e806

19 files changed

+1361
-1010
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,3 @@ updates:
99
directory: /
1010
schedule:
1111
interval: monthly
12-
13-
- package-ecosystem: docker
14-
directory: /
15-
schedule:
16-
interval: monthly

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
ARG PYTHON_VERSION
2-
FROM ghcr.io/astral-sh/uv:0.2.31 as uv
32
FROM python:${PYTHON_VERSION}-slim-bullseye
43

4+
# hadolint ignore=DL3013,DL3042
5+
RUN pip install uv
6+
57
WORKDIR /app
68
COPY pyproject.toml README.md ./
79
COPY stompman/__init__.py stompman/__init__.py
810

911
ENV SETUPTOOLS_SCM_PRETEND_VERSION=0
10-
RUN --mount=from=uv,source=/uv,target=/bin/uv \
11-
--mount=type=cache,target=~/.cache/uv \
12+
RUN --mount=type=cache,target=~/.cache/uv \
1213
uv lock && uv sync
1314
COPY . .

README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,9 @@ stompman takes care of cleaning up resources automatically. When you leave the c
105105

106106
### Handling Connectivity Issues
107107

108-
- If multiple servers were provided, stompman will attempt to connect to each one simultaneously and will use the first that succeeds.
108+
- If multiple servers were provided, stompman will attempt to connect to each one simultaneously and will use the first that succeeds. If all servers fail to connect, an `stompman.FailedAllConnectAttemptsError` will be raised. In normal situation it doesn't need to be handled: tune retry and timeout parameters in `stompman.Client()` to your needs.
109109

110-
- If all servers fail to connect, an `stompman.FailedAllConnectAttemptsError` will be raised. In normal situation it doesn't need to be handled: tune retry and timeout parameters in `stompman.Client()` to your needs.
111-
112-
- If a connection is lost, a `stompman.ConnectionLostError` will be raised. You should implement reconnect logic manually, for example, with stamina:
113-
114-
```python
115-
for attempt in stamina.retry_context(on=stompman.ConnectionLostError):
116-
with attempt:
117-
async with stompman.Client(...) as client:
118-
...
119-
```
110+
- When connection is lost, stompman will handle it automatically. `stompman.FailedAllConnectAttemptsError` will be raised if all connection attempts fail. `stompman.RepeatedConnectionLostError` will be raised if connection succeeds but operation (like sending a frame) leads to connection getting lost.
120111

121112
### ...and caveats
122113

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ignore = ["D1", "D203", "D213", "COM812", "ISC001", "CPY001"]
5858
extend-per-file-ignores = { "tests/*" = ["S101", "SLF001", "ARG"] }
5959

6060
[tool.pytest.ini_options]
61-
addopts = "--cov -s"
61+
addopts = "--cov -s -vv"
6262

6363
[tool.coverage.report]
6464
skip_covered = true

stompman/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
from stompman.client import Client, ConnectionParameters, Heartbeat, Subscription, Transaction
1+
from stompman.client import Client, Subscription, Transaction
2+
from stompman.config import ConnectionParameters, Heartbeat
23
from stompman.connection import AbstractConnection, Connection
4+
from stompman.connection_manager import ActiveConnectionState, ConnectionManager
35
from stompman.errors import (
46
ConnectionConfirmationTimeoutError,
57
ConnectionLostError,
68
Error,
79
FailedAllConnectAttemptsError,
10+
RepeatedConnectionLostError,
811
UnsupportedProtocolVersionError,
912
)
1013
from stompman.frames import (
1114
AbortFrame,
1215
AckFrame,
16+
AckMode,
1317
AnyClientFrame,
1418
AnyRealServerFrame,
1519
AnyServerFrame,
@@ -32,6 +36,8 @@
3236
"AbortFrame",
3337
"AbstractConnection",
3438
"AckFrame",
39+
"AckMode",
40+
"ActiveConnectionState",
3541
"AnyClientFrame",
3642
"AnyRealServerFrame",
3743
"AnyServerFrame",
@@ -43,6 +49,7 @@
4349
"Connection",
4450
"ConnectionConfirmationTimeoutError",
4551
"ConnectionLostError",
52+
"ConnectionManager",
4653
"ConnectionParameters",
4754
"DisconnectFrame",
4855
"Error",
@@ -53,6 +60,7 @@
5360
"MessageFrame",
5461
"NackFrame",
5562
"ReceiptFrame",
63+
"RepeatedConnectionLostError",
5664
"SendFrame",
5765
"SubscribeFrame",
5866
"Subscription",

0 commit comments

Comments
 (0)