You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-17Lines changed: 43 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,11 @@
5
5
6
6
# Apache Kafka Python Demo
7
7
8
-
## 🧩 Overview
8
+
## Overview
9
9
10
10
A minimal Apache Kafka demo using Python featuring:
11
-
- A **JSON-producing**`producer.py`
12
-
- A **format-tolerant**`consumer.py` supporting JSON & plain text
11
+
- A multi-format`producer.py` (JSON by default; Protobuf via env)
12
+
- A **format-tolerant**`consumer.py` supporting JSON, Protobuf & plain text
13
13
- Partition-awareness, message keying, and consumer group support
14
14
- Integration testing via `Testcontainers`
15
15
- GitHub Actions & Codecov integration
@@ -18,7 +18,7 @@ It’s designed to simulate a polyglot messaging environment, where different sy
18
18
19
19
---
20
20
21
-
## ⚙️ Requirements
21
+
## Requirements
22
22
23
23
- Python 3.10+
24
24
- Docker & Docker Compose (for container-based setup) - more details could be found in the [separate section](documentation/docker.md).
@@ -32,7 +32,7 @@ pip install -r requirements.txt
32
32
33
33
---
34
34
35
-
## 🚀 Running the Demo
35
+
## Running the Demo
36
36
37
37
### 1. Start Apache Kafka
38
38
@@ -46,27 +46,49 @@ docker run -d --name kafka-391 \
46
46
47
47
More information about helper scripts Kafka provides could be found in the [separate section](documentation/kafka.md).
48
48
49
-
### 🟢 Run Producer
49
+
### Run Producer
50
50
51
51
```bash
52
52
python producer.py
53
53
```
54
54
55
-
Produces random JSON events (`note_created`, `note_updated`, `note_deleted`) with message keys for partitioning.
55
+
Produces random events (`note_created`, `note_updated`, `note_deleted`) with message keys for partitioning.
56
56
57
-
### 🔵 Run Consumer
57
+
Formats:
58
+
- JSON (default)
59
+
- Protobuf (enable via `MESSAGE_FORMAT=protobuf`)
60
+
61
+
Examples:
62
+
63
+
```bash
64
+
# JSON (default)
65
+
python producer.py
66
+
67
+
# Protobuf
68
+
MESSAGE_FORMAT=protobuf python producer.py
69
+
```
70
+
71
+
### Run Consumer
58
72
59
73
```bash
60
74
python consumer.py # All events
61
75
python consumer.py --event-type X # Filtered by event_type
62
76
python consumer.py --group-id my-group
63
77
```
64
78
65
-
Displays event type, partition, and offset info.
79
+
Displays event type, partition, and offset info. The consumer detects the payload format using the Kafka `content-type` header sent by the producer and falls back to JSON-or-plain-text when the header is missing.
80
+
81
+
Log annotation:
82
+
- Each consumed message line includes a suffix indicating the wire format detected: `[wire=protobuf]`, `[wire=json]`, `[wire=text]`, or `[wire=unknown]`.
Note: The `✅ JSON (...)` prefix reflects that the payload was parsed into a dict (even for Protobuf). The `[wire=...]` suffix shows the on-wire format.
66
88
67
89
---
68
90
69
-
### 🔑 Message Keys and Partitions
91
+
### Message Keys and Partitions
70
92
71
93
The producer now uses the message's `event_type` as the Kafka **key**, which ensures that:
72
94
@@ -99,7 +121,7 @@ To see all partitions used, try increasing the number of unique keys or remove t
99
121
100
122
---
101
123
102
-
### 👥 Consumer Groups and Partition Rebalancing
124
+
### Consumer Groups and Partition Rebalancing
103
125
104
126
Kafka uses consumer groups to distribute the workload of processing messages across multiple consumers.
105
127
@@ -123,7 +145,7 @@ Note: If you have more partitions than consumers, some consumers may receive mul
123
145
124
146
---
125
147
126
-
## 🧪 Running Tests & Coverage
148
+
## Running Tests & Coverage
127
149
128
150
Details could be found in the [separate section](documentation/tests.md).
@@ -192,15 +218,15 @@ KAFKA_TOPIC=my-topic docker compose up -d
192
218
193
219
---
194
220
195
-
## 🧾 About TemplateTasks
221
+
## About TemplateTasks
196
222
197
223
TemplateTasks is a personal software development initiative by Vadim Starichkov, focused on sharing open-source libraries, services, and technical demos.
198
224
199
225
It operates independently and outside the scope of any employment.
200
226
201
227
All code is released under permissive open-source licenses. The legal structure may evolve as the project grows.
202
228
203
-
## 📜 License & Attribution
229
+
## License & Attribution
204
230
205
231
This project is licensed under the **MIT License** - see the [LICENSE](https://github.com/starichkov/kafka-python-demo/blob/main/LICENSE.md) file for details.
0 commit comments