from kafka import KafkaConsumer #导入第三方库 import time from log.log import logger # 与kafka建立连接 consumer = KafkaConsumer('kafka-topic',bootstrap_servers=['ip:9092']) print("连接成功") for message in consumer: #开始消费消息 logger.info("%s value=%s" %(message.topic,message.value)) print ("%s %s value=%s" % (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),message.topic,message.value))