From: Kai Moritz Date: Sat, 2 Apr 2022 13:09:37 +0000 (+0200) Subject: Der Producer schreibt alle Nachrichten mit `null` als Key X-Git-Tag: notnagel~3 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=50953aaa727c34bed1898b7442148cca9181f6d8;p=demos%2Fkafka%2Ftraining Der Producer schreibt alle Nachrichten mit `null` als Key --- diff --git a/README.sh b/README.sh index 3ec2781..884ddb5 100755 --- 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 diff --git a/docker-compose.yml b/docker-compose.yml index d715e66..9c92485 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ de.juplo.kafka - endless-producer - Endless Producer: a Simple Producer that endlessly writes numbers into a topic + nullkey-producer + Endless Producer: a Simple Producer that endlessly writes numbers into a topic without a key 1.0-SNAPSHOT diff --git a/src/main/java/de/juplo/kafka/EndlessProducer.java b/src/main/java/de/juplo/kafka/EndlessProducer.java index 8b3743d..98a1781 100644 --- a/src/main/java/de/juplo/kafka/EndlessProducer.java +++ b/src/main/java/de/juplo/kafka/EndlessProducer.java @@ -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 record = new ProducerRecord<>( topic, // Topic - key, // Key + null, // Key value // Value );