KafkaConsumerCommon.java 1.0 KB

1234567891011121314151617181920212223242526
  1. import org.apache.kafka.clients.consumer.ConsumerRecord;
  2. import org.apache.kafka.clients.consumer.ConsumerRecords;
  3. import org.apache.kafka.common.serialization.StringDeserializer;
  4. public class KafkaConsumerCommon {
  5. public static final String STRING_DESERIALIZER = StringDeserializer.class.getName();
  6. public static final Integer TIMEOUT = 200;
  7. protected static Boolean started = false;
  8. protected static Integer pass = 0;
  9. static void process(ConsumerRecords<String, String> records) {
  10. if (!started) {
  11. started = true;
  12. System.out.printf("Started");
  13. }
  14. // for (ConsumerRecord<String, String> cr : records.records(TOPIC)) {
  15. // System.out.printf("\t\tKey: %s Value: %s\n", cr.key(), cr.value());
  16. // }
  17. for (ConsumerRecord<String, String> cr : records) {
  18. System.out.printf("Pass: %d/%d Topic: %s Partition: %d, Offset: %d, Key: %s Value: %s\n",
  19. pass, records.count(),
  20. cr.key(), cr.partition(), cr.offset(), cr.key(), cr.value());
  21. }
  22. pass++;
  23. }
  24. }