I'm doing Python Kafka (trying to use kafka.consumer.SimpleConsumer or kafka.consumer.simple.SimpleConsumer at http://kafka-python.readthedocs.org/en/latest/apidoc/kafka.consumer.html ) when I run the following a piece of code, it will work all the time, even if all messages are consumed. I hope the consumer stops if he consumes all messages. How to do it? Also, I have no idea how to use the stop () function (which is in the base class kafka.consumer.base.Consumer).
UPDATE
I used a signal handler to call the consumer.stop () method. Some error messages were printed on the screen. But the program is still stuck in the loop. When new messages appeared, the consumer consumed and printed them. I also tried client.close (). But the same result.
I need several ways to terminate the for-loop gracefully.
client = KafkaClient("localhost:9092") consumer = SimpleConsumer(client, "test-group", "test") consumer.seek(0, 2)# (0,2) and (0,0) for message in consumer: print "Offset:", message.offset print "Value:", message.message.value
Any help is appreciated. Thanks.
python apache-kafka kafka-consumer-api kafka-python
Bae
source share