Skip to content

Instantly share code, notes, and snippets.

@victorarias
Last active March 21, 2018 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorarias/b7c4cfeab648e20bcea718083f6de00a to your computer and use it in GitHub Desktop.
Save victorarias/b7c4cfeab648e20bcea718083f6de00a to your computer and use it in GitHub Desktop.
public static void main(String[] args) {
KafkaConsumer consumer = new KafkaConsumer(getProperties());
consumer.subscribe(Collections.singletonList("bids"));
System.out.println("Starting polling from Java bids consumer:");
while(true) {
ConsumerRecords<String, String> records = consumer.poll(100);
for (ConsumerRecord<String, String> record : records) {
String message = String.format("key: %s, payload: %s", record.key(), record.value());
System.out.println(message);
}
consumer.commitSync();
}
}
private static Properties getProperties() {
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("group.id", "HelloConsumer");
props.put("key.deserializer",
"org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer",
"org.apache.kafka.common.serialization.StringDeserializer");
return props;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment