Guest User

Untitled

a guest
Jul 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #!/usr/bin/env jython
  2.  
  3. import os
  4. import sys
  5. sys.path.extend(["lib/"+x for x in os.listdir("lib") if x.endswith('.jar')])
  6. sys.path.extend(["dist/"+x for x in os.listdir("dist") if x.endswith('.jar')])
  7.  
  8. import jarray
  9. from kafka.api import FetchRequest
  10. from kafka.consumer import SimpleConsumer
  11.  
  12. consumer = SimpleConsumer("localhost", 9092, 10000, 1024000)
  13. req = FetchRequest("test", 0, 0, 1000000)
  14. messageset = consumer.fetch(req) # ByteBufferMessageSet
  15.  
  16. msgs = list(messageset.elements()) # [kafka.message.Message]
  17. for msg in msgs:
  18. buf = msg.payload() # java.nio.HeapByteBuffer
  19. barray = jarray.zeros(buf.remaining(), 'b')
  20. buf.get(barray)
  21. print barray.tostring()
Add Comment
Please, Sign In to add comment