khen | b95fe9a | 2016-10-05 11:15:25 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | import threading, logging, time |
| 3 | |
| 4 | from kafka import KafkaConsumer |
| 5 | |
| 6 | |
| 7 | class Consumer(threading.Thread): |
| 8 | daemon = True |
| 9 | |
| 10 | def run(self): |
| 11 | #consumer = KafkaConsumer(bootstrap_servers='10.100.198.220:9092', |
| 12 | consumer = KafkaConsumer(bootstrap_servers='10.0.2.15:9092', |
| 13 | auto_offset_reset='earliest') |
| 14 | consumer.subscribe(['voltha-heartbeat']) |
| 15 | |
| 16 | for message in consumer: |
| 17 | print (message) |
| 18 | |
| 19 | |
| 20 | def main(): |
| 21 | threads = [ |
| 22 | Consumer() |
| 23 | ] |
| 24 | |
| 25 | for t in threads: |
| 26 | t.start() |
| 27 | |
| 28 | time.sleep(3000) |
| 29 | |
| 30 | if __name__ == "__main__": |
| 31 | logging.basicConfig( |
| 32 | format='%(asctime)s.%(msecs)s:%(name)s:%(thread)d:%(levelname)s:%(process)d:%(message)s', |
| 33 | level=logging.INFO |
| 34 | ) |
| 35 | main() |
| 36 | |