Vorlage grundlagen/simple-consumer--vorlage---2023-06-signal
authorKai Moritz <kai@juplo.de>
Tue, 22 Nov 2022 18:29:32 +0000 (19:29 +0100)
committerKai Moritz <kai@juplo.de>
Mon, 12 Jun 2023 19:25:10 +0000 (21:25 +0200)
pom.xml
src/main/java/de/juplo/kafka/SimpleConsumer.java

diff --git a/pom.xml b/pom.xml
index 985797b..a07cfaa 100644 (file)
--- a/pom.xml
+++ b/pom.xml
 
   <build>
     <plugins>
-      <plugin>
-        <groupId>pl.project13.maven</groupId>
-        <artifactId>git-commit-id-plugin</artifactId>
-      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
index cee2165..819bdac 100644 (file)
@@ -26,13 +26,7 @@ public class SimpleConsumer
   public SimpleConsumer(String broker, String topic, String groupId, String clientId)
   {
     Properties props = new Properties();
-    props.put("bootstrap.servers", broker);
-    props.put("group.id", groupId); // ID für die Offset-Commits
-    props.put("client.id", clientId); // Nur zur Wiedererkennung
-    props.put("auto.offset.reset", "earliest"); // Von Beginn an lesen
-    props.put("partition.assignment.strategy", "org.apache.kafka.clients.consumer.CooperativeStickyAssignor");
-    props.put("key.deserializer", StringDeserializer.class.getName());
-    props.put("value.deserializer", StringDeserializer.class.getName());
+    // Konfiguration für den Consumer zusammenstellen
 
     this.id = clientId;
     this.topic = topic;
@@ -45,28 +39,15 @@ public class SimpleConsumer
     try
     {
       log.info("{} - Subscribing to topic {}", id, topic);
-      consumer.subscribe(Arrays.asList(topic));
+      // TODO: subscribe!
       running = true;
 
       while (true)
       {
-        ConsumerRecords<String, String> records =
-            consumer.poll(Duration.ofSeconds(1));
-
-        log.info("{} - Received {} messages", id, records.count());
-        for (ConsumerRecord<String, String> record : records)
-        {
-          consumed++;
-          log.info(
-              "{} - {}: {}/{} - {}={}",
-              id,
-              record.offset(),
-              record.topic(),
-              record.partition(),
-              record.key(),
-              record.value()
-          );
-        }
+        // TODO:
+        // Über consumer.poll() Nachrichten abrufen und diese
+        // über log.info() ausgeben und in dem Attribut consumed
+        // zählen.
       }
     }
     catch(WakeupException e)