Der Producer schreibt alle Nachrichten mit `null` als Key
authorKai Moritz <kai@juplo.de>
Sat, 2 Apr 2022 13:09:37 +0000 (15:09 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 2 Apr 2022 17:42:22 +0000 (19:42 +0200)
README.sh
docker-compose.yml
pom.xml
src/main/java/de/juplo/kafka/EndlessProducer.java

index 3ec2781..884ddb5 100755 (executable)
--- a/README.sh
+++ b/README.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-IMAGE=juplo/endless-producer:1.0-SNAPSHOT
+IMAGE=juplo/nullkey-producer:1.0-SNAPSHOT
 
 if [ "$1" = "cleanup" ]
 then
index d715e66..9c92485 100644 (file)
@@ -37,7 +37,7 @@ services:
     command: sleep infinity
 
   producer:
-    image: juplo/endless-producer:1.0-SNAPSHOT
+    image: juplo/nullkey-producer:1.0-SNAPSHOT
     ports:
       - 8000:8080
     environment:
diff --git a/pom.xml b/pom.xml
index 267e035..7a7ac25 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -12,8 +12,8 @@
   </parent>
 
   <groupId>de.juplo.kafka</groupId>
-  <artifactId>endless-producer</artifactId>
-  <name>Endless Producer: a Simple Producer that endlessly writes numbers into a topic</name>
+  <artifactId>nullkey-producer</artifactId>
+  <name>Endless Producer: a Simple Producer that endlessly writes numbers into a topic without a key</name>
   <version>1.0-SNAPSHOT</version>
 
   <dependencies>
index 8b3743d..98a1781 100644 (file)
@@ -55,7 +55,7 @@ public class EndlessProducer implements Runnable
     {
       for (; running; i++)
       {
-        send(Long.toString(i%10), Long.toString(i));
+        send(Long.toString(i));
 
         if (throttleMs > 0)
         {
@@ -86,13 +86,13 @@ public class EndlessProducer implements Runnable
     }
   }
 
-  void send(String key, String value)
+  void send(String value)
   {
     final long time = System.currentTimeMillis();
 
     final ProducerRecord<String, String> record = new ProducerRecord<>(
         topic,  // Topic
-        key,    // Key
+        null,   // Key
         value   // Value
     );