From 194ba0860041210db7daafc3017c6c1b44962e87 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 25 Sep 2024 18:27:09 +0200 Subject: [PATCH] Code & Setup an abgeleitete Versionen angeglichen --- .dockerignore | 2 ++ .maven-dockerexclude | 1 + .maven-dockerinclude | 1 + pom.xml | 5 +++++ src/main/java/de/juplo/kafka/ExampleProducer.java | 12 +++++++----- 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 .maven-dockerexclude create mode 100644 .maven-dockerinclude diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1ad9963 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +* +!target/*.jar diff --git a/.maven-dockerexclude b/.maven-dockerexclude new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/.maven-dockerexclude @@ -0,0 +1 @@ +* diff --git a/.maven-dockerinclude b/.maven-dockerinclude new file mode 100644 index 0000000..fd6cecd --- /dev/null +++ b/.maven-dockerinclude @@ -0,0 +1 @@ +target/*.jar diff --git a/pom.xml b/pom.xml index 987adce..ad7f17a 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ de.juplo.kafka simple-producer Super Simple Producer + A Simple Producer, programmed with pure Java, that sends messages via Kafka 1.0-SNAPSHOT @@ -66,6 +67,10 @@ + + pl.project13.maven + git-commit-id-plugin + io.fabric8 docker-maven-plugin diff --git a/src/main/java/de/juplo/kafka/ExampleProducer.java b/src/main/java/de/juplo/kafka/ExampleProducer.java index 51178f5..06e14ef 100644 --- a/src/main/java/de/juplo/kafka/ExampleProducer.java +++ b/src/main/java/de/juplo/kafka/ExampleProducer.java @@ -16,9 +16,9 @@ public class ExampleProducer private final String topic; private final Producer producer; - private long produced = 0; private volatile boolean running = true; private volatile boolean done = false; + private long produced = 0; public ExampleProducer(String broker, String topic, String clientId) { @@ -39,13 +39,16 @@ public class ExampleProducer try { - for (; running ; i++) + for (; running; i++) { send(Long.toString(i%10), Long.toString(i)); Thread.sleep(500); } } - catch (InterruptedException e) {} + catch (Exception e) + { + log.error("{} - Unexpected error: {}!", id, e.toString()); + } finally { log.info("{}: Closing the KafkaProducer", id); @@ -99,9 +102,8 @@ public class ExampleProducer long now = System.currentTimeMillis(); log.trace( - "{} - Queued #{} key={} latency={}ms", + "{} - Queued message with key={} latency={}ms", id, - value, record.key(), now - time ); -- 2.20.1