Skip to content

Instantly share code, notes, and snippets.

@gavinwhyte
Created October 6, 2017 10:38
Show Gist options
  • Save gavinwhyte/bd84df731264d1c1c35b8cc4e5c976aa to your computer and use it in GitHub Desktop.
Save gavinwhyte/bd84df731264d1c1c35b8cc4e5c976aa to your computer and use it in GitHub Desktop.
import java.util
import org.apache.kafka.clients.consumer.KafkaConsumer
import scala.collection.JavaConverters._
object ConsumerExample extends App {
import java.util.Properties
val TOPIC="test"
val props = new Properties()
props.put("bootstrap.servers", "localhost:9092")
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
props.put("group.id", "something")
val consumer = new KafkaConsumer[String, String](props)
consumer.subscribe(util.Collections.singletonList(TOPIC))
while(true){
val records=consumer.poll(100)
for (record<-records.asScala){
println(record)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment