Guest User

Untitled

a guest
Mar 7th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2. pos = 12345678
  3. from kafka import KafkaConsumer
  4. from kafka import TopicPartition
  5. import time
  6.  
  7. topic = TopicPartition('test',0)
  8.  
  9. # Create connection to Kafka broker
  10. consumer = KafkaConsumer(bootstrap_servers='localhost:9092', group_id='logstash')
  11.  
  12. # Assign partition list for the consumer
  13. consumer.assign([topic])
  14.  
  15. # Get position of next reccord
  16. position = consumer.position(topic)
  17.  
  18. # Specify to fetch the last message
  19. # consumer.seek(topic, position - 1)
  20. consumer.seek(topic, pos)
  21.  
  22. # commit offset -- http://kafka-python.readthedocs.io/en/master/apidoc/kafka.consumer.html
  23. consumer.commit()
  24.    
  25. # Close connection to broker
  26. consumer.close()
Advertisement
Add Comment
Please, Sign In to add comment