Code & Setup an abgeleitete Versionen angeglichen
authorKai Moritz <kai@juplo.de>
Wed, 25 Sep 2024 16:27:09 +0000 (18:27 +0200)
committerKai Moritz <kai@juplo.de>
Thu, 26 Sep 2024 12:30:28 +0000 (14:30 +0200)
.dockerignore [new file with mode: 0644]
.maven-dockerexclude [new file with mode: 0644]
.maven-dockerinclude [new file with mode: 0644]
pom.xml
src/main/java/de/juplo/kafka/ExampleProducer.java

diff --git a/.dockerignore b/.dockerignore
new file mode 100644 (file)
index 0000000..1ad9963
--- /dev/null
@@ -0,0 +1,2 @@
+*
+!target/*.jar
diff --git a/.maven-dockerexclude b/.maven-dockerexclude
new file mode 100644 (file)
index 0000000..72e8ffc
--- /dev/null
@@ -0,0 +1 @@
+*
diff --git a/.maven-dockerinclude b/.maven-dockerinclude
new file mode 100644 (file)
index 0000000..fd6cecd
--- /dev/null
@@ -0,0 +1 @@
+target/*.jar
diff --git a/pom.xml b/pom.xml
index 987adce..ad7f17a 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -14,6 +14,7 @@
   <groupId>de.juplo.kafka</groupId>
   <artifactId>simple-producer</artifactId>
   <name>Super Simple Producer</name>
+  <description>A Simple Producer, programmed with pure Java, that sends messages via Kafka</description>
   <version>1.0-SNAPSHOT</version>
 
   <properties>
           </archive>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>pl.project13.maven</groupId>
+        <artifactId>git-commit-id-plugin</artifactId>
+      </plugin>
       <plugin>
         <groupId>io.fabric8</groupId>
         <artifactId>docker-maven-plugin</artifactId>
index 51178f5..06e14ef 100644 (file)
@@ -16,9 +16,9 @@ public class ExampleProducer
   private final String topic;
   private final Producer<String, String> 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
     );