vs-queue 0.1.1__tar.gz → 0.1.3__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.
- vs_queue-0.1.3/LICENSE.txt +181 -0
- {vs_queue-0.1.1/vs_queue.egg-info → vs_queue-0.1.3}/PKG-INFO +248 -14
- vs_queue-0.1.1/PKG-INFO → vs_queue-0.1.3/README.md +63 -44
- {vs_queue-0.1.1 → vs_queue-0.1.3}/pyproject.toml +2 -2
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/__init__.py +3 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/base/vs_base_consumer.py +2 -2
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/base/vs_base_queue.py +10 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/factory/vs_queue_factory.py +6 -1
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/provider/vs_rabbitmq_queue.py +15 -2
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/provider/vs_redis_queue.py +23 -1
- vs_queue-0.1.3/vs_queue/schema/__init__.py +0 -0
- vs_queue-0.1.3/vs_queue/schema/vs_retention.py +8 -0
- vs_queue-0.1.1/README.md → vs_queue-0.1.3/vs_queue.egg-info/PKG-INFO +278 -13
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue.egg-info/SOURCES.txt +4 -1
- {vs_queue-0.1.1 → vs_queue-0.1.3}/setup.cfg +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/base/__init__.py +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/decorator/__init__.py +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/decorator/vs_queue_listener.py +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/factory/__init__.py +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/manager/__init__.py +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/manager/vs_queue_manager.py +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/provider/__init__.py +0 -0
- /vs_queue-0.1.1/vs_queue/registry/__init__.py → /vs_queue-0.1.3/vs_queue/py.typed +0 -0
- {vs_queue-0.1.1/vs_queue/retry → vs_queue-0.1.3/vs_queue/registry}/__init__.py +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/registry/vs_queue_registry.py +0 -0
- {vs_queue-0.1.1/vs_queue/schema → vs_queue-0.1.3/vs_queue/retry}/__init__.py +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/retry/vs_retry_policy.py +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue/schema/vs_message.py +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue.egg-info/dependency_links.txt +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue.egg-info/requires.txt +0 -0
- {vs_queue-0.1.1 → vs_queue-0.1.3}/vs_queue.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and derivative works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and incorporated
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or
|
|
82
|
+
contributory patent infringement, then any patent licenses granted to
|
|
83
|
+
You under this License for that Work shall terminate as of the date
|
|
84
|
+
such litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" file as part of its distribution,
|
|
104
|
+
You must include a readable copy of the attribution notices
|
|
105
|
+
contained within such NOTICE file, in at least one of the
|
|
106
|
+
following places: within a NOTICE text file distributed as part
|
|
107
|
+
of the Derivative Works; within the Source form or documentation,
|
|
108
|
+
if provided along with the Derivative Works; or, within a display
|
|
109
|
+
generated by the Derivative Works, if and wherever such
|
|
110
|
+
third-party notices normally appear. The contents of the NOTICE
|
|
111
|
+
file are for informational purposes only and do not modify the
|
|
112
|
+
License. You may add Your own attribution notices within
|
|
113
|
+
Derivative Works that You distribute, alongside or as an addendum
|
|
114
|
+
to the NOTICE text from the Work, provided that such additional
|
|
115
|
+
attribution notices cannot be construed as modifying the License.
|
|
116
|
+
|
|
117
|
+
You may add Your own license statement for Your modifications and
|
|
118
|
+
may provide additional grant of rights to use, modify, and distribute
|
|
119
|
+
Your modifications.
|
|
120
|
+
|
|
121
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
122
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
123
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
124
|
+
this License, without any additional terms or conditions.
|
|
125
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
126
|
+
the terms of any separate license agreement you may have executed
|
|
127
|
+
with Licensor regarding such Contributions.
|
|
128
|
+
|
|
129
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
130
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
131
|
+
except as required for reasonable and customary use in describing the
|
|
132
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
133
|
+
|
|
134
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
135
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
136
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
137
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
138
|
+
implied, including, without limitation, any conditions of TITLE,
|
|
139
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
140
|
+
PURPOSE. You are solely responsible for determining the
|
|
141
|
+
appropriateness of using or reproducing the Work and assume any
|
|
142
|
+
risks associated with Your exercise of permissions under this License.
|
|
143
|
+
|
|
144
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
145
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
146
|
+
unless required by applicable law (such as deliberate and grossly
|
|
147
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
148
|
+
liable to You for damages, including any direct, indirect, special,
|
|
149
|
+
incidental, or exemplary damages of any character arising as a
|
|
150
|
+
result of this License or out of the use or inability to use the
|
|
151
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
152
|
+
work stoppage, computer failure or malfunction, or all other
|
|
153
|
+
commercial damages or losses), even if such Contributor has been
|
|
154
|
+
advised of the possibility of such damages.
|
|
155
|
+
|
|
156
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
157
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
158
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
159
|
+
or other liability obligations and/or rights consistent with this
|
|
160
|
+
License. However, in accepting such obligations, You may act only
|
|
161
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
162
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
163
|
+
defend, and hold each Contributor harmless for any liability
|
|
164
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
165
|
+
of your accepting any such warranty or additional liability.
|
|
166
|
+
|
|
167
|
+
END OF TERMS AND CONDITIONS
|
|
168
|
+
|
|
169
|
+
Copyright 2026 VivekaSutra. All rights reserved.
|
|
170
|
+
|
|
171
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
172
|
+
you may not use this file except in compliance with the License.
|
|
173
|
+
You may obtain a copy of the License at
|
|
174
|
+
|
|
175
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
176
|
+
|
|
177
|
+
Unless required by applicable law or agreed to in writing, software
|
|
178
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
179
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
180
|
+
implied. See the License for the specific language governing
|
|
181
|
+
permissions and limitations under the License.
|
|
@@ -1,7 +1,189 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vs-queue
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Pluggable async message queue library for Viveka Sutra — Redis Streams, RabbitMQ, retry, dead letter, and annotation-based consumers
|
|
5
|
+
License: Apache License
|
|
6
|
+
Version 2.0, January 2004
|
|
7
|
+
http://www.apache.org/licenses/
|
|
8
|
+
|
|
9
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
10
|
+
|
|
11
|
+
1. Definitions.
|
|
12
|
+
|
|
13
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
14
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
15
|
+
|
|
16
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
17
|
+
the copyright owner that is granting the License.
|
|
18
|
+
|
|
19
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
20
|
+
other entities that control, are controlled by, or are under common
|
|
21
|
+
control with that entity. For the purposes of this definition,
|
|
22
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
23
|
+
direction or management of such entity, whether by contract or
|
|
24
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
25
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
26
|
+
|
|
27
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
28
|
+
exercising permissions granted by this License.
|
|
29
|
+
|
|
30
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
31
|
+
including but not limited to software source code, documentation
|
|
32
|
+
source, and configuration files.
|
|
33
|
+
|
|
34
|
+
"Object" form shall mean any form resulting from mechanical
|
|
35
|
+
transformation or translation of a Source form, including but
|
|
36
|
+
not limited to compiled object code, generated documentation,
|
|
37
|
+
and conversions to other media types.
|
|
38
|
+
|
|
39
|
+
"Work" shall mean the work of authorship made available under
|
|
40
|
+
the License, as indicated by a copyright notice that is included in
|
|
41
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and derivative works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
52
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
53
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
54
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
55
|
+
or written communication sent to the Licensor or its representatives,
|
|
56
|
+
including but not limited to communication on electronic mailing lists,
|
|
57
|
+
source code control systems, and issue tracking systems that are managed
|
|
58
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
59
|
+
improving the Work, but excluding communication that is conspicuously
|
|
60
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
61
|
+
Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
64
|
+
whom a Contribution has been received by the Licensor and incorporated
|
|
65
|
+
within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a cross-claim
|
|
84
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
85
|
+
Contribution embodied within the Work constitutes direct or
|
|
86
|
+
contributory patent infringement, then any patent licenses granted to
|
|
87
|
+
You under this License for that Work shall terminate as of the date
|
|
88
|
+
such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
96
|
+
Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" file as part of its distribution,
|
|
108
|
+
You must include a readable copy of the attribution notices
|
|
109
|
+
contained within such NOTICE file, in at least one of the
|
|
110
|
+
following places: within a NOTICE text file distributed as part
|
|
111
|
+
of the Derivative Works; within the Source form or documentation,
|
|
112
|
+
if provided along with the Derivative Works; or, within a display
|
|
113
|
+
generated by the Derivative Works, if and wherever such
|
|
114
|
+
third-party notices normally appear. The contents of the NOTICE
|
|
115
|
+
file are for informational purposes only and do not modify the
|
|
116
|
+
License. You may add Your own attribution notices within
|
|
117
|
+
Derivative Works that You distribute, alongside or as an addendum
|
|
118
|
+
to the NOTICE text from the Work, provided that such additional
|
|
119
|
+
attribution notices cannot be construed as modifying the License.
|
|
120
|
+
|
|
121
|
+
You may add Your own license statement for Your modifications and
|
|
122
|
+
may provide additional grant of rights to use, modify, and distribute
|
|
123
|
+
Your modifications.
|
|
124
|
+
|
|
125
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
126
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
127
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
128
|
+
this License, without any additional terms or conditions.
|
|
129
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
130
|
+
the terms of any separate license agreement you may have executed
|
|
131
|
+
with Licensor regarding such Contributions.
|
|
132
|
+
|
|
133
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
134
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
135
|
+
except as required for reasonable and customary use in describing the
|
|
136
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
137
|
+
|
|
138
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
139
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
140
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
141
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
142
|
+
implied, including, without limitation, any conditions of TITLE,
|
|
143
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
144
|
+
PURPOSE. You are solely responsible for determining the
|
|
145
|
+
appropriateness of using or reproducing the Work and assume any
|
|
146
|
+
risks associated with Your exercise of permissions under this License.
|
|
147
|
+
|
|
148
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
149
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
150
|
+
unless required by applicable law (such as deliberate and grossly
|
|
151
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
152
|
+
liable to You for damages, including any direct, indirect, special,
|
|
153
|
+
incidental, or exemplary damages of any character arising as a
|
|
154
|
+
result of this License or out of the use or inability to use the
|
|
155
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
156
|
+
work stoppage, computer failure or malfunction, or all other
|
|
157
|
+
commercial damages or losses), even if such Contributor has been
|
|
158
|
+
advised of the possibility of such damages.
|
|
159
|
+
|
|
160
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
161
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
162
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
163
|
+
or other liability obligations and/or rights consistent with this
|
|
164
|
+
License. However, in accepting such obligations, You may act only
|
|
165
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
166
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
167
|
+
defend, and hold each Contributor harmless for any liability
|
|
168
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
169
|
+
of your accepting any such warranty or additional liability.
|
|
170
|
+
|
|
171
|
+
END OF TERMS AND CONDITIONS
|
|
172
|
+
|
|
173
|
+
Copyright 2026 VivekaSutra. All rights reserved.
|
|
174
|
+
|
|
175
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
176
|
+
you may not use this file except in compliance with the License.
|
|
177
|
+
You may obtain a copy of the License at
|
|
178
|
+
|
|
179
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
180
|
+
|
|
181
|
+
Unless required by applicable law or agreed to in writing, software
|
|
182
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
183
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
184
|
+
implied. See the License for the specific language governing
|
|
185
|
+
permissions and limitations under the License.
|
|
186
|
+
|
|
5
187
|
Project-URL: Homepage, https://vivekasutra.com/
|
|
6
188
|
Project-URL: Source, https://github.com/vivekasutra/viveka-mula
|
|
7
189
|
Keywords: queue,messaging,redis,rabbitmq,async,consumer,viveka,vs
|
|
@@ -17,6 +199,7 @@ Classifier: Framework :: AsyncIO
|
|
|
17
199
|
Classifier: Typing :: Typed
|
|
18
200
|
Requires-Python: >=3.11
|
|
19
201
|
Description-Content-Type: text/markdown
|
|
202
|
+
License-File: LICENSE.txt
|
|
20
203
|
Requires-Dist: pydantic>=2.0
|
|
21
204
|
Provides-Extra: redis
|
|
22
205
|
Requires-Dist: redis>=5.0; extra == "redis"
|
|
@@ -28,6 +211,7 @@ Requires-Dist: build; extra == "dev"
|
|
|
28
211
|
Requires-Dist: twine; extra == "dev"
|
|
29
212
|
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
30
213
|
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
214
|
+
Dynamic: license-file
|
|
31
215
|
|
|
32
216
|
# vs-queue
|
|
33
217
|
|
|
@@ -304,6 +488,12 @@ Abstract base class for all queue backends. Extend this to implement a custom pr
|
|
|
304
488
|
| `publish(queue, message)` | Publish a `VsMessage` to a named queue |
|
|
305
489
|
| `subscribe(queue, consumer, retry_policy)` | Begin consuming from a queue using a `VsBaseConsumer` |
|
|
306
490
|
|
|
491
|
+
**Concrete method:**
|
|
492
|
+
|
|
493
|
+
| Method | Description |
|
|
494
|
+
|---|---|
|
|
495
|
+
| `set_retention(queue, VsRetention)` | Register a per-queue retention policy. Call before `connect()`. See [Retention](#retention). |
|
|
496
|
+
|
|
307
497
|
---
|
|
308
498
|
|
|
309
499
|
## VsBaseConsumer
|
|
@@ -315,13 +505,13 @@ Abstract base class for all consumers. Extend this and implement `handle` to pro
|
|
|
315
505
|
| Method | Description |
|
|
316
506
|
|---|---|
|
|
317
507
|
| `handle(message)` | Called for every message received. Raise any exception to trigger retry. |
|
|
318
|
-
| `start()` | Called once when the consumer begins. Use for setup. |
|
|
319
|
-
| `stop()` | Called once on graceful shutdown. Use for cleanup. |
|
|
320
508
|
|
|
321
|
-
**Optional override
|
|
509
|
+
**Optional overrides** (concrete no-ops by default — override only if you need them):
|
|
322
510
|
|
|
323
511
|
| Method | Description |
|
|
324
512
|
|---|---|
|
|
513
|
+
| `start()` | Called once when the consumer begins. Use for setup. |
|
|
514
|
+
| `stop()` | Called once on graceful shutdown. Use for cleanup. |
|
|
325
515
|
| `on_error(message, error)` | Called when `handle` raises an exception, before retry logic runs. Use for logging or alerting. |
|
|
326
516
|
|
|
327
517
|
**Example with error hook:**
|
|
@@ -374,9 +564,6 @@ Decorator that registers a `VsBaseConsumer` subclass as a listener. `VsQueueMana
|
|
|
374
564
|
class SimpleConsumer(VsBaseConsumer):
|
|
375
565
|
async def handle(self, message: VsMessage) -> None:
|
|
376
566
|
print(message.payload)
|
|
377
|
-
|
|
378
|
-
async def start(self) -> None: pass
|
|
379
|
-
async def stop(self) -> None: pass
|
|
380
567
|
```
|
|
381
568
|
|
|
382
569
|
**Example — full configuration:**
|
|
@@ -543,9 +730,6 @@ class DlqConsumer(VsBaseConsumer):
|
|
|
543
730
|
f"Message permanently failed | id={message.id} retries={message.retry_count}",
|
|
544
731
|
payload=message.payload,
|
|
545
732
|
)
|
|
546
|
-
|
|
547
|
-
async def start(self) -> None: pass
|
|
548
|
-
async def stop(self) -> None: pass
|
|
549
733
|
```
|
|
550
734
|
|
|
551
735
|
**Example — replaying a DLQ message:**
|
|
@@ -560,6 +744,44 @@ await queue.publish("orchestrator:tasks", dlq_message)
|
|
|
560
744
|
|
|
561
745
|
---
|
|
562
746
|
|
|
747
|
+
## Retention
|
|
748
|
+
|
|
749
|
+
Retention is a property of the queue, not the message — so you register it per queue name, once, before `connect()`. `VsMessage` is unchanged.
|
|
750
|
+
|
|
751
|
+
```python
|
|
752
|
+
from vs_queue.schema.vs_retention import VsRetention
|
|
753
|
+
|
|
754
|
+
# via the factory
|
|
755
|
+
queue = VsQueueFactory.create(
|
|
756
|
+
provider="redis", host="localhost", port=6379,
|
|
757
|
+
retention={
|
|
758
|
+
"vs_trace:logs": VsRetention(ttl_seconds=604800, max_len=100_000),
|
|
759
|
+
},
|
|
760
|
+
)
|
|
761
|
+
|
|
762
|
+
# or directly, any time before the first publish/subscribe to that queue
|
|
763
|
+
queue.set_retention("vs_trace:logs", VsRetention(ttl_seconds=604800))
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
| Field | Meaning |
|
|
767
|
+
|---|---|
|
|
768
|
+
| `ttl_seconds` | Drop messages older than this |
|
|
769
|
+
| `max_len` | Keep at most this many messages |
|
|
770
|
+
|
|
771
|
+
Applied the first time the queue is published to or subscribed. Queues with no policy are unbounded, same as before.
|
|
772
|
+
|
|
773
|
+
**Redis Streams** — no native per-message TTL, so:
|
|
774
|
+
- `max_len` → `XADD ... MAXLEN ~ n` on every publish
|
|
775
|
+
- `ttl_seconds` → throttled `XTRIM <queue> MINID ~ <now - ttl>` (stream IDs are ms timestamps); runs at most once per `ttl/10` seconds per queue, not on every publish
|
|
776
|
+
|
|
777
|
+
**RabbitMQ** — set as queue arguments on declare:
|
|
778
|
+
- `ttl_seconds` → `x-message-ttl`
|
|
779
|
+
- `max_len` → `x-max-length`
|
|
780
|
+
|
|
781
|
+
RabbitMQ rejects redeclaring a live queue with different arguments — the first declare wins. To change a policy, use a new queue name or a broker policy.
|
|
782
|
+
|
|
783
|
+
---
|
|
784
|
+
|
|
563
785
|
## Logging
|
|
564
786
|
|
|
565
787
|
Both backends log consumer lifecycle and per-message activity on the provider logger
|
|
@@ -711,7 +933,7 @@ Creates queue instances from a registered provider name.
|
|
|
711
933
|
|
|
712
934
|
| Method | Signature | Description |
|
|
713
935
|
|---|---|---|
|
|
714
|
-
| `create` | `create(provider, host, port, credentials) -> VsBaseQueue` | Create and return a queue instance. Does not call `connect()`. |
|
|
936
|
+
| `create` | `create(provider, host, port, credentials, retention) -> VsBaseQueue` | Create and return a queue instance. Does not call `connect()`. `retention` is an optional `{queue_name: VsRetention}` map — see [Retention](#retention). |
|
|
715
937
|
|
|
716
938
|
**Example:**
|
|
717
939
|
|
|
@@ -920,6 +1142,18 @@ Abstract base. Extend to implement a custom queue provider.
|
|
|
920
1142
|
| `health_check()` | Returns `True` if broker is reachable |
|
|
921
1143
|
| `publish(queue, message)` | Publish a message |
|
|
922
1144
|
| `subscribe(queue, consumer, retry_policy)` | Start consuming |
|
|
1145
|
+
| `set_retention(queue, VsRetention)` | Register a retention policy for a queue (before `connect()`) |
|
|
1146
|
+
|
|
1147
|
+
---
|
|
1148
|
+
|
|
1149
|
+
### VsRetention
|
|
1150
|
+
|
|
1151
|
+
Per-queue retention policy. See [Retention](#retention).
|
|
1152
|
+
|
|
1153
|
+
| Field | Type | Default | Description |
|
|
1154
|
+
|---|---|---|---|
|
|
1155
|
+
| `ttl_seconds` | `Optional[int]` | `None` | Drop messages older than this |
|
|
1156
|
+
| `max_len` | `Optional[int]` | `None` | Keep at most this many messages |
|
|
923
1157
|
|
|
924
1158
|
---
|
|
925
1159
|
|
|
@@ -938,9 +1172,9 @@ Abstract base. Extend and implement `handle` to process messages.
|
|
|
938
1172
|
| Method | Required | Description |
|
|
939
1173
|
|---|---|---|
|
|
940
1174
|
| `handle(message)` | Yes | Process a message. Raise to trigger retry. |
|
|
941
|
-
| `start()` |
|
|
942
|
-
| `stop()` |
|
|
943
|
-
| `on_error(message, error)` | No | Called on `handle` failure before retry |
|
|
1175
|
+
| `start()` | No — no-op by default | Setup before consuming begins |
|
|
1176
|
+
| `stop()` | No — no-op by default | Cleanup on shutdown — called on graceful cancel |
|
|
1177
|
+
| `on_error(message, error)` | No — no-op by default | Called on `handle` failure before retry |
|
|
944
1178
|
|
|
945
1179
|
---
|
|
946
1180
|
|
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: vs-queue
|
|
3
|
-
Version: 0.1.1
|
|
4
|
-
Summary: Pluggable async message queue library for Viveka Sutra — Redis Streams, RabbitMQ, retry, dead letter, and annotation-based consumers
|
|
5
|
-
Project-URL: Homepage, https://vivekasutra.com/
|
|
6
|
-
Project-URL: Source, https://github.com/vivekasutra/viveka-mula
|
|
7
|
-
Keywords: queue,messaging,redis,rabbitmq,async,consumer,viveka,vs
|
|
8
|
-
Classifier: Development Status :: 3 - Alpha
|
|
9
|
-
Classifier: Intended Audience :: Developers
|
|
10
|
-
Classifier: License :: Other/Proprietary License
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
-
Classifier: Topic :: System :: Distributed Computing
|
|
16
|
-
Classifier: Framework :: AsyncIO
|
|
17
|
-
Classifier: Typing :: Typed
|
|
18
|
-
Requires-Python: >=3.11
|
|
19
|
-
Description-Content-Type: text/markdown
|
|
20
|
-
Requires-Dist: pydantic>=2.0
|
|
21
|
-
Provides-Extra: redis
|
|
22
|
-
Requires-Dist: redis>=5.0; extra == "redis"
|
|
23
|
-
Requires-Dist: hiredis>=2.0; extra == "redis"
|
|
24
|
-
Provides-Extra: rabbitmq
|
|
25
|
-
Requires-Dist: aio-pika>=9.0; extra == "rabbitmq"
|
|
26
|
-
Provides-Extra: dev
|
|
27
|
-
Requires-Dist: build; extra == "dev"
|
|
28
|
-
Requires-Dist: twine; extra == "dev"
|
|
29
|
-
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
30
|
-
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
31
|
-
|
|
32
1
|
# vs-queue
|
|
33
2
|
|
|
34
3
|
Pluggable async message queue library for Viveka Sutra — Redis Streams, RabbitMQ, retry policies, dead letter queues, and annotation-based consumers.
|
|
@@ -304,6 +273,12 @@ Abstract base class for all queue backends. Extend this to implement a custom pr
|
|
|
304
273
|
| `publish(queue, message)` | Publish a `VsMessage` to a named queue |
|
|
305
274
|
| `subscribe(queue, consumer, retry_policy)` | Begin consuming from a queue using a `VsBaseConsumer` |
|
|
306
275
|
|
|
276
|
+
**Concrete method:**
|
|
277
|
+
|
|
278
|
+
| Method | Description |
|
|
279
|
+
|---|---|
|
|
280
|
+
| `set_retention(queue, VsRetention)` | Register a per-queue retention policy. Call before `connect()`. See [Retention](#retention). |
|
|
281
|
+
|
|
307
282
|
---
|
|
308
283
|
|
|
309
284
|
## VsBaseConsumer
|
|
@@ -315,13 +290,13 @@ Abstract base class for all consumers. Extend this and implement `handle` to pro
|
|
|
315
290
|
| Method | Description |
|
|
316
291
|
|---|---|
|
|
317
292
|
| `handle(message)` | Called for every message received. Raise any exception to trigger retry. |
|
|
318
|
-
| `start()` | Called once when the consumer begins. Use for setup. |
|
|
319
|
-
| `stop()` | Called once on graceful shutdown. Use for cleanup. |
|
|
320
293
|
|
|
321
|
-
**Optional override
|
|
294
|
+
**Optional overrides** (concrete no-ops by default — override only if you need them):
|
|
322
295
|
|
|
323
296
|
| Method | Description |
|
|
324
297
|
|---|---|
|
|
298
|
+
| `start()` | Called once when the consumer begins. Use for setup. |
|
|
299
|
+
| `stop()` | Called once on graceful shutdown. Use for cleanup. |
|
|
325
300
|
| `on_error(message, error)` | Called when `handle` raises an exception, before retry logic runs. Use for logging or alerting. |
|
|
326
301
|
|
|
327
302
|
**Example with error hook:**
|
|
@@ -374,9 +349,6 @@ Decorator that registers a `VsBaseConsumer` subclass as a listener. `VsQueueMana
|
|
|
374
349
|
class SimpleConsumer(VsBaseConsumer):
|
|
375
350
|
async def handle(self, message: VsMessage) -> None:
|
|
376
351
|
print(message.payload)
|
|
377
|
-
|
|
378
|
-
async def start(self) -> None: pass
|
|
379
|
-
async def stop(self) -> None: pass
|
|
380
352
|
```
|
|
381
353
|
|
|
382
354
|
**Example — full configuration:**
|
|
@@ -543,9 +515,6 @@ class DlqConsumer(VsBaseConsumer):
|
|
|
543
515
|
f"Message permanently failed | id={message.id} retries={message.retry_count}",
|
|
544
516
|
payload=message.payload,
|
|
545
517
|
)
|
|
546
|
-
|
|
547
|
-
async def start(self) -> None: pass
|
|
548
|
-
async def stop(self) -> None: pass
|
|
549
518
|
```
|
|
550
519
|
|
|
551
520
|
**Example — replaying a DLQ message:**
|
|
@@ -560,6 +529,44 @@ await queue.publish("orchestrator:tasks", dlq_message)
|
|
|
560
529
|
|
|
561
530
|
---
|
|
562
531
|
|
|
532
|
+
## Retention
|
|
533
|
+
|
|
534
|
+
Retention is a property of the queue, not the message — so you register it per queue name, once, before `connect()`. `VsMessage` is unchanged.
|
|
535
|
+
|
|
536
|
+
```python
|
|
537
|
+
from vs_queue.schema.vs_retention import VsRetention
|
|
538
|
+
|
|
539
|
+
# via the factory
|
|
540
|
+
queue = VsQueueFactory.create(
|
|
541
|
+
provider="redis", host="localhost", port=6379,
|
|
542
|
+
retention={
|
|
543
|
+
"vs_trace:logs": VsRetention(ttl_seconds=604800, max_len=100_000),
|
|
544
|
+
},
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
# or directly, any time before the first publish/subscribe to that queue
|
|
548
|
+
queue.set_retention("vs_trace:logs", VsRetention(ttl_seconds=604800))
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
| Field | Meaning |
|
|
552
|
+
|---|---|
|
|
553
|
+
| `ttl_seconds` | Drop messages older than this |
|
|
554
|
+
| `max_len` | Keep at most this many messages |
|
|
555
|
+
|
|
556
|
+
Applied the first time the queue is published to or subscribed. Queues with no policy are unbounded, same as before.
|
|
557
|
+
|
|
558
|
+
**Redis Streams** — no native per-message TTL, so:
|
|
559
|
+
- `max_len` → `XADD ... MAXLEN ~ n` on every publish
|
|
560
|
+
- `ttl_seconds` → throttled `XTRIM <queue> MINID ~ <now - ttl>` (stream IDs are ms timestamps); runs at most once per `ttl/10` seconds per queue, not on every publish
|
|
561
|
+
|
|
562
|
+
**RabbitMQ** — set as queue arguments on declare:
|
|
563
|
+
- `ttl_seconds` → `x-message-ttl`
|
|
564
|
+
- `max_len` → `x-max-length`
|
|
565
|
+
|
|
566
|
+
RabbitMQ rejects redeclaring a live queue with different arguments — the first declare wins. To change a policy, use a new queue name or a broker policy.
|
|
567
|
+
|
|
568
|
+
---
|
|
569
|
+
|
|
563
570
|
## Logging
|
|
564
571
|
|
|
565
572
|
Both backends log consumer lifecycle and per-message activity on the provider logger
|
|
@@ -711,7 +718,7 @@ Creates queue instances from a registered provider name.
|
|
|
711
718
|
|
|
712
719
|
| Method | Signature | Description |
|
|
713
720
|
|---|---|---|
|
|
714
|
-
| `create` | `create(provider, host, port, credentials) -> VsBaseQueue` | Create and return a queue instance. Does not call `connect()`. |
|
|
721
|
+
| `create` | `create(provider, host, port, credentials, retention) -> VsBaseQueue` | Create and return a queue instance. Does not call `connect()`. `retention` is an optional `{queue_name: VsRetention}` map — see [Retention](#retention). |
|
|
715
722
|
|
|
716
723
|
**Example:**
|
|
717
724
|
|
|
@@ -920,6 +927,18 @@ Abstract base. Extend to implement a custom queue provider.
|
|
|
920
927
|
| `health_check()` | Returns `True` if broker is reachable |
|
|
921
928
|
| `publish(queue, message)` | Publish a message |
|
|
922
929
|
| `subscribe(queue, consumer, retry_policy)` | Start consuming |
|
|
930
|
+
| `set_retention(queue, VsRetention)` | Register a retention policy for a queue (before `connect()`) |
|
|
931
|
+
|
|
932
|
+
---
|
|
933
|
+
|
|
934
|
+
### VsRetention
|
|
935
|
+
|
|
936
|
+
Per-queue retention policy. See [Retention](#retention).
|
|
937
|
+
|
|
938
|
+
| Field | Type | Default | Description |
|
|
939
|
+
|---|---|---|---|
|
|
940
|
+
| `ttl_seconds` | `Optional[int]` | `None` | Drop messages older than this |
|
|
941
|
+
| `max_len` | `Optional[int]` | `None` | Keep at most this many messages |
|
|
923
942
|
|
|
924
943
|
---
|
|
925
944
|
|
|
@@ -938,9 +957,9 @@ Abstract base. Extend and implement `handle` to process messages.
|
|
|
938
957
|
| Method | Required | Description |
|
|
939
958
|
|---|---|---|
|
|
940
959
|
| `handle(message)` | Yes | Process a message. Raise to trigger retry. |
|
|
941
|
-
| `start()` |
|
|
942
|
-
| `stop()` |
|
|
943
|
-
| `on_error(message, error)` | No | Called on `handle` failure before retry |
|
|
960
|
+
| `start()` | No — no-op by default | Setup before consuming begins |
|
|
961
|
+
| `stop()` | No — no-op by default | Cleanup on shutdown — called on graceful cancel |
|
|
962
|
+
| `on_error(message, error)` | No — no-op by default | Called on `handle` failure before retry |
|
|
944
963
|
|
|
945
964
|
---
|
|
946
965
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "vs-queue"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.3"
|
|
8
8
|
description = "Pluggable async message queue library for Viveka Sutra — Redis Streams, RabbitMQ, retry, dead letter, and annotation-based consumers"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -52,4 +52,4 @@ include = ["vs_queue*"]
|
|
|
52
52
|
exclude = [".venv*"]
|
|
53
53
|
|
|
54
54
|
[tool.setuptools.package-data]
|
|
55
|
-
vs_queue = ["py.typed"
|
|
55
|
+
vs_queue = ["py.typed"]
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
from vs_queue.registry.vs_queue_registry import VsQueueRegistry
|
|
2
2
|
from vs_queue.provider.vs_redis_queue import VsRedisQueue
|
|
3
3
|
from vs_queue.provider.vs_rabbitmq_queue import VsRabbitMQQueue
|
|
4
|
+
from vs_queue.schema.vs_retention import VsRetention
|
|
4
5
|
|
|
5
6
|
VsQueueRegistry.register("redis", VsRedisQueue)
|
|
6
7
|
VsQueueRegistry.register("rabbitmq", VsRabbitMQQueue)
|
|
8
|
+
|
|
9
|
+
__all__ = ["VsQueueRegistry", "VsRedisQueue", "VsRabbitMQQueue", "VsRetention"]
|
|
@@ -13,12 +13,12 @@ class VsBaseConsumer(ABC):
|
|
|
13
13
|
async def handle(self, message: VsMessage) -> None:
|
|
14
14
|
pass
|
|
15
15
|
|
|
16
|
-
@abstractmethod
|
|
17
16
|
async def start(self) -> None:
|
|
17
|
+
"""Called once before consuming begins. Override for setup."""
|
|
18
18
|
pass
|
|
19
19
|
|
|
20
|
-
@abstractmethod
|
|
21
20
|
async def stop(self) -> None:
|
|
21
|
+
"""Called once on graceful shutdown. Override for cleanup."""
|
|
22
22
|
pass
|
|
23
23
|
|
|
24
24
|
async def on_error(self, message: VsMessage, error: Exception) -> None:
|
|
@@ -2,6 +2,7 @@ from abc import ABC, abstractmethod
|
|
|
2
2
|
from typing import Any, Dict, Optional
|
|
3
3
|
|
|
4
4
|
from vs_queue.schema.vs_message import VsMessage
|
|
5
|
+
from vs_queue.schema.vs_retention import VsRetention
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
class VsBaseQueue(ABC):
|
|
@@ -10,6 +11,15 @@ class VsBaseQueue(ABC):
|
|
|
10
11
|
self._host = host
|
|
11
12
|
self._port = port
|
|
12
13
|
self._credentials = credentials or {}
|
|
14
|
+
self._retention: Dict[str, VsRetention] = {}
|
|
15
|
+
|
|
16
|
+
def set_retention(self, queue: str, retention: VsRetention) -> None:
|
|
17
|
+
"""Register a retention policy for a queue. Applied the first time the
|
|
18
|
+
queue is published to or subscribed. Call before connect()."""
|
|
19
|
+
self._retention[queue] = retention
|
|
20
|
+
|
|
21
|
+
def _retention_for(self, queue: str) -> Optional[VsRetention]:
|
|
22
|
+
return self._retention.get(queue)
|
|
13
23
|
|
|
14
24
|
@abstractmethod
|
|
15
25
|
async def connect(self) -> None:
|
|
@@ -2,6 +2,7 @@ from typing import Any, Dict, Optional
|
|
|
2
2
|
|
|
3
3
|
from vs_queue.base.vs_base_queue import VsBaseQueue
|
|
4
4
|
from vs_queue.registry.vs_queue_registry import VsQueueRegistry
|
|
5
|
+
from vs_queue.schema.vs_retention import VsRetention
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
class VsQueueFactory:
|
|
@@ -13,6 +14,10 @@ class VsQueueFactory:
|
|
|
13
14
|
host: str,
|
|
14
15
|
port: int,
|
|
15
16
|
credentials: Optional[Dict[str, Any]] = None,
|
|
17
|
+
retention: Optional[Dict[str, VsRetention]] = None,
|
|
16
18
|
) -> VsBaseQueue:
|
|
17
19
|
queue_class = VsQueueRegistry.get(provider)
|
|
18
|
-
|
|
20
|
+
queue = queue_class(host=host, port=port, credentials=credentials)
|
|
21
|
+
for name, policy in (retention or {}).items():
|
|
22
|
+
queue.set_retention(name, policy)
|
|
23
|
+
return queue
|
|
@@ -44,9 +44,22 @@ class VsRabbitMQQueue(VsBaseQueue):
|
|
|
44
44
|
async def health_check(self) -> bool:
|
|
45
45
|
return self._connection is not None and not self._connection.is_closed
|
|
46
46
|
|
|
47
|
+
async def _declare(self, queue: str):
|
|
48
|
+
# RabbitMQ 406s if a live queue is redeclared with different args, so the
|
|
49
|
+
# first declare wins — change the policy via a new queue or a broker policy.
|
|
50
|
+
arguments: Dict[str, Any] = {}
|
|
51
|
+
retention = self._retention_for(queue)
|
|
52
|
+
if retention and retention.ttl_seconds:
|
|
53
|
+
arguments["x-message-ttl"] = retention.ttl_seconds * 1000
|
|
54
|
+
if retention and retention.max_len:
|
|
55
|
+
arguments["x-max-length"] = retention.max_len
|
|
56
|
+
return await self._channel.declare_queue(
|
|
57
|
+
queue, durable=True, arguments=arguments or None,
|
|
58
|
+
)
|
|
59
|
+
|
|
47
60
|
async def publish(self, queue: str, message: VsMessage) -> None:
|
|
48
61
|
import aio_pika
|
|
49
|
-
await self.
|
|
62
|
+
await self._declare(queue)
|
|
50
63
|
body = json.dumps({
|
|
51
64
|
"id": message.id,
|
|
52
65
|
"timestamp": message.timestamp.isoformat(),
|
|
@@ -60,7 +73,7 @@ class VsRabbitMQQueue(VsBaseQueue):
|
|
|
60
73
|
)
|
|
61
74
|
|
|
62
75
|
async def subscribe(self, queue: str, consumer: VsBaseConsumer, retry_policy: Optional[VsRetryPolicy] = None) -> None:
|
|
63
|
-
q = await self.
|
|
76
|
+
q = await self._declare(queue)
|
|
64
77
|
await consumer.start()
|
|
65
78
|
_logger.info(f"Subscribed | queue={queue} consumer={type(consumer).__name__}")
|
|
66
79
|
try:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import json
|
|
3
3
|
import logging
|
|
4
|
+
import time
|
|
4
5
|
from typing import Any, Dict, Optional
|
|
5
6
|
|
|
6
7
|
import redis.asyncio as aioredis
|
|
@@ -18,6 +19,7 @@ class VsRedisQueue(VsBaseQueue):
|
|
|
18
19
|
def __init__(self, host: str, port: int, credentials: Optional[Dict[str, Any]] = None):
|
|
19
20
|
super().__init__(host, port, credentials)
|
|
20
21
|
self._client: Optional[aioredis.Redis] = None
|
|
22
|
+
self._last_trim: Dict[str, float] = {}
|
|
21
23
|
|
|
22
24
|
async def connect(self) -> None:
|
|
23
25
|
password = self._credentials.get("password")
|
|
@@ -49,7 +51,27 @@ class VsRedisQueue(VsBaseQueue):
|
|
|
49
51
|
"headers": json.dumps(message.headers),
|
|
50
52
|
"payload": json.dumps(message.payload or {}),
|
|
51
53
|
}
|
|
52
|
-
|
|
54
|
+
retention = self._retention_for(queue)
|
|
55
|
+
kwargs: Dict[str, Any] = {}
|
|
56
|
+
if retention and retention.max_len:
|
|
57
|
+
kwargs = {"maxlen": retention.max_len, "approximate": True}
|
|
58
|
+
await self._client.xadd(queue, data, **kwargs)
|
|
59
|
+
if retention and retention.ttl_seconds:
|
|
60
|
+
await self._trim_by_age(queue, retention.ttl_seconds)
|
|
61
|
+
|
|
62
|
+
async def _trim_by_age(self, queue: str, ttl_seconds: int) -> None:
|
|
63
|
+
# Stream IDs are ms timestamps, so MINID trims by age. Throttle so we
|
|
64
|
+
# don't XTRIM on every publish.
|
|
65
|
+
now = time.time()
|
|
66
|
+
interval = max(ttl_seconds / 10, 1)
|
|
67
|
+
if now - self._last_trim.get(queue, 0.0) < interval:
|
|
68
|
+
return
|
|
69
|
+
self._last_trim[queue] = now
|
|
70
|
+
min_id = f"{int((now - ttl_seconds) * 1000)}-0"
|
|
71
|
+
try:
|
|
72
|
+
await self._client.xtrim(queue, minid=min_id, approximate=True)
|
|
73
|
+
except Exception as e:
|
|
74
|
+
_logger.warning(f"Retention trim failed | queue={queue} error={e}")
|
|
53
75
|
|
|
54
76
|
async def blpop(self, key: str, timeout: int = 30) -> Optional[str]:
|
|
55
77
|
result = await self._client.blpop(key, timeout=timeout)
|
|
File without changes
|
|
@@ -1,3 +1,218 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vs-queue
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Pluggable async message queue library for Viveka Sutra — Redis Streams, RabbitMQ, retry, dead letter, and annotation-based consumers
|
|
5
|
+
License: Apache License
|
|
6
|
+
Version 2.0, January 2004
|
|
7
|
+
http://www.apache.org/licenses/
|
|
8
|
+
|
|
9
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
10
|
+
|
|
11
|
+
1. Definitions.
|
|
12
|
+
|
|
13
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
14
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
15
|
+
|
|
16
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
17
|
+
the copyright owner that is granting the License.
|
|
18
|
+
|
|
19
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
20
|
+
other entities that control, are controlled by, or are under common
|
|
21
|
+
control with that entity. For the purposes of this definition,
|
|
22
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
23
|
+
direction or management of such entity, whether by contract or
|
|
24
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
25
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
26
|
+
|
|
27
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
28
|
+
exercising permissions granted by this License.
|
|
29
|
+
|
|
30
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
31
|
+
including but not limited to software source code, documentation
|
|
32
|
+
source, and configuration files.
|
|
33
|
+
|
|
34
|
+
"Object" form shall mean any form resulting from mechanical
|
|
35
|
+
transformation or translation of a Source form, including but
|
|
36
|
+
not limited to compiled object code, generated documentation,
|
|
37
|
+
and conversions to other media types.
|
|
38
|
+
|
|
39
|
+
"Work" shall mean the work of authorship made available under
|
|
40
|
+
the License, as indicated by a copyright notice that is included in
|
|
41
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and derivative works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
52
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
53
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
54
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
55
|
+
or written communication sent to the Licensor or its representatives,
|
|
56
|
+
including but not limited to communication on electronic mailing lists,
|
|
57
|
+
source code control systems, and issue tracking systems that are managed
|
|
58
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
59
|
+
improving the Work, but excluding communication that is conspicuously
|
|
60
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
61
|
+
Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
64
|
+
whom a Contribution has been received by the Licensor and incorporated
|
|
65
|
+
within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a cross-claim
|
|
84
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
85
|
+
Contribution embodied within the Work constitutes direct or
|
|
86
|
+
contributory patent infringement, then any patent licenses granted to
|
|
87
|
+
You under this License for that Work shall terminate as of the date
|
|
88
|
+
such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
96
|
+
Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" file as part of its distribution,
|
|
108
|
+
You must include a readable copy of the attribution notices
|
|
109
|
+
contained within such NOTICE file, in at least one of the
|
|
110
|
+
following places: within a NOTICE text file distributed as part
|
|
111
|
+
of the Derivative Works; within the Source form or documentation,
|
|
112
|
+
if provided along with the Derivative Works; or, within a display
|
|
113
|
+
generated by the Derivative Works, if and wherever such
|
|
114
|
+
third-party notices normally appear. The contents of the NOTICE
|
|
115
|
+
file are for informational purposes only and do not modify the
|
|
116
|
+
License. You may add Your own attribution notices within
|
|
117
|
+
Derivative Works that You distribute, alongside or as an addendum
|
|
118
|
+
to the NOTICE text from the Work, provided that such additional
|
|
119
|
+
attribution notices cannot be construed as modifying the License.
|
|
120
|
+
|
|
121
|
+
You may add Your own license statement for Your modifications and
|
|
122
|
+
may provide additional grant of rights to use, modify, and distribute
|
|
123
|
+
Your modifications.
|
|
124
|
+
|
|
125
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
126
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
127
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
128
|
+
this License, without any additional terms or conditions.
|
|
129
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
130
|
+
the terms of any separate license agreement you may have executed
|
|
131
|
+
with Licensor regarding such Contributions.
|
|
132
|
+
|
|
133
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
134
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
135
|
+
except as required for reasonable and customary use in describing the
|
|
136
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
137
|
+
|
|
138
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
139
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
140
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
141
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
142
|
+
implied, including, without limitation, any conditions of TITLE,
|
|
143
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
144
|
+
PURPOSE. You are solely responsible for determining the
|
|
145
|
+
appropriateness of using or reproducing the Work and assume any
|
|
146
|
+
risks associated with Your exercise of permissions under this License.
|
|
147
|
+
|
|
148
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
149
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
150
|
+
unless required by applicable law (such as deliberate and grossly
|
|
151
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
152
|
+
liable to You for damages, including any direct, indirect, special,
|
|
153
|
+
incidental, or exemplary damages of any character arising as a
|
|
154
|
+
result of this License or out of the use or inability to use the
|
|
155
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
156
|
+
work stoppage, computer failure or malfunction, or all other
|
|
157
|
+
commercial damages or losses), even if such Contributor has been
|
|
158
|
+
advised of the possibility of such damages.
|
|
159
|
+
|
|
160
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
161
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
162
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
163
|
+
or other liability obligations and/or rights consistent with this
|
|
164
|
+
License. However, in accepting such obligations, You may act only
|
|
165
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
166
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
167
|
+
defend, and hold each Contributor harmless for any liability
|
|
168
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
169
|
+
of your accepting any such warranty or additional liability.
|
|
170
|
+
|
|
171
|
+
END OF TERMS AND CONDITIONS
|
|
172
|
+
|
|
173
|
+
Copyright 2026 VivekaSutra. All rights reserved.
|
|
174
|
+
|
|
175
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
176
|
+
you may not use this file except in compliance with the License.
|
|
177
|
+
You may obtain a copy of the License at
|
|
178
|
+
|
|
179
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
180
|
+
|
|
181
|
+
Unless required by applicable law or agreed to in writing, software
|
|
182
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
183
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
184
|
+
implied. See the License for the specific language governing
|
|
185
|
+
permissions and limitations under the License.
|
|
186
|
+
|
|
187
|
+
Project-URL: Homepage, https://vivekasutra.com/
|
|
188
|
+
Project-URL: Source, https://github.com/vivekasutra/viveka-mula
|
|
189
|
+
Keywords: queue,messaging,redis,rabbitmq,async,consumer,viveka,vs
|
|
190
|
+
Classifier: Development Status :: 3 - Alpha
|
|
191
|
+
Classifier: Intended Audience :: Developers
|
|
192
|
+
Classifier: License :: Other/Proprietary License
|
|
193
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
194
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
195
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
196
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
197
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
198
|
+
Classifier: Framework :: AsyncIO
|
|
199
|
+
Classifier: Typing :: Typed
|
|
200
|
+
Requires-Python: >=3.11
|
|
201
|
+
Description-Content-Type: text/markdown
|
|
202
|
+
License-File: LICENSE.txt
|
|
203
|
+
Requires-Dist: pydantic>=2.0
|
|
204
|
+
Provides-Extra: redis
|
|
205
|
+
Requires-Dist: redis>=5.0; extra == "redis"
|
|
206
|
+
Requires-Dist: hiredis>=2.0; extra == "redis"
|
|
207
|
+
Provides-Extra: rabbitmq
|
|
208
|
+
Requires-Dist: aio-pika>=9.0; extra == "rabbitmq"
|
|
209
|
+
Provides-Extra: dev
|
|
210
|
+
Requires-Dist: build; extra == "dev"
|
|
211
|
+
Requires-Dist: twine; extra == "dev"
|
|
212
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
213
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
214
|
+
Dynamic: license-file
|
|
215
|
+
|
|
1
216
|
# vs-queue
|
|
2
217
|
|
|
3
218
|
Pluggable async message queue library for Viveka Sutra — Redis Streams, RabbitMQ, retry policies, dead letter queues, and annotation-based consumers.
|
|
@@ -273,6 +488,12 @@ Abstract base class for all queue backends. Extend this to implement a custom pr
|
|
|
273
488
|
| `publish(queue, message)` | Publish a `VsMessage` to a named queue |
|
|
274
489
|
| `subscribe(queue, consumer, retry_policy)` | Begin consuming from a queue using a `VsBaseConsumer` |
|
|
275
490
|
|
|
491
|
+
**Concrete method:**
|
|
492
|
+
|
|
493
|
+
| Method | Description |
|
|
494
|
+
|---|---|
|
|
495
|
+
| `set_retention(queue, VsRetention)` | Register a per-queue retention policy. Call before `connect()`. See [Retention](#retention). |
|
|
496
|
+
|
|
276
497
|
---
|
|
277
498
|
|
|
278
499
|
## VsBaseConsumer
|
|
@@ -284,13 +505,13 @@ Abstract base class for all consumers. Extend this and implement `handle` to pro
|
|
|
284
505
|
| Method | Description |
|
|
285
506
|
|---|---|
|
|
286
507
|
| `handle(message)` | Called for every message received. Raise any exception to trigger retry. |
|
|
287
|
-
| `start()` | Called once when the consumer begins. Use for setup. |
|
|
288
|
-
| `stop()` | Called once on graceful shutdown. Use for cleanup. |
|
|
289
508
|
|
|
290
|
-
**Optional override
|
|
509
|
+
**Optional overrides** (concrete no-ops by default — override only if you need them):
|
|
291
510
|
|
|
292
511
|
| Method | Description |
|
|
293
512
|
|---|---|
|
|
513
|
+
| `start()` | Called once when the consumer begins. Use for setup. |
|
|
514
|
+
| `stop()` | Called once on graceful shutdown. Use for cleanup. |
|
|
294
515
|
| `on_error(message, error)` | Called when `handle` raises an exception, before retry logic runs. Use for logging or alerting. |
|
|
295
516
|
|
|
296
517
|
**Example with error hook:**
|
|
@@ -343,9 +564,6 @@ Decorator that registers a `VsBaseConsumer` subclass as a listener. `VsQueueMana
|
|
|
343
564
|
class SimpleConsumer(VsBaseConsumer):
|
|
344
565
|
async def handle(self, message: VsMessage) -> None:
|
|
345
566
|
print(message.payload)
|
|
346
|
-
|
|
347
|
-
async def start(self) -> None: pass
|
|
348
|
-
async def stop(self) -> None: pass
|
|
349
567
|
```
|
|
350
568
|
|
|
351
569
|
**Example — full configuration:**
|
|
@@ -512,9 +730,6 @@ class DlqConsumer(VsBaseConsumer):
|
|
|
512
730
|
f"Message permanently failed | id={message.id} retries={message.retry_count}",
|
|
513
731
|
payload=message.payload,
|
|
514
732
|
)
|
|
515
|
-
|
|
516
|
-
async def start(self) -> None: pass
|
|
517
|
-
async def stop(self) -> None: pass
|
|
518
733
|
```
|
|
519
734
|
|
|
520
735
|
**Example — replaying a DLQ message:**
|
|
@@ -529,6 +744,44 @@ await queue.publish("orchestrator:tasks", dlq_message)
|
|
|
529
744
|
|
|
530
745
|
---
|
|
531
746
|
|
|
747
|
+
## Retention
|
|
748
|
+
|
|
749
|
+
Retention is a property of the queue, not the message — so you register it per queue name, once, before `connect()`. `VsMessage` is unchanged.
|
|
750
|
+
|
|
751
|
+
```python
|
|
752
|
+
from vs_queue.schema.vs_retention import VsRetention
|
|
753
|
+
|
|
754
|
+
# via the factory
|
|
755
|
+
queue = VsQueueFactory.create(
|
|
756
|
+
provider="redis", host="localhost", port=6379,
|
|
757
|
+
retention={
|
|
758
|
+
"vs_trace:logs": VsRetention(ttl_seconds=604800, max_len=100_000),
|
|
759
|
+
},
|
|
760
|
+
)
|
|
761
|
+
|
|
762
|
+
# or directly, any time before the first publish/subscribe to that queue
|
|
763
|
+
queue.set_retention("vs_trace:logs", VsRetention(ttl_seconds=604800))
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
| Field | Meaning |
|
|
767
|
+
|---|---|
|
|
768
|
+
| `ttl_seconds` | Drop messages older than this |
|
|
769
|
+
| `max_len` | Keep at most this many messages |
|
|
770
|
+
|
|
771
|
+
Applied the first time the queue is published to or subscribed. Queues with no policy are unbounded, same as before.
|
|
772
|
+
|
|
773
|
+
**Redis Streams** — no native per-message TTL, so:
|
|
774
|
+
- `max_len` → `XADD ... MAXLEN ~ n` on every publish
|
|
775
|
+
- `ttl_seconds` → throttled `XTRIM <queue> MINID ~ <now - ttl>` (stream IDs are ms timestamps); runs at most once per `ttl/10` seconds per queue, not on every publish
|
|
776
|
+
|
|
777
|
+
**RabbitMQ** — set as queue arguments on declare:
|
|
778
|
+
- `ttl_seconds` → `x-message-ttl`
|
|
779
|
+
- `max_len` → `x-max-length`
|
|
780
|
+
|
|
781
|
+
RabbitMQ rejects redeclaring a live queue with different arguments — the first declare wins. To change a policy, use a new queue name or a broker policy.
|
|
782
|
+
|
|
783
|
+
---
|
|
784
|
+
|
|
532
785
|
## Logging
|
|
533
786
|
|
|
534
787
|
Both backends log consumer lifecycle and per-message activity on the provider logger
|
|
@@ -680,7 +933,7 @@ Creates queue instances from a registered provider name.
|
|
|
680
933
|
|
|
681
934
|
| Method | Signature | Description |
|
|
682
935
|
|---|---|---|
|
|
683
|
-
| `create` | `create(provider, host, port, credentials) -> VsBaseQueue` | Create and return a queue instance. Does not call `connect()`. |
|
|
936
|
+
| `create` | `create(provider, host, port, credentials, retention) -> VsBaseQueue` | Create and return a queue instance. Does not call `connect()`. `retention` is an optional `{queue_name: VsRetention}` map — see [Retention](#retention). |
|
|
684
937
|
|
|
685
938
|
**Example:**
|
|
686
939
|
|
|
@@ -889,6 +1142,18 @@ Abstract base. Extend to implement a custom queue provider.
|
|
|
889
1142
|
| `health_check()` | Returns `True` if broker is reachable |
|
|
890
1143
|
| `publish(queue, message)` | Publish a message |
|
|
891
1144
|
| `subscribe(queue, consumer, retry_policy)` | Start consuming |
|
|
1145
|
+
| `set_retention(queue, VsRetention)` | Register a retention policy for a queue (before `connect()`) |
|
|
1146
|
+
|
|
1147
|
+
---
|
|
1148
|
+
|
|
1149
|
+
### VsRetention
|
|
1150
|
+
|
|
1151
|
+
Per-queue retention policy. See [Retention](#retention).
|
|
1152
|
+
|
|
1153
|
+
| Field | Type | Default | Description |
|
|
1154
|
+
|---|---|---|---|
|
|
1155
|
+
| `ttl_seconds` | `Optional[int]` | `None` | Drop messages older than this |
|
|
1156
|
+
| `max_len` | `Optional[int]` | `None` | Keep at most this many messages |
|
|
892
1157
|
|
|
893
1158
|
---
|
|
894
1159
|
|
|
@@ -907,9 +1172,9 @@ Abstract base. Extend and implement `handle` to process messages.
|
|
|
907
1172
|
| Method | Required | Description |
|
|
908
1173
|
|---|---|---|
|
|
909
1174
|
| `handle(message)` | Yes | Process a message. Raise to trigger retry. |
|
|
910
|
-
| `start()` |
|
|
911
|
-
| `stop()` |
|
|
912
|
-
| `on_error(message, error)` | No | Called on `handle` failure before retry |
|
|
1175
|
+
| `start()` | No — no-op by default | Setup before consuming begins |
|
|
1176
|
+
| `stop()` | No — no-op by default | Cleanup on shutdown — called on graceful cancel |
|
|
1177
|
+
| `on_error(message, error)` | No — no-op by default | Called on `handle` failure before retry |
|
|
913
1178
|
|
|
914
1179
|
---
|
|
915
1180
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
LICENSE.txt
|
|
1
2
|
README.md
|
|
2
3
|
pyproject.toml
|
|
3
4
|
vs_queue/__init__.py
|
|
5
|
+
vs_queue/py.typed
|
|
4
6
|
vs_queue.egg-info/PKG-INFO
|
|
5
7
|
vs_queue.egg-info/SOURCES.txt
|
|
6
8
|
vs_queue.egg-info/dependency_links.txt
|
|
@@ -23,4 +25,5 @@ vs_queue/registry/vs_queue_registry.py
|
|
|
23
25
|
vs_queue/retry/__init__.py
|
|
24
26
|
vs_queue/retry/vs_retry_policy.py
|
|
25
27
|
vs_queue/schema/__init__.py
|
|
26
|
-
vs_queue/schema/vs_message.py
|
|
28
|
+
vs_queue/schema/vs_message.py
|
|
29
|
+
vs_queue/schema/vs_retention.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|