V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
css3
V2EX  ›  Kafka

Python 消费 kafka 时无限挂起,如何定位原因

  •  
  •   css3 · 2021-06-18 20:57:27 +08:00 · 745 次点击
    这是一个创建于 1014 天前的主题,其中的信息可能已经有所发展或是发生改变。

    直接通过 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)
    
    
    
    2 条回复    2021-06-18 21:12:06 +08:00
    tcpdump
        1
    tcpdump  
       2021-06-18 21:03:12 +08:00
    换消费组啊,你都消费了,偏移肯定是最后的
    或者 auto_offset_reset 设置为最早吧
    跟 Python 没关系
    css3
        2
    css3  
    OP
       2021-06-18 21:12:06 +08:00 via iPhone
    @tcpdump 换了也不行,试过了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3529 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:51 · PVG 12:51 · LAX 21:51 · JFK 00:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.