这里提供一个python脚本,监控kafka消息的:
# -*- coding: utf-8 -*-
def monitorkafka(topic_name):
client_monitor = KafkaClient(hosts='127.0.0.1:9092')
topic = client_monitor.topics[topic_name]
balanced_consumer = topic.get_balanced_consumer(
reset_offset_on_start=False,
consumer_group=topic_name,
auto_commit_enable=True,
auto_commit_interval_ms=1000,
zookeeper_connect='127.0.0.1:2181')
for message in balanced_consumer:
if message is not None:
print("*"*100)
print(str(message.offset) + '\t' + message.value)
# balanced_consumer.commit_offset()
balanced_consumer
if __name__ == '__main__':
monitorkafka("topic_name")