直接通过 kafka 命令行是可以消费的,但通过 python 消费时,一直消费不到,进程也不超时
import time
from kafka import KafkaConsumer
topic1 = 'additional_order'
host = '192.168.14.55:9092'
consume = KafkaConsumer(topic, group_id="group1",
bootstrap_servers=host, auto_offset_reset='latest',
security_protocol='SASL_PLAINTEXT',
sasl_mechanism='PLAIN',
sasl_plain_username='admin',
sasl_plain_password='$%foper!@#$',
api_version=(0, 10)
)
while True:
count += 1
if time.time() - start_time > 1 * 60:
print('超时,退出')
break
msg = consume.poll(1000, 1) # 看上去,进程是一直等候在这里
print(count)
1
tcpdump 2021-06-18 21:03:12 +08:00
换消费组啊,你都消费了,偏移肯定是最后的
或者 auto_offset_reset 设置为最早吧 跟 Python 没关系 |