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

python 使用 kafka 系列问题 topics 为空

  •  
  •   QuinlanGgame · 2016-12-07 23:13:42 +08:00 · 2254 次点击
    这是一个创建于 2702 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码

    from pykafka import KakaClient
    client = KafkaClient(
    zookeeper_hosts='127.0.0.1:2181')
    print client, dir(client), client.brokers, client.cluster
    print client.topics
    

    输出

    {'test': None, 'syslog-topic': None}
    

    我在 shell 里面通过

    >>bin/kafka-console-producer.sh --broker-list localhost:9092 --topic syslog-topic
    >>asdkasdjkasjd
    

    输入了一些字符串 为什么 topics 字典里面还是 None

    4 条回复    2016-12-08 16:46:21 +08:00
    QuinlanGgame
        1
    QuinlanGgame  
    OP
       2016-12-07 23:54:02 +08:00
    哎呀呀,新手跪求大神帮忙
    phttc
        2
    phttc  
       2016-12-08 09:10:01 +08:00
    消息订阅啊。。。你客户端得去调用订阅。。。
    QuinlanGgame
        3
    QuinlanGgame  
    OP
       2016-12-08 11:46:18 +08:00
    @phttc 我代码里面获取到了这个 topics ,这个字典的 value 是个 none ,不应该是 Topic 对象么?是 Topic 对象的话,才可以去 consume 的吧?
    baocaixiong
        4
    baocaixiong  
       2016-12-08 16:46:21 +08:00
    print client.topics['test'] 有惊喜
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2243 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 09:27 · PVG 17:27 · LAX 02:27 · JFK 05:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.