sify-queue-kafka 0.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,270 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sify-queue-kafka
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Enterprise Queue management Framework
|
|
5
|
+
Author: sifymodernization
|
|
6
|
+
Author-email: sifymodernization <sifymodernization.dev@sifycorp.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Keywords: kafka,events,queue,messaging
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
Requires-Dist: kafka-python>=2.0.2
|
|
23
|
+
Requires-Dist: pydantic>=2.0.0
|
|
24
|
+
Requires-Dist: typing-extensions>=4.0.0; python_version < "3.10"
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
29
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
31
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
33
|
+
|
|
34
|
+
# Sify Queue Kafka
|
|
35
|
+
|
|
36
|
+
Enterprise Queue management Framework for building robust, scalable event-driven applications.
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- **Event-Driven Architecture**: Built on Apache Kafka for reliable message streaming
|
|
41
|
+
- **Type Safety**: Pydantic models for event validation and serialization
|
|
42
|
+
- **Retry & Resilience**: Exponential backoff retry with configurable policies
|
|
43
|
+
- **Idempotency**: Built-in duplicate event detection and prevention
|
|
44
|
+
- **Dead Letter Queue**: Automatic failed event routing for error handling
|
|
45
|
+
- **Stage-Based Processing**: Multi-stage event pipelines with stage-specific handlers
|
|
46
|
+
- **Comprehensive Logging**: Structured logging throughout the framework
|
|
47
|
+
- **Exception Handling**: Custom exception types for better error management
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install sify-queue-kafka
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For development with additional tools:
|
|
56
|
+
```bash
|
|
57
|
+
pip install sify-queue-kafka[dev]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quick Start
|
|
61
|
+
|
|
62
|
+
### Basic Producer
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from datetime import datetime, timezone
|
|
66
|
+
from queue_kafka import Producer
|
|
67
|
+
|
|
68
|
+
producer = Producer()
|
|
69
|
+
|
|
70
|
+
def send_user_created_event():
|
|
71
|
+
message = {
|
|
72
|
+
"eventType": "USER_CREATED",
|
|
73
|
+
"eventVersion": "1.0",
|
|
74
|
+
"source": "user-service",
|
|
75
|
+
"tenantId": "tenant-123",
|
|
76
|
+
"payload": {
|
|
77
|
+
"userId": "user-456",
|
|
78
|
+
"email": "user@example.com",
|
|
79
|
+
"name": "John Doe"
|
|
80
|
+
},
|
|
81
|
+
"metadata": {
|
|
82
|
+
"stage": "SendWelcomeEmail",
|
|
83
|
+
"created_at": datetime.now(timezone.utc).isoformat()
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
producer.send("user-topic", message)
|
|
88
|
+
print("USER_CREATED event sent")
|
|
89
|
+
|
|
90
|
+
if __name__ == "__main__":
|
|
91
|
+
try:
|
|
92
|
+
send_user_created_event()
|
|
93
|
+
finally:
|
|
94
|
+
producer.close()
|
|
95
|
+
print("Producer closed")
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Basic Consumer (with stage)
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from queue_kafka import Consumer, event_handler, KafkaEvent
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@event_handler("USER_CREATED", stage="EMAIL_NOTIFICATION")
|
|
105
|
+
def send_welcome_email(event: KafkaEvent):
|
|
106
|
+
print(f"Sending welcome email to: {event.payload['email']}")
|
|
107
|
+
|
|
108
|
+
if __name__ == "__main__":
|
|
109
|
+
|
|
110
|
+
consumer = Consumer(
|
|
111
|
+
topics="user-topic",
|
|
112
|
+
config={
|
|
113
|
+
"stage": "EMAIL_NOTIFICATION",
|
|
114
|
+
"tenant_id": "tenant-123",
|
|
115
|
+
"source": "email-service",
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
try:
|
|
120
|
+
print("Consumer running... Press Ctrl+C to stop")
|
|
121
|
+
consumer.start()
|
|
122
|
+
except KeyboardInterrupt:
|
|
123
|
+
print("\nKeyboard interrupt received")
|
|
124
|
+
finally:
|
|
125
|
+
consumer.stop()
|
|
126
|
+
print("Consumer stopped")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Basic Consumer (without stage)
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from queue_kafka import Consumer, event_handler, KafkaEvent
|
|
133
|
+
|
|
134
|
+
@event_handler("USER_CREATED")
|
|
135
|
+
def send_welcome_email(event: KafkaEvent):
|
|
136
|
+
print(f"Sending welcome email to: {event.payload['email']}")
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
if __name__ == "__main__":
|
|
140
|
+
|
|
141
|
+
consumer = Consumer(
|
|
142
|
+
topics="user-topic",
|
|
143
|
+
config={
|
|
144
|
+
"tenant_id": "tenant-123",
|
|
145
|
+
"source": "email-service",
|
|
146
|
+
}
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
try:
|
|
150
|
+
print("Consumer running... Press Ctrl+C to stop")
|
|
151
|
+
consumer.start()
|
|
152
|
+
except KeyboardInterrupt:
|
|
153
|
+
print("\nKeyboard interrupt received")
|
|
154
|
+
finally:
|
|
155
|
+
consumer.stop()
|
|
156
|
+
print("Consumer stopped")
|
|
157
|
+
```
|
|
158
|
+
### Error Handling and DLQ
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from queue_kafka import Consumer, event_handler, KafkaEvent, EventProcessingError
|
|
162
|
+
|
|
163
|
+
@event_handler("PAYMENT_INIT", stage="ProcessPayment")
|
|
164
|
+
def process_payment(event: KafkaEvent):
|
|
165
|
+
print("Payment processed successfully")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if __name__ == "__main__":
|
|
169
|
+
|
|
170
|
+
process_consumer = Consumer(
|
|
171
|
+
topics=payment-topic,
|
|
172
|
+
config={
|
|
173
|
+
"stage": "ProcessPayment",
|
|
174
|
+
"tenant_id": "tenant-222",
|
|
175
|
+
"source": "payment-service",
|
|
176
|
+
"dead_letter_topic": payment-dlq-topic
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
try:
|
|
181
|
+
process_consumer.start()
|
|
182
|
+
|
|
183
|
+
except KeyboardInterrupt:
|
|
184
|
+
print("\nShutting down...")
|
|
185
|
+
|
|
186
|
+
finally:
|
|
187
|
+
process_consumer.stop()
|
|
188
|
+
print("Consumer stopped")
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Configuration Options
|
|
192
|
+
|
|
193
|
+
| Option | Type | Default | Description |
|
|
194
|
+
|--------|------|---------|-------------|
|
|
195
|
+
| `bootstrap_servers` | str | Required | Kafka bootstrap servers |
|
|
196
|
+
| `group_id` | str | None | Consumer group ID |
|
|
197
|
+
| `enable_auto_commit` | bool | False | Enable auto commit of offsets |
|
|
198
|
+
| `auto_offset_reset` | str | "earliest" | Offset reset policy |
|
|
199
|
+
| `enable_idempotency` | bool | True | Enable duplicate detection |
|
|
200
|
+
| `enable_retry` | bool | True | Enable retry with backoff |
|
|
201
|
+
| `dead_letter_topic` | str | None | Topic for failed events |
|
|
202
|
+
| `stage` | str | None | Processing stage name |
|
|
203
|
+
|
|
204
|
+
## Event Model
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
class KafkaEvent(BaseModel):
|
|
208
|
+
eventId: str
|
|
209
|
+
eventType: str
|
|
210
|
+
eventVersion: str
|
|
211
|
+
source: str
|
|
212
|
+
tenantId: str
|
|
213
|
+
timestamp: datetime
|
|
214
|
+
correlationId: Optional[str]
|
|
215
|
+
traceId: Optional[str]
|
|
216
|
+
priority: Optional[str]
|
|
217
|
+
retryCount: int
|
|
218
|
+
maxRetries: int
|
|
219
|
+
payload: Dict[str, Any]
|
|
220
|
+
metadata: Optional[Dict[str, Any]]
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Exception Types
|
|
224
|
+
|
|
225
|
+
- `QueueSDKError`: Base exception for all SDK errors
|
|
226
|
+
- `ConfigurationError`: Configuration-related errors
|
|
227
|
+
- `HandlerNotFoundError`: No handler found for event type/stage
|
|
228
|
+
- `EventProcessingError`: Event processing failures
|
|
229
|
+
- `ProducerError`: Producer operation failures
|
|
230
|
+
- `ConsumerError`: Consumer operation failures
|
|
231
|
+
- `SerializationError`: Event serialization/deserialization errors
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
## Architecture
|
|
235
|
+
|
|
236
|
+
```
|
|
237
|
+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
|
238
|
+
│ Producer │───▶│ Kafka Topic │───▶│ Consumer │
|
|
239
|
+
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
|
240
|
+
│
|
|
241
|
+
▼
|
|
242
|
+
┌─────────────────┐
|
|
243
|
+
│ Dispatcher │
|
|
244
|
+
└─────────────────┘
|
|
245
|
+
│
|
|
246
|
+
▼
|
|
247
|
+
┌─────────────────┐
|
|
248
|
+
│ Event Registry │
|
|
249
|
+
└─────────────────┘
|
|
250
|
+
│
|
|
251
|
+
▼
|
|
252
|
+
┌─────────────────┐
|
|
253
|
+
│ Event Handler │
|
|
254
|
+
└─────────────────┘
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## License
|
|
258
|
+
|
|
259
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
260
|
+
|
|
261
|
+
## Changelog
|
|
262
|
+
|
|
263
|
+
### v0.1.3
|
|
264
|
+
- Initial release
|
|
265
|
+
- Basic producer/consumer functionality
|
|
266
|
+
- Event validation with Pydantic
|
|
267
|
+
- Retry and idempotency features
|
|
268
|
+
- Dead letter queue support
|
|
269
|
+
- Comprehensive logging
|
|
270
|
+
- Unit test coverage
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
sify_queue_kafka-0.1.3.dist-info/METADATA,sha256=Elk9emHWCuIaCxuV0uX2Jcmf3oi4QxNWxYIJi8D7dLw,8917
|
|
2
|
+
sify_queue_kafka-0.1.3.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
3
|
+
sify_queue_kafka-0.1.3.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
+
sify_queue_kafka-0.1.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|