
4

Python Kafka Basics
source link: https://fuzzyblog.io/blog/python/2020/04/16/python-kafka-basics.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python Kafka Basics
Apr 16, 2020
This is a starting point blog post where different things I learn about using Python Kafka will be documented.
Getting the Value out of a Consumer Record
The output of a Python Kafka call is a Consumer Record which is a "set of named tuples (blah blah blah)" where what you actually want is the value tuple. This can be gotten with the .value attribute:
#!/usr/bin/env python
from kafka import KafkaConsumer
consumer = KafkaConsumer(
'dimon_tcpdump',
group_id='zhg_group',
value_deserializer=lambda m: json.loads(m.decode('utf-8')),
bootstrap_servers='192.168.100.9:9092'
)
for msg in consumer:
# this is what you actually want;
print msg.value
# process msg here
See Also
Posted In: #kafka
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK