排除步骤1:
使用group_id="consumer_group_id_001" 和 auto_offset_reset="earliest"
python
from kafka import KafkaConsumer
consumer = KafkaConsumer(bootstrap_servers=["dev-kafka01.test.xxx.cloud:9092"],
enable_auto_commit=True, auto_commit_interval_ms=5000, group_id="test-consumer-group",
auto_offset_reset="earliest")
consumer.subscribe(['add_topic'])
for msg in consumer:
print(msg.key, msg.value)
排除步骤2:
生产者发完消息后,在close中 先执行 producer.flush() ,再执行 producer.close()
python
# -*- coding: utf-8 -*-
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers=["dev-kafka01.test.xxx.cloud:9092"])
producer.send('add_topic', key=b'我是消息键',value=b'我是消息体,我是主角')
producer.flush()
排除步骤3:
使用offset 观看消息是否写到kafka中。