-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracker.py
More file actions
32 lines (25 loc) · 781 Bytes
/
tracker.py
File metadata and controls
32 lines (25 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import json
from confluent_kafka import Consumer
consumer_config = {
"bootstrap.servers": "localhost:9092",
"group.id": "order-tracker",
"auto.offset.reset": "earliest"
}
consumer = Consumer(consumer_config)
consumer.subscribe(["orders"])
print("🟢 Consumer is running and subscribed to orders topic")
try:
while True:
msg = consumer.poll(1.0)
if msg is None:
continue
if msg.error():
print("❌ Error:", msg.error())
continue
value = msg.value().decode("utf-8")
order = json.loads(value)
print(f"📦 Received order: {order['quantity']} x {order['item']} from {order['user']}")
except KeyboardInterrupt:
print("\n🔴 Stopping consumer")
finally:
consumer.close()