From 2116e3554b29b4f2536998a7b5e5f0a68aaf3c37 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 1 Aug 2022 22:40:27 +0200 Subject: [PATCH] Vorlage --- pom.xml | 4 -- .../java/de/juplo/kafka/SimpleProducer.java | 45 ++++--------------- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/pom.xml b/pom.xml index 4c52f37..9bd2418 100644 --- a/pom.xml +++ b/pom.xml @@ -33,10 +33,6 @@ - - pl.project13.maven - git-commit-id-plugin - org.apache.maven.plugins maven-dependency-plugin diff --git a/src/main/java/de/juplo/kafka/SimpleProducer.java b/src/main/java/de/juplo/kafka/SimpleProducer.java index 9fcaa6e..4db0082 100644 --- a/src/main/java/de/juplo/kafka/SimpleProducer.java +++ b/src/main/java/de/juplo/kafka/SimpleProducer.java @@ -59,43 +59,14 @@ public class SimpleProducer { final long time = System.currentTimeMillis(); - final ProducerRecord 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 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( -- 2.20.1