Kafka Consumer
基本用法 topic_name = 'my_topic_name' consumer = KafkaConsumer(topic_name, bootstrap_servers=['172.16.89.80:9092']) # consumer是一个消息队列,当后台有消息时,这个消息队列就会自动增加.所以遍历也总是会有数据,当消息队列中没有数据时,就会堵塞等待消息到来 for msg in consumer: recv = "%s:%d:%d: key=%s value=%s" % (msg.topic, msg.partition, msg.offset, msg.key, msg.value) print recv 指定分区、offset、消费组 #encoding:utf8 from kafka import KafkaConsumer, TopicPartition my_topic = "my_topic_name" # 指定需要消费的主题 consumer = KafkaConsumer( bootstrap_servers = "192.168.70.221:19092,192.168.70.222:19092,192.168.70.223:19092", # kafka集群地址 group_id = "my_group_a", # 消费组id enable_auto