Created
October 9, 2019 13:46
-
-
Save recursivecodes/ea65c4810d3e26626e752ab5fabd2f75 to your computer and use it in GitHub Desktop.
CompatibleConsumer.java
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
try { | |
consumer.subscribe(Collections.singletonList( topicName ) ); | |
while(true) { | |
Duration duration = Duration.ofMillis(1000); | |
ConsumerRecords<Long, String> consumerRecords = consumer.poll(duration); | |
consumerRecords.forEach(record -> { | |
System.out.println("Record Key " + record.key()); | |
System.out.println("Record value " + record.value()); | |
System.out.println("Record partition " + record.partition()); | |
System.out.println("Record offset " + record.offset()); | |
}); | |
// commits the offset of record to broker. | |
consumer.commitAsync(); | |
} | |
} | |
catch(WakeupException e) { | |
// do nothing, shutting down... | |
} | |
finally { | |
System.out.println("closing consumer"); | |
consumer.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment