1.pip install kafka-python
2.Producer.py from kafka import KafkaProducer producer = KafkaProducer(bootstrap_servers=‘10.32.106.42:9092‘) for _ in range(1000): producer.send(‘foobar‘, b‘some_message_bytes‘)
3.consumer.py from kafka import KafkaConsumer consumer = KafkaConsumer(‘TestTopic‘,bootstrap_servers=[‘10.32.106.42:9092‘]) for msg in consumer: print("%s:%d:%d: key=%s value=%s" % (msg.topic, msg.partition, msg.offset, msg.key, msg.value))
原文地址:https://www.cnblogs.com/lwhctv/p/10985112.html
时间: 2024-10-19 17:02:47