File tree 3 files changed +53
-1
lines changed
3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -364,6 +364,38 @@ Group id group-XX - Consumer id: consumer-group-XX-1-421db3e2-6501-45b1-acfd-275
364
364
Group id group-XX - Consumer id: consumer-group-XX-1-421db3e2-6501-45b1-acfd-275ce8d18368 - Topic: users_clicks - Partition: 1 - Offset: 0 - Key: frank - Value: 1
365
365
----
366
366
367
+ === Python Consumer
368
+
369
+ Install python lib _confluent-kafka_:
370
+
371
+ [source,bash]
372
+ ----
373
+ pip install confluent-kafka
374
+ ----
375
+
376
+ Create topic:
377
+
378
+ [source,bash]
379
+ ----
380
+ kafka-topics --bootstrap-server localhost:9092 --create --topic kafka-topic --replication-factor 1 --partitions 1
381
+ ----
382
+
383
+ Run producer:
384
+
385
+ [source,bash]
386
+ ----
387
+ cd kafka-python-producer
388
+ python producer.py
389
+ ----
390
+
391
+ Run consumer:
392
+
393
+ [source,bash]
394
+ ----
395
+ cd kafka-python-consumer
396
+ python consumer.py
397
+ ----
398
+
367
399
== Admin & Management
368
400
369
401
=== Kafka CLI Tools
Original file line number Diff line number Diff line change
1
+ from confluent_kafka import Consumer
2
+
3
+ conf = {'bootstrap.servers' : "localhost:9092" , 'group.id' : 'pythongroup' , 'auto.offset.reset' : 'earliest' }
4
+ topic = 'test-python'
5
+
6
+ consumer = Consumer (conf )
7
+
8
+ consumer .subscribe ([topic ])
9
+
10
+ while True :
11
+ msg = consumer .poll (1.0 )
12
+
13
+ if msg is None :
14
+ continue
15
+ if msg .error ():
16
+ print ("Error: {}" .format (msg .error ()))
17
+ continue
18
+
19
+ print ('Message: {}' .format (msg .value ().decode ('utf-8' )))
20
+
21
+ consumer .close ()
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ def ack(error, message):
11
11
print ("offset={}" .format (message .offset ()))
12
12
13
13
14
-
15
14
conf = {'bootstrap.servers' : "localhost:9092" }
16
15
17
16
producer = Producer (conf )
You can’t perform that action at this time.
0 commit comments