Vorlage simple-producer--vorlage simple-producer--vorlage---lvm-2-tage--easy-path
authorKai Moritz <kai@juplo.de>
Mon, 1 Aug 2022 20:40:27 +0000 (22:40 +0200)
committerKai Moritz <kai@juplo.de>
Tue, 22 Nov 2022 19:22:04 +0000 (20:22 +0100)
pom.xml
src/main/java/de/juplo/kafka/SimpleProducer.java

diff --git a/pom.xml b/pom.xml
index 4c52f37..9bd2418 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 9fcaa6e..4db0082 100644 (file)
@@ -59,43 +59,14 @@ public class SimpleProducer
   {
     final long time = System.currentTimeMillis();
 
-    final ProducerRecord<String, String> record = new ProducerRecord<>(
-        topic,  // Topic
-        key,    // Key
-        value   // Value
-    );
-
-    producer.send(record, (metadata, e) ->
-    {
-      long now = System.currentTimeMillis();
-      if (e == null)
-      {
-        // HANDLE SUCCESS
-        produced++;
-        log.debug(
-            "{} - Sent key={} message={} partition={}/{} timestamp={} latency={}ms",
-            id,
-            record.key(),
-            record.value(),
-            metadata.partition(),
-            metadata.offset(),
-            metadata.timestamp(),
-            now - time
-        );
-      }
-      else
-      {
-        // HANDLE ERROR
-        log.error(
-            "{} - ERROR key={} timestamp={} latency={}ms: {}",
-            id,
-            record.key(),
-            metadata == null ? -1 : metadata.timestamp(),
-            now - time,
-            e.toString()
-        );
-      }
-    });
+    // Aufgabe:
+    // 1. ProducerRecord<String, String> erzeugen
+    // 2. Record mit producer.send(...) verschicken
+    // Dabei beachten:
+    // * Callback implementieren und Erfolg/Fehler logge
+    // * Tipp: Aktuellen Zeitstempel auch im Callback erzeugen und
+    //   Millisekunden berechnen, die bis zum Senden verstrichen sind:
+    //   long now = System.currentTimeMillis(); // Für: now - time
 
     long now = System.currentTimeMillis();
     log.trace(