Last active
March 21, 2018 20:31
-
-
Save victorarias/b7c4cfeab648e20bcea718083f6de00a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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