from kafka import KafkaConsumer
from kafka.errors import kafka_errors
import traceback
consumer = KafkaConsumer(
'topic_001',
bootstrap_servers=':9092',
group_id='test')
try:
for message in consumer:
print(message)
except kafka_errors: # 抛出kafka_errors
traceback.format_exc()
执行 .../TestProj36/kafkaTestConsumerMessage.py
ConsumerRecord(topic='topic_001', partition=0, offset=1, timestamp=1640251953252, timestamp_type=0, key=b'"mytopic"', value=b'"{'msg': 'hello kafka!'}"', checksum=2046109647, serialized_key_size=9, serialized_value_size=25)
python3.6环境测试



