DefStream-RabbitMQ 0.1.1__py3-none-any.whl → 0.1.1.3__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.
@@ -0,0 +1,239 @@
1
+ Metadata-Version: 2.4
2
+ Name: DefStream-RabbitMQ
3
+ Version: 0.1.1.3
4
+ Summary: RabbitMQ broker adapter for DefStream
5
+ Home-page: https://github.com/yong5eon/DefStream-RabbitMQ
6
+ Author: Heo Yongseon
7
+ Project-URL: Source, https://github.com/yong5eon/DefStream-RabbitMQ
8
+ Project-URL: Issues, https://github.com/yong5eon/DefStream-RabbitMQ/issues
9
+ Project-URL: Releases, https://github.com/yong5eon/DefStream-RabbitMQ/releases
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: DefStream>=0.1.0
20
+ Requires-Dist: pika>=1.3.2
21
+ Dynamic: author
22
+ Dynamic: classifier
23
+ Dynamic: description
24
+ Dynamic: description-content-type
25
+ Dynamic: home-page
26
+ Dynamic: license-file
27
+ Dynamic: project-url
28
+ Dynamic: requires-dist
29
+ Dynamic: requires-python
30
+ Dynamic: summary
31
+
32
+ # DefStream-RabbitMQ
33
+
34
+ **한국어** | [English](./README.en.md)
35
+
36
+ DefStream에서 RabbitMQ를 사용할 수 있게 해주는 브로커 어댑터입니다.
37
+ 일반 큐, Exchange 라우팅, 스트림 이력 읽기, 동기 RPC를 제공하며,
38
+ DefStream Worker에 연결해 작업을 스레드·프로세스 풀에서 실행할 수 있습니다.
39
+ 내부 클라이언트로 Pika를 사용합니다.
40
+
41
+ ## 설치
42
+
43
+ Python **3.9 이상**과 접속 가능한 RabbitMQ 서버가 필요합니다.
44
+
45
+ ```shell
46
+ python -m pip install DefStream-RabbitMQ
47
+ ```
48
+
49
+ `DefStream>=0.1.0`과 `pika>=1.3.2`도 함께 설치됩니다.
50
+ 배포 패키지 이름은 `DefStream-RabbitMQ`이고 import 경로는
51
+ `DefStream.Broker.Implements.RabbitMQ`입니다.
52
+
53
+ ## 큐에 보내고 받기
54
+
55
+ 로컬 RabbitMQ의 `guest` 계정을 사용하는 예제입니다.
56
+ 운영에서는 별도 계정과 환경변수·비밀 저장소를 사용하세요.
57
+ 예제는 `defstream.example.rabbitmq` 큐를 만들며 실행 후에도 큐를 유지합니다.
58
+
59
+ ```python
60
+ from DefStream.Broker.Implements.RabbitMQ import Configuration, Connection
61
+
62
+
63
+ connection = Connection(Configuration(
64
+ host='127.0.0.1',
65
+ port=5672,
66
+ username='guest',
67
+ password='guest',
68
+ ))
69
+ try:
70
+ connection.connect()
71
+ connection.create_queue('defstream.example.rabbitmq')
72
+ queue = connection.queue('defstream.example.rabbitmq')
73
+ queue.send({'message': 'Hello, DefStream!'})
74
+ event = queue.pop(timeout=1000)
75
+ if event is not None:
76
+ print(event.body)
77
+ event.ack()
78
+ finally:
79
+ connection.close()
80
+ ```
81
+
82
+ 메시지는 기본 JSON 코덱으로 직렬화됩니다.
83
+ `pop()` 제한 시간은 **밀리초**이며, 양수 제한 시간에 메시지가 없으면 `None`을 반환합니다.
84
+ `None` 또는 `0`은 무기한 대기입니다.
85
+ 처리가 성공하면 `ack()`, 재전달하려면 `nack()`, 거부하려면 `reject()`를 호출하세요.
86
+ 거부한 메시지는 브로커의 dead-letter 설정이 있으면 해당 목적지로, 없으면 폐기됩니다.
87
+
88
+ ## 연결 설정
89
+
90
+ | 옵션 | 의미 |
91
+ | --- | --- |
92
+ | `host`, `port` | RabbitMQ 주소와 AMQP 포트 |
93
+ | `username`, `password` | 인증 정보 |
94
+ | `vhost` | 가상 호스트, 기본값 `/` |
95
+ | `ssl` | TLS 사용 여부, 기본값 `False` |
96
+ | `timeout` | blocked-connection 제한 시간, 밀리초 |
97
+ | `heartbeat` | 현재 구현은 `int(heartbeat * 2 / 1000)`초로 변환하여 Pika에 전달 |
98
+ | `encode`, `decode` | 메시지 코덱, 기본값 JSON |
99
+
100
+ `timeout`은 모든 작업에 대한 전체 실행 제한 시간이 아닙니다.
101
+ 일반 연결의 heartbeat는 애플리케이션 작업·유휴 시간에 맞게 설정하고 처리되도록 관리하세요.
102
+ 연결과 그 리소스는 **소유 스레드에서만 사용**해야 하며, 스레드·프로세스 사이에 공유하지 마세요.
103
+
104
+ ## Worker로 작업 처리하기
105
+
106
+ 다음은 큐와 오류 큐를 준비한 후 작업을 소비하는 실행 파일입니다.
107
+
108
+ ```python
109
+ from signal import SIGINT, signal
110
+
111
+ from DefStream.Broker.Implements.RabbitMQ import (
112
+ Configuration,
113
+ Connection,
114
+ Reject,
115
+ Subscription,
116
+ )
117
+ from DefStream.Worker import Run, ThreadPool, Worker, WorkerSetup, declare
118
+
119
+
120
+ class Add(
121
+ Run,
122
+ parameters=Subscription(
123
+ queue='defstream.example.rabbitmq.add',
124
+ qos=4,
125
+ error='defstream.example.rabbitmq.add.error',
126
+ ),
127
+ on_error=Reject(),
128
+ ):
129
+ def run(
130
+ self,
131
+ a: int,
132
+ b: int,
133
+ ):
134
+ return a + b
135
+
136
+
137
+ class Prepare(WorkerSetup):
138
+ def __call__(
139
+ self,
140
+ worker: Worker,
141
+ ) -> None:
142
+ for task in worker.tasks:
143
+ declare(
144
+ task=task,
145
+ broker=worker.broker,
146
+ )
147
+
148
+
149
+ if __name__ == '__main__':
150
+ worker = Worker(
151
+ Connection(Configuration(
152
+ host='127.0.0.1',
153
+ port=5672,
154
+ username='guest',
155
+ password='guest',
156
+ )),
157
+ ThreadPool(4),
158
+ setups=Prepare(),
159
+ )
160
+ worker.add(Add)
161
+ signal(
162
+ SIGINT,
163
+ lambda *_: worker.stop(),
164
+ )
165
+ worker.run()
166
+ ```
167
+
168
+ 다른 프로세스에서 같은 큐에 `{'a': 10, 'b': 20}`을 보내면 처리됩니다.
169
+ Worker는 실행과 완료 훅이 끝난 뒤 ACK하고, 실패하면 지정한 정책을 적용합니다.
170
+ `on_error`를 생략하면 기본값은 `Requeue()`입니다.
171
+
172
+ `Subscription` 옵션:
173
+
174
+ - `queue`: 작업 큐 이름.
175
+ - `qos`: 이 구독의 미확인 메시지 수 제한. 기본 소비자 값은 1이며, 0은 무제한입니다.
176
+ Worker의 공유 풀 크기와 별개입니다.
177
+ - `error`: `declare()`가 생성하고 연결할 오류 큐 이름. 거부된 메시지의 DLQ입니다.
178
+ - `offset`: RabbitMQ 스트림 구독에 사용할 정수 오프셋.
179
+
180
+ `Subscription` 객체 생성이나 `consumer.subs()`는 큐를 선언하지 않습니다.
181
+ 작업용 `declare()`는 일반 durable 큐와 선택적 DLQ를 준비하며,
182
+ 스트림 큐나 Exchange 바인딩을 자동 생성하지 않습니다.
183
+ 기존 큐의 선언 옵션이 다르면 실패하며 자동 삭제·재생성하지 않습니다.
184
+
185
+ ## 동기 RPC
186
+
187
+ 실행 중인 Worker가 있는 큐에 `call()`을 사용하면 `Run.run()`의 반환값을 받습니다.
188
+ 아래 코드는 앞의 직접 연결 예제에서 `connect()`와 `close()` 사이에 사용하세요.
189
+
190
+ ```python
191
+ result = connection.queue('defstream.example.rabbitmq.add').call(
192
+ {'a': 10, 'b': 20},
193
+ timeout=5,
194
+ )
195
+ print(result)
196
+ ```
197
+
198
+ - `timeout`은 **초** 단위이며 응답이 없으면 `TimeoutError`가 발생합니다.
199
+ 이미 전달된 서버 작업을 취소하거나 전체 연결·정리 시간을 엄격히 제한하는 값은 아닙니다.
200
+ - 각 호출은 전용 연결과 임시 응답 큐를 사용하고 종료 시 정리합니다.
201
+ - 서버가 요청을 거부하면 `DefStream.Broker.RemoteError`가 발생합니다.
202
+ 재큐잉은 최종 오류 응답 없이 재시도할 수 있습니다.
203
+ - 응답 발행과 요청 ACK는 원자적이지 않습니다. RPC에서도 중복 실행에 대비하세요.
204
+
205
+ 공유 `Run` 클래스를 사용하는 애플리케이션은 코어의
206
+ `request(body, task=Add, broker=connection, timeout=5)`도 사용할 수 있습니다.
207
+
208
+ ## Exchange와 스트림
209
+
210
+ - `connection.exchange(name)`은 `send()`와 `call()`을 제공합니다.
211
+ `event=`가 라우팅 키입니다. Exchange와 큐·바인딩을 먼저 선언하세요.
212
+ - Exchange RPC가 여러 큐로 라우팅되면 여러 곳에서 실행될 수 있으며,
213
+ 클라이언트는 첫 일치 응답만 받습니다. 일반 RPC에는 단일 목적지를 사용하세요.
214
+ - `create_exchange()`, `bind_exchange_to_queue()`, `bind_exchange_to_exchange()`로 라우팅을 구성합니다.
215
+ 각각에 대응하는 `delete_...` 또는 `unbind_...` 메서드도 있습니다.
216
+ - `create_stream()`으로 스트림 큐를 만든 뒤 `connection.stream(name)`의
217
+ `send()`와 `read(offset=0, timeout=1000)`을 사용합니다. 읽기 제한 시간은 밀리초입니다.
218
+ 읽은 이벤트는 이터레이터가 다음 단계로 진행될 때 자동 ACK합니다.
219
+ - `delete_queue()`, `delete_stream()`, `delete_exchange()`는 리소스를 삭제하므로
220
+ 애플리케이션 소유 리소스에만 사용하세요.
221
+
222
+ ## 운영 시 주의사항
223
+
224
+ - 최소 한 번(at-least-once) 전달을 전제로 멱등 작업을 작성하세요.
225
+ - 무제한 재큐잉은 영구 오류 메시지의 반복 실행을 만들 수 있습니다. DLQ와 재시도 정책을 설계하세요.
226
+ - 소비자 연결에서 긴 작업을 직접 실행하지 말고 Worker의 풀을 사용하세요.
227
+ - 작업 훅에서 발행하려면 훅이 실행되는 스레드·프로세스 안에 별도 생산자 연결을 만드세요.
228
+ - `worker.stop()`은 처리 중인 작업과 ACK를 기다린 뒤 연결과 풀을 닫습니다.
229
+ 강제 종료 또는 종료 대기 시간 제한은 제공하지 않습니다.
230
+
231
+ ## 더 알아보기
232
+
233
+ - [DefStream 사용 설명서](https://github.com/yong5eon/DefStream#readme): 작업, 풀, 훅, 검증, Inspector, 대시보드·콘솔
234
+ - [큐·Exchange 예제](./sample/Sample.py)
235
+ - [독립 실행 RPC 예제](./sample/Sample.RPC.py)
236
+ - [스트림 예제](./sample/Sample.Stream.py)
237
+ - [릴리즈와 변경 내역](https://github.com/yong5eon/DefStream-RabbitMQ/releases)
238
+
239
+ GNU GPL v3 라이선스를 사용합니다. 자세한 조건은 [LICENSE](./LICENSE)를 확인하세요.
@@ -9,8 +9,8 @@ DefStream/Broker/Implements/RabbitMQ/Serializer.py,sha256=ylwIBJ0blftq2W9usuYvjS
9
9
  DefStream/Broker/Implements/RabbitMQ/Stream.py,sha256=9E7R_bX_kDZ3VIH7hkMpP-Z7zGbJTonU8V6q_KT3YRI,2283
10
10
  DefStream/Broker/Implements/RabbitMQ/Subscription.py,sha256=0ACs8skbn_s9UfricBDf59hT0F6G3ljO4aUrkpLuI9g,1284
11
11
  DefStream/Broker/Implements/RabbitMQ/__init__.py,sha256=Ndt5yNXcgecN1mj0Qv7M32LUFK96WKmSi88wKMB1ZdU,673
12
- defstream_rabbitmq-0.1.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
13
- defstream_rabbitmq-0.1.1.dist-info/METADATA,sha256=aXWKLYLX7ygLs5KI_94b6fKBU5qqL3NC_0Y9ENc1pV0,5569
14
- defstream_rabbitmq-0.1.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
15
- defstream_rabbitmq-0.1.1.dist-info/top_level.txt,sha256=zsnisIu5wHL4b7VM8e9AggG9KTSdUU4morFqpb8YWFs,10
16
- defstream_rabbitmq-0.1.1.dist-info/RECORD,,
12
+ defstream_rabbitmq-0.1.1.3.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
13
+ defstream_rabbitmq-0.1.1.3.dist-info/METADATA,sha256=SRhV3AAy1XwU3uwaI-tFnFMZjqOP1zEmghZorysWznc,9242
14
+ defstream_rabbitmq-0.1.1.3.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
15
+ defstream_rabbitmq-0.1.1.3.dist-info/top_level.txt,sha256=zsnisIu5wHL4b7VM8e9AggG9KTSdUU4morFqpb8YWFs,10
16
+ defstream_rabbitmq-0.1.1.3.dist-info/RECORD,,
@@ -1,143 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: DefStream-RabbitMQ
3
- Version: 0.1.1
4
- Summary: RabbitMQ broker adapter for DefStream
5
- Home-page: https://github.com/yong5eon/DefStream-RabbitMQ
6
- Author: Heo Yongseon
7
- Project-URL: Source, https://github.com/yong5eon/DefStream-RabbitMQ
8
- Project-URL: Issues, https://github.com/yong5eon/DefStream-RabbitMQ/issues
9
- Classifier: Programming Language :: Python :: 3.9
10
- Classifier: Programming Language :: Python :: 3.10
11
- Classifier: Programming Language :: Python :: 3.11
12
- Classifier: Programming Language :: Python :: 3.12
13
- Classifier: Programming Language :: Python :: 3.13
14
- Classifier: Programming Language :: Python :: 3.14
15
- Requires-Python: >=3.9
16
- Description-Content-Type: text/markdown
17
- License-File: LICENSE
18
- Requires-Dist: DefStream>=0.1.0
19
- Requires-Dist: pika>=1.3.2
20
- Dynamic: author
21
- Dynamic: classifier
22
- Dynamic: description
23
- Dynamic: description-content-type
24
- Dynamic: home-page
25
- Dynamic: license-file
26
- Dynamic: project-url
27
- Dynamic: requires-dist
28
- Dynamic: requires-python
29
- Dynamic: summary
30
-
31
- # DefStream-RabbitMQ
32
-
33
- ## CI and PyPI releases
34
-
35
- The `CI` workflow tests PRs targeting `master` and pushes to `master` on Python
36
- 3.9 through 3.14. It builds all three DefStream packages from source, installs
37
- their wheels in a clean environment, and runs this repository's tests with
38
- RabbitMQ 4.1 and Redis 7.4 service containers. The current repository uses the
39
- event commit; sibling repositories use their `master` branches, with resolved
40
- commit IDs recorded in the log. All three GitHub repositories must be accessible.
41
- This bootstrap setup does not require existing PyPI releases and does not
42
- certify compatibility with previously published dependencies.
43
-
44
- On a `master` push, the build uses `major.minor.<github.run_number>` from the
45
- checked-in `VERSION` (for example, `0.1.42`). PR builds retain `VERSION`. No
46
- version commit, PR, or tag is created. Change major/minor to start a new series;
47
- run numbers can have gaps. Check for PyPI version collisions before replacing
48
- or renaming the workflow.
49
-
50
- Only after all six Python checks pass does a separate publish job upload the
51
- exact Python 3.13 build artifacts. A fully published version is skipped on a
52
- rerun; first-attempt collisions, incomplete releases, and unexpected network
53
- errors fail. Active runs are not cancelled; older pending runs may be superseded.
54
-
55
- Configure `PYPI_API_TOKEN` as a repository Actions secret or a secret in the
56
- `pypi` environment. Restrict that environment to `master`; omit approval rules
57
- for fully automatic releases. Protect `master` with required PRs and all six
58
- `Test Python 3.x` checks, not the push-only `Publish PyPI` job. Never commit the
59
- token. Publish the core before this adapter so users can resolve its dependency.
60
-
61
- RabbitMQ broker adapter for DefStream, distributed separately from the core.
62
- Requires Python 3.9 or newer.
63
-
64
- ## Installation
65
-
66
- ```shell
67
- pip install DefStream-RabbitMQ
68
- ```
69
-
70
- This installs `DefStream>=0.1.0` and `pika>=1.3.2`. The distribution name is
71
- `DefStream-RabbitMQ`; the Python import path remains
72
- `DefStream.Broker.Implements.RabbitMQ`.
73
-
74
- ## Usage
75
-
76
- ```python
77
- from DefStream.Broker.Implements.RabbitMQ import (
78
- Configuration,
79
- Connection,
80
- )
81
-
82
- broker = Connection(Configuration(
83
- host='127.0.0.1',
84
- port=5672,
85
- username='guest',
86
- password='guest',
87
- ))
88
- broker.connect()
89
- try:
90
- broker.create_queue('tasks')
91
- broker.queue('tasks').send({'message': 'hello'})
92
- finally:
93
- broker.close()
94
- ```
95
-
96
- A reachable RabbitMQ server is required. Use connections and their resources
97
- on the thread that owns them.
98
-
99
- The adapter provides queues, exchanges, streams, subscriptions, error policies,
100
- and synchronous queue/exchange RPC. Use its `Connection` with
101
- `DefStream.Worker.Worker` for worker execution.
102
-
103
- ## Source layout
104
-
105
- The contents of the former `DefStream/src/Broker/Implements/RabbitMQ` directory
106
- now live directly in this project's [src](./src) directory. Packaging maps that
107
- directory to `DefStream.Broker.Implements.RabbitMQ`; this distribution does not
108
- own or overwrite the parent packages supplied by DefStream.
109
-
110
- ## Development
111
-
112
- With the core and both adapters checked out as sibling directories, run this
113
- from their common parent using your virtual environment's Python:
114
-
115
- ```powershell
116
- python -m pip install --config-settings editable_mode=strict -e .\DefStream
117
- python -m pip install -e .\DefStream-RabbitMQ -e .\DefStream-Redis
118
- python -m unittest discover -s .\DefStream-RabbitMQ\test -p "test_*.py"
119
- ```
120
-
121
- The core uses strict editable mode to prevent the adapters' editable namespace
122
- entries from masking its packages. Keep the core's generated `build` link tree;
123
- reinstall the core after adding or removing its modules. Adapters use default
124
- editable mode.
125
-
126
- RabbitMQ-specific tests live in this project's `test` directory, covering
127
- resource methods, subscriptions, consumers, RPC, and broker integration.
128
- Broker examples live in `sample`. Shared Worker, Inspector, and cross-adapter
129
- contract tests remain in the DefStream repository and require both adapters.
130
-
131
- Run `python -m unittest discover -s test -p "test_*.py"` from this project
132
- directory after installation. Integration tests are opt-in via
133
- `DEFSTREAM_RABBITMQ_TESTS=1`; ordinary unit tests do not require a running broker
134
- or the Redis adapter.
135
-
136
- Do not combine editable installs with a `site-packages/DefStream` link pointing
137
- directly at the core source: installing adapter files through that link can
138
- write into the core checkout. Remove such a link before installing the projects.
139
- Reinstall after changing package metadata or dependencies.
140
-
141
- ## License
142
-
143
- See [LICENSE](./LICENSE), copied unchanged from DefStream.