css3
V2EX  ›  Kafka

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

  •  
  •   css3 · Jun 18, 2021 · 1437 views
    This topic created in 1806 days ago, the information mentioned may be changed or developed.

    直接通过 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 replies    2021-06-18 21:12:06 +08:00
    tcpdump
        1
    tcpdump  
       Jun 18, 2021
    换消费组啊,你都消费了,偏移肯定是最后的
    或者 auto_offset_reset 设置为最早吧
    跟 Python 没关系
    css3
        2
    css3  
    OP
       Jun 18, 2021 via iPhone
    @tcpdump 换了也不行,试过了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2876 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 07:22 · PVG 15:22 · LAX 00:22 · JFK 03:22
    ♥ Do have faith in what you're doing.