stompman 0.6.2__tar.gz → 0.6.4__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-0.6.4/.dockerignore +2 -0
- stompman-0.6.4/.github/dependabot.yml +11 -0
- stompman-0.6.4/.github/workflows/publish.yml +24 -0
- stompman-0.6.4/.github/workflows/test.yml +82 -0
- stompman-0.6.4/.gitignore +4 -0
- stompman-0.6.4/Dockerfile +16 -0
- stompman-0.6.4/Justfile +35 -0
- {stompman-0.6.2 → stompman-0.6.4}/PKG-INFO +8 -13
- {stompman-0.6.2 → stompman-0.6.4}/README.md +1 -0
- stompman-0.6.4/docker-compose.yml +20 -0
- {stompman-0.6.2 → stompman-0.6.4}/pyproject.toml +21 -16
- {stompman-0.6.2 → stompman-0.6.4}/stompman/connection.py +11 -10
- {stompman-0.6.2 → stompman-0.6.4}/stompman/errors.py +1 -2
- {stompman-0.6.2 → stompman-0.6.4}/stompman/protocol.py +26 -17
- stompman-0.6.4/testing/__init__.py +0 -0
- stompman-0.6.4/testing/consumer.py +19 -0
- stompman-0.6.4/testing/producer.py +18 -0
- stompman-0.6.4/tests/__init__.py +0 -0
- stompman-0.6.4/tests/conftest.py +12 -0
- stompman-0.6.4/tests/integration.py +40 -0
- stompman-0.6.4/tests/test_client.py +465 -0
- stompman-0.6.4/tests/test_connection.py +171 -0
- stompman-0.6.4/tests/test_errors.py +6 -0
- stompman-0.6.4/tests/test_protocol.py +234 -0
- {stompman-0.6.2 → stompman-0.6.4}/LICENSE +0 -0
- {stompman-0.6.2 → stompman-0.6.4}/stompman/__init__.py +0 -0
- {stompman-0.6.2 → stompman-0.6.4}/stompman/client.py +0 -0
- {stompman-0.6.2 → stompman-0.6.4}/stompman/frames.py +0 -0
- {stompman-0.6.2 → stompman-0.6.4}/stompman/listening_events.py +0 -0
- {stompman-0.6.2 → stompman-0.6.4}/stompman/py.typed +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types:
|
|
6
|
+
- published
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
|
+
with:
|
|
15
|
+
python-version: "3.12"
|
|
16
|
+
- uses: actions/cache@v4
|
|
17
|
+
with:
|
|
18
|
+
path: ~/.cache/uv
|
|
19
|
+
key: publish-${{ hashFiles('pyproject.toml') }}
|
|
20
|
+
- uses: extractions/setup-just@v2
|
|
21
|
+
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
22
|
+
- run: just publish
|
|
23
|
+
env:
|
|
24
|
+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
pull_request:
|
|
9
|
+
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ${{ github.head_ref || github.run_id }}
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
env:
|
|
15
|
+
DEFAULT_PYTHON_VERSION: "3.12"
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
check-types:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
|
|
25
|
+
- uses: actions/cache@v4
|
|
26
|
+
with:
|
|
27
|
+
path: ~/.cache/uv
|
|
28
|
+
key: check-types-${{ hashFiles('pyproject.toml') }}
|
|
29
|
+
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
30
|
+
- uses: extractions/setup-just@v2
|
|
31
|
+
- run: just install check-types
|
|
32
|
+
|
|
33
|
+
lint:
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/checkout@v4
|
|
37
|
+
- uses: actions/setup-python@v5
|
|
38
|
+
with:
|
|
39
|
+
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
|
|
40
|
+
- uses: actions/cache@v4
|
|
41
|
+
with:
|
|
42
|
+
path: ~/.cache/uv
|
|
43
|
+
key: lint-${{ hashFiles('pyproject.toml') }}
|
|
44
|
+
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
45
|
+
- uses: extractions/setup-just@v2
|
|
46
|
+
- run: just install lint
|
|
47
|
+
|
|
48
|
+
test:
|
|
49
|
+
runs-on: ubuntu-latest
|
|
50
|
+
strategy:
|
|
51
|
+
fail-fast: false
|
|
52
|
+
matrix:
|
|
53
|
+
python-version:
|
|
54
|
+
- "3.11"
|
|
55
|
+
- "3.12"
|
|
56
|
+
steps:
|
|
57
|
+
- uses: actions/checkout@v4
|
|
58
|
+
- uses: actions/setup-python@v5
|
|
59
|
+
with:
|
|
60
|
+
python-version: ${{ matrix.python-version }}
|
|
61
|
+
- uses: actions/cache@v4
|
|
62
|
+
with:
|
|
63
|
+
path: ~/.cache/uv
|
|
64
|
+
key: ${{ github.job }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
|
|
65
|
+
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
66
|
+
- uses: extractions/setup-just@v2
|
|
67
|
+
- run: just install test -vv
|
|
68
|
+
|
|
69
|
+
test-integration:
|
|
70
|
+
runs-on: ubuntu-latest
|
|
71
|
+
strategy:
|
|
72
|
+
fail-fast: false
|
|
73
|
+
matrix:
|
|
74
|
+
python-version:
|
|
75
|
+
- "3.11"
|
|
76
|
+
- "3.12"
|
|
77
|
+
steps:
|
|
78
|
+
- uses: actions/checkout@v4
|
|
79
|
+
- uses: extractions/setup-just@v2
|
|
80
|
+
- run: just test-integration
|
|
81
|
+
env:
|
|
82
|
+
PYTHON_VERSION: ${{ matrix.python-version }}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
ARG PYTHON_VERSION
|
|
2
|
+
FROM python:${PYTHON_VERSION}-slim-bullseye
|
|
3
|
+
|
|
4
|
+
# hadolint ignore=DL3013, DL3042
|
|
5
|
+
RUN --mount=type=cache,target=~/.cache/pip pip install uv
|
|
6
|
+
|
|
7
|
+
WORKDIR /app
|
|
8
|
+
|
|
9
|
+
ENV SETUPTOOLS_SCM_PRETEND_VERSION=0
|
|
10
|
+
COPY pyproject.toml README.md ./
|
|
11
|
+
RUN uv lock
|
|
12
|
+
|
|
13
|
+
COPY stompman/__init__.py stompman/__init__.py
|
|
14
|
+
RUN --mount=type=cache,target=~/.cache/uv uv sync
|
|
15
|
+
|
|
16
|
+
COPY . .
|
stompman-0.6.4/Justfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
default: install lint check-types test test-integration
|
|
2
|
+
|
|
3
|
+
install:
|
|
4
|
+
uv -q lock
|
|
5
|
+
uv -q sync
|
|
6
|
+
|
|
7
|
+
test *args:
|
|
8
|
+
uv -q run pytest -- {{args}}
|
|
9
|
+
|
|
10
|
+
lint:
|
|
11
|
+
uv -q run ruff check .
|
|
12
|
+
uv -q run ruff format .
|
|
13
|
+
|
|
14
|
+
check-types:
|
|
15
|
+
uv -q run mypy .
|
|
16
|
+
|
|
17
|
+
run-artemis:
|
|
18
|
+
docker compose up
|
|
19
|
+
|
|
20
|
+
run-consumer:
|
|
21
|
+
uv -q run python testing/consumer.py
|
|
22
|
+
|
|
23
|
+
run-producer:
|
|
24
|
+
uv -q run python testing/producer.py
|
|
25
|
+
|
|
26
|
+
test-integration *args:
|
|
27
|
+
#!/bin/bash
|
|
28
|
+
trap 'echo; docker compose down --remove-orphans' EXIT
|
|
29
|
+
docker compose run --build --rm app .venv/bin/pytest tests/integration.py --no-cov {{args}}
|
|
30
|
+
|
|
31
|
+
publish:
|
|
32
|
+
rm -rf dist/*
|
|
33
|
+
uv tool run --from build python -- -m build --installer uv
|
|
34
|
+
uv tool run twine check dist/*
|
|
35
|
+
uv tool run twine upload dist/* --username __token__ --password $PYPI_TOKEN
|
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: stompman
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.4
|
|
4
4
|
Summary: Python STOMP client with pleasant API
|
|
5
|
-
|
|
5
|
+
Project-URL: repository, https://github.com/vrslev/stompman
|
|
6
|
+
Author-email: Lev Vereshchagin <mail@vrslev.com>
|
|
6
7
|
License: MIT
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Author-email: mail@vrslev.com
|
|
10
|
-
Requires-Python: >=3.11,<4.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: activemq,artemis,jms,messaging,stomp
|
|
11
10
|
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
13
11
|
Classifier: Natural Language :: English
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
17
12
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
13
|
Classifier: Topic :: System :: Networking
|
|
19
14
|
Classifier: Typing :: Typed
|
|
20
|
-
|
|
15
|
+
Requires-Python: >=3.11
|
|
21
16
|
Description-Content-Type: text/markdown
|
|
22
17
|
|
|
23
18
|
# stompman
|
|
@@ -37,6 +32,7 @@ Before you start using stompman, make sure you have it installed:
|
|
|
37
32
|
```sh
|
|
38
33
|
pip install stompman
|
|
39
34
|
poetry add stompman
|
|
35
|
+
uv add stompman
|
|
40
36
|
```
|
|
41
37
|
|
|
42
38
|
Initialize a client:
|
|
@@ -163,4 +159,3 @@ Also, I want to pointed out that:
|
|
|
163
159
|
## No docs
|
|
164
160
|
|
|
165
161
|
I try to keep it simple and easy to understand. May be counter-intuitive for some, but concise high-quality code speaks for itself. There're no comments and little indirection. Read the source if you wish, leave an issue if it's not enough or you want to add or fix something.
|
|
166
|
-
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
services:
|
|
2
|
+
app:
|
|
3
|
+
build:
|
|
4
|
+
context: .
|
|
5
|
+
args:
|
|
6
|
+
PYTHON_VERSION: ${PYTHON_VERSION:-3.12}
|
|
7
|
+
depends_on:
|
|
8
|
+
artemis:
|
|
9
|
+
condition: service_started
|
|
10
|
+
environment:
|
|
11
|
+
ARTEMIS_HOST: artemis
|
|
12
|
+
|
|
13
|
+
artemis:
|
|
14
|
+
image: apache/activemq-artemis:2.34.0-alpine
|
|
15
|
+
environment:
|
|
16
|
+
ARTEMIS_USER: admin
|
|
17
|
+
ARTEMIS_PASSWORD: admin
|
|
18
|
+
ports:
|
|
19
|
+
- 8161:8161
|
|
20
|
+
- 61616:61616
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
[
|
|
1
|
+
[project]
|
|
2
2
|
name = "stompman"
|
|
3
|
-
version = "0.6.2"
|
|
4
3
|
description = "Python STOMP client with pleasant API"
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
authors = [{ name = "Lev Vereshchagin", email = "mail@vrslev.com" }]
|
|
5
|
+
dependencies = []
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
7
|
readme = "README.md"
|
|
8
|
-
|
|
8
|
+
license = { text = "MIT" }
|
|
9
9
|
keywords = ["stomp", "artemis", "activemq", "messaging", "jms"]
|
|
10
10
|
classifiers = [
|
|
11
11
|
"Development Status :: 4 - Beta",
|
|
@@ -14,22 +14,27 @@ classifiers = [
|
|
|
14
14
|
"Topic :: System :: Networking",
|
|
15
15
|
"Typing :: Typed",
|
|
16
16
|
]
|
|
17
|
+
dynamic = ["version"]
|
|
17
18
|
|
|
18
|
-
[
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
[project.urls]
|
|
20
|
+
repository = "https://github.com/vrslev/stompman"
|
|
21
21
|
|
|
22
|
-
[tool.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
pytest-cov
|
|
27
|
-
|
|
22
|
+
[tool.uv]
|
|
23
|
+
dev-dependencies = [
|
|
24
|
+
"anyio~=4.4.0",
|
|
25
|
+
"mypy~=1.10.0",
|
|
26
|
+
"pytest-cov~=5.0.0",
|
|
27
|
+
"pytest~=8.2.2",
|
|
28
|
+
"ruff~=0.4.8",
|
|
29
|
+
"uvloop~=0.19.0",
|
|
30
|
+
]
|
|
28
31
|
|
|
29
32
|
[build-system]
|
|
30
|
-
requires = ["
|
|
31
|
-
build-backend = "
|
|
33
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
34
|
+
build-backend = "hatchling.build"
|
|
32
35
|
|
|
36
|
+
[tool.hatch.version]
|
|
37
|
+
source = "vcs"
|
|
33
38
|
|
|
34
39
|
[tool.mypy]
|
|
35
40
|
python_version = "3.11"
|
|
@@ -83,6 +83,14 @@ class AbstractConnection(Protocol):
|
|
|
83
83
|
return frame
|
|
84
84
|
|
|
85
85
|
|
|
86
|
+
@contextmanager
|
|
87
|
+
def _reraise_connection_lost(*causes: type[Exception]) -> Generator[None, None, None]:
|
|
88
|
+
try:
|
|
89
|
+
yield
|
|
90
|
+
except causes as exception:
|
|
91
|
+
raise ConnectionLostError from exception
|
|
92
|
+
|
|
93
|
+
|
|
86
94
|
@dataclass
|
|
87
95
|
class Connection(AbstractConnection):
|
|
88
96
|
connection_parameters: ConnectionParameters
|
|
@@ -102,16 +110,9 @@ class Connection(AbstractConnection):
|
|
|
102
110
|
return False
|
|
103
111
|
return True
|
|
104
112
|
|
|
105
|
-
@contextmanager
|
|
106
|
-
def _reraise_connection_lost(self, *causes: type[Exception]) -> Generator[None, None, None]:
|
|
107
|
-
try:
|
|
108
|
-
yield
|
|
109
|
-
except causes as exception:
|
|
110
|
-
raise ConnectionLostError(self.read_timeout) from exception
|
|
111
|
-
|
|
112
113
|
async def close(self) -> None:
|
|
113
114
|
self.writer.close()
|
|
114
|
-
with
|
|
115
|
+
with _reraise_connection_lost(ConnectionError):
|
|
115
116
|
await self.writer.wait_closed()
|
|
116
117
|
|
|
117
118
|
def write_heartbeat(self) -> None:
|
|
@@ -119,7 +120,7 @@ class Connection(AbstractConnection):
|
|
|
119
120
|
|
|
120
121
|
async def write_frame(self, frame: AnyClientFrame) -> None:
|
|
121
122
|
self.writer.write(dump_frame(frame))
|
|
122
|
-
with
|
|
123
|
+
with _reraise_connection_lost(ConnectionError):
|
|
123
124
|
await self.writer.drain()
|
|
124
125
|
|
|
125
126
|
async def _read_non_empty_bytes(self) -> bytes:
|
|
@@ -133,7 +134,7 @@ class Connection(AbstractConnection):
|
|
|
133
134
|
parser = Parser()
|
|
134
135
|
|
|
135
136
|
while True:
|
|
136
|
-
with
|
|
137
|
+
with _reraise_connection_lost(ConnectionError, TimeoutError):
|
|
137
138
|
raw_frames = await asyncio.wait_for(self._read_non_empty_bytes(), timeout=self.read_timeout)
|
|
138
139
|
|
|
139
140
|
for frame in cast(Iterator[AnyServerFrame], parser.load_frames(raw_frames)):
|
|
@@ -31,6 +31,13 @@ CARRIAGE = b"\r"
|
|
|
31
31
|
CARRIAGE_NEWLINE_CARRIAGE_NEWLINE = (CARRIAGE, NEWLINE, CARRIAGE, NEWLINE)
|
|
32
32
|
|
|
33
33
|
|
|
34
|
+
def iter_bytes(bytes_: bytes) -> tuple[bytes, ...]:
|
|
35
|
+
return struct.unpack(f"{len(bytes_)!s}c", bytes_)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
VALID_COMMANDS = [list(iter_bytes(command)) for command in COMMANDS_TO_FRAMES]
|
|
39
|
+
|
|
40
|
+
|
|
34
41
|
def dump_header(key: str, value: str) -> bytes:
|
|
35
42
|
escaped_key = "".join(ESCAPE_CHARS.get(char, char) for char in key)
|
|
36
43
|
escaped_value = "".join(ESCAPE_CHARS.get(char, char) for char in value)
|
|
@@ -79,7 +86,7 @@ def parse_headers(buffer: list[bytes]) -> tuple[str, str] | None:
|
|
|
79
86
|
return (b"".join(key_buffer).decode(), b"".join(value_buffer).decode()) if key_parsed else None
|
|
80
87
|
|
|
81
88
|
|
|
82
|
-
def parse_lines_into_frame(lines: deque[list[bytes]]) -> AnyClientFrame | AnyServerFrame
|
|
89
|
+
def parse_lines_into_frame(lines: deque[list[bytes]]) -> AnyClientFrame | AnyServerFrame:
|
|
83
90
|
command = b"".join(lines.popleft())
|
|
84
91
|
headers = {}
|
|
85
92
|
|
|
@@ -89,9 +96,7 @@ def parse_lines_into_frame(lines: deque[list[bytes]]) -> AnyClientFrame | AnySer
|
|
|
89
96
|
headers[header[0]] = header[1]
|
|
90
97
|
body = b"".join(lines.popleft()) if lines else b""
|
|
91
98
|
|
|
92
|
-
|
|
93
|
-
return known_frame_type(headers=cast(Any, headers), body=body)
|
|
94
|
-
return None
|
|
99
|
+
return COMMANDS_TO_FRAMES[command](headers=cast(Any, headers), body=body)
|
|
95
100
|
|
|
96
101
|
|
|
97
102
|
@dataclass
|
|
@@ -101,29 +106,33 @@ class Parser:
|
|
|
101
106
|
_previous_byte: bytes = field(default=b"", init=False)
|
|
102
107
|
_headers_processed: bool = field(default=False, init=False)
|
|
103
108
|
|
|
109
|
+
def _reset(self) -> None:
|
|
110
|
+
self._headers_processed = False
|
|
111
|
+
self._lines.clear()
|
|
112
|
+
self._current_line = []
|
|
113
|
+
|
|
104
114
|
def load_frames(self, raw_frames: bytes) -> Iterator[AnyClientFrame | AnyServerFrame | HeartbeatFrame]:
|
|
105
|
-
buffer = deque(
|
|
115
|
+
buffer = deque(iter_bytes(raw_frames))
|
|
106
116
|
while buffer:
|
|
107
117
|
byte = buffer.popleft()
|
|
108
118
|
|
|
109
|
-
if
|
|
110
|
-
self.
|
|
111
|
-
|
|
112
|
-
yield
|
|
113
|
-
self.
|
|
114
|
-
self._lines.clear()
|
|
115
|
-
self._current_line = []
|
|
119
|
+
if byte == NULL:
|
|
120
|
+
if self._headers_processed:
|
|
121
|
+
self._lines.append(self._current_line)
|
|
122
|
+
yield parse_lines_into_frame(self._lines)
|
|
123
|
+
self._reset()
|
|
116
124
|
|
|
117
125
|
elif not self._headers_processed and byte == NEWLINE:
|
|
118
126
|
if self._current_line or self._lines:
|
|
119
|
-
if not self._current_line: # extra empty line after headers
|
|
120
|
-
self._headers_processed = True
|
|
121
|
-
|
|
122
127
|
if self._previous_byte == b"\r":
|
|
123
128
|
self._current_line.pop()
|
|
129
|
+
self._headers_processed = not self._current_line # extra empty line after headers
|
|
124
130
|
|
|
125
|
-
self._lines
|
|
126
|
-
|
|
131
|
+
if not self._lines and self._current_line not in VALID_COMMANDS:
|
|
132
|
+
self._reset()
|
|
133
|
+
else:
|
|
134
|
+
self._lines.append(self._current_line)
|
|
135
|
+
self._current_line = []
|
|
127
136
|
else:
|
|
128
137
|
yield HeartbeatFrame()
|
|
129
138
|
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
import stompman
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def main() -> None:
|
|
7
|
+
async with (
|
|
8
|
+
stompman.Client(servers=[stompman.ConnectionParameters("0.0.0.0", 61616, "admin", "admin")]) as client, # noqa: S104
|
|
9
|
+
client.subscribe("DLQ"),
|
|
10
|
+
):
|
|
11
|
+
async for event in client.listen():
|
|
12
|
+
print(event) # noqa: T201
|
|
13
|
+
match event:
|
|
14
|
+
case stompman.MessageEvent():
|
|
15
|
+
await event.ack()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
import stompman
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def main() -> None:
|
|
7
|
+
async with (
|
|
8
|
+
stompman.Client(servers=[stompman.ConnectionParameters("0.0.0.0", 61616, "admin", "admin")]) as client, # noqa: S104
|
|
9
|
+
client.enter_transaction() as transaction,
|
|
10
|
+
):
|
|
11
|
+
for _ in range(10):
|
|
12
|
+
await client.send(body=b"hi there!", destination="DLQ", transaction=transaction)
|
|
13
|
+
await asyncio.sleep(3)
|
|
14
|
+
await client.send(body=b"hi there!", destination="DLQ", transaction=transaction)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
if __name__ == "__main__":
|
|
18
|
+
asyncio.run(main())
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@pytest.fixture(
|
|
5
|
+
params=[
|
|
6
|
+
pytest.param(("asyncio", {"use_uvloop": True}), id="asyncio+uvloop"),
|
|
7
|
+
pytest.param(("asyncio", {"use_uvloop": False}), id="asyncio"),
|
|
8
|
+
],
|
|
9
|
+
autouse=True,
|
|
10
|
+
)
|
|
11
|
+
def anyio_backend(request: pytest.FixtureRequest) -> object:
|
|
12
|
+
return request.param
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import os
|
|
3
|
+
from uuid import uuid4
|
|
4
|
+
|
|
5
|
+
import stompman
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
async def test_integration() -> None:
|
|
9
|
+
server = stompman.ConnectionParameters(host=os.environ["ARTEMIS_HOST"], port=61616, login="admin", passcode="admin")
|
|
10
|
+
destination = "DLQ"
|
|
11
|
+
messages = [str(uuid4()).encode() for _ in range(10000)]
|
|
12
|
+
|
|
13
|
+
async def produce() -> None:
|
|
14
|
+
async with producer.enter_transaction() as transaction:
|
|
15
|
+
for message in messages:
|
|
16
|
+
await producer.send(
|
|
17
|
+
body=message, destination=destination, transaction=transaction, headers={"hello": "world"}
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
async def consume() -> None:
|
|
21
|
+
received_messages = []
|
|
22
|
+
|
|
23
|
+
async with asyncio.timeout(5), consumer.subscribe(destination=destination):
|
|
24
|
+
async for event in consumer.listen():
|
|
25
|
+
match event:
|
|
26
|
+
case stompman.MessageEvent(body=body):
|
|
27
|
+
await event.ack()
|
|
28
|
+
received_messages.append(body)
|
|
29
|
+
if len(received_messages) == len(messages):
|
|
30
|
+
break
|
|
31
|
+
|
|
32
|
+
assert sorted(received_messages) == sorted(messages)
|
|
33
|
+
|
|
34
|
+
async with (
|
|
35
|
+
stompman.Client(servers=[server], read_timeout=10, connection_confirmation_timeout=10) as consumer,
|
|
36
|
+
stompman.Client(servers=[server], read_timeout=10, connection_confirmation_timeout=10) as producer,
|
|
37
|
+
asyncio.TaskGroup() as task_group,
|
|
38
|
+
):
|
|
39
|
+
task_group.create_task(consume())
|
|
40
|
+
task_group.create_task(produce())
|