From: Kai Moritz Date: Tue, 31 Jan 2023 18:31:22 +0000 (+0100) Subject: Code & Setup für acks-Übung überarbeitet X-Git-Tag: supersimple-producer--acks X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=5920903147fce2b51f388b709c2ac1eddf522a2c;p=demos%2Fkafka%2Ftraining Code & Setup für acks-Übung überarbeitet --- diff --git a/README.sh b/README.sh index b10c65a..b03b79b 100755 --- a/README.sh +++ b/README.sh @@ -1,6 +1,6 @@ #!/bin/bash -IMAGE=juplo/supersimple-producer:1.0-SNAPSHOT +IMAGE=juplo/supersimple-producer-endless:1.0-SNAPSHOT if [ "$1" = "cleanup" ] then diff --git a/docker-compose.yml b/docker-compose.yml index e910e9c..efdadd5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -107,26 +107,25 @@ services: - kafka-3 acks-all: - image: juplo/supersimple-producer:1.0-SNAPSHOT + image: juplo/supersimple-producer-endless:1.0-SNAPSHOT environment: spring.kafka.bootstrap-servers: kafka:9092 spring.kafka.client-id: acks-all spring.kafka.producer.acks: all + command: --key=klaus acks-1: - image: juplo/supersimple-producer:1.0-SNAPSHOT + image: juplo/supersimple-producer-endless:1.0-SNAPSHOT environment: spring.kafka.bootstrap-servers: kafka:9092 spring.kafka.client-id: acks-1 spring.kafka.producer.acks: 1 + command: --key=peter acks-0: - image: juplo/supersimple-producer:1.0-SNAPSHOT + image: juplo/supersimple-producer-endless:1.0-SNAPSHOT environment: spring.kafka.bootstrap-servers: kafka:9092 spring.kafka.client-id: acks-0 spring.kafka.producer.acks: 0 - - consumer: - image: juplo/toolbox - command: kafkacat -C -b kafka:9092 -t test -o 0 -f'p=%p|o=%o|k=%k|v=%s\n' + command: --key=ute diff --git a/pom.xml b/pom.xml index ccab861..cab26a7 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ de.juplo.kafka - supersimple-producer + supersimple-producer-endless Super Simple Producer Most minimal Kafka Producer ever! 1.0-SNAPSHOT diff --git a/src/main/java/de/juplo/kafka/Application.java b/src/main/java/de/juplo/kafka/Application.java index 4632e22..2dc5756 100644 --- a/src/main/java/de/juplo/kafka/Application.java +++ b/src/main/java/de/juplo/kafka/Application.java @@ -10,6 +10,8 @@ import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.support.SendResult; import org.springframework.util.concurrent.ListenableFuture; +import java.util.List; + @Slf4j @SpringBootApplication @@ -21,10 +23,17 @@ public class Application implements ApplicationRunner @Override public void run(ApplicationArguments args) { + List keys = args.getOptionValues("key"); + if (keys == null || keys.size() != 1) + { + log.error("Exactly one key has to be given with --key"); + return; + } + String key = keys.get(0); for (int i = 0; true; i++) { ListenableFuture> listenableFuture = - kafkaTemplate.send("test", Long.toString(i%10), Long.toString(i)); + kafkaTemplate.send("test", key, Long.toString(i)); listenableFuture.addCallback( result -> log.info(