Handling der Records wie in abgeleiteten Versionen in eigener Methode
authorKai Moritz <kai@juplo.de>
Sun, 29 Sep 2024 12:30:42 +0000 (14:30 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 14 Mar 2025 15:51:25 +0000 (16:51 +0100)
src/main/java/de/juplo/kafka/ExampleConsumer.java

index a945917..553efa1 100644 (file)
@@ -60,16 +60,12 @@ public class ExampleConsumer
         log.info("{} - Received {} messages", id, records.count());
         for (ConsumerRecord<String, String> record : records)
         {
-          consumed++;
-          log.info(
-            "{} - {}: {}/{} - {}={}",
-            id,
-            record.offset(),
+          handleRecord(
             record.topic(),
             record.partition(),
+            record.offset(),
             record.key(),
-            record.value()
-          );
+            record.value());
         }
       }
     }
@@ -91,6 +87,17 @@ public class ExampleConsumer
     }
   }
 
+  private void handleRecord(
+    String topic,
+    Integer partition,
+    Long offset,
+    String key,
+    String value)
+  {
+    consumed++;
+    log.info("{} - {}: {}/{} - {}={}", id, offset, topic, partition, key, value);
+  }
+
 
   public static void main(String[] args) throws Exception
   {