From 4aff371c1aaf01c07b577fabdf09fd577456adec Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 31 Jan 2023 19:31:22 +0100 Subject: [PATCH] =?utf8?q?Code=20&=20Setup=20f=C3=BCr=20acks-=C3=9Cbung=20?= =?utf8?q?=C3=BCberarbeitet?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- README.sh | 2 +- docker/docker-compose.yml | 9 ++++++--- pom.xml | 2 +- src/main/java/de/juplo/kafka/Application.java | 11 ++++++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.sh b/README.sh index e1cf1d0..7264308 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/docker-compose.yml b/docker/docker-compose.yml index 2339e29..cb63b42 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -212,28 +212,31 @@ 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.template.default-topic: test 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.template.default-topic: test 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.template.default-topic: test spring.kafka.producer.acks: 0 + command: --key=ute consumer: image: juplo/toolbox diff --git a/pom.xml b/pom.xml index ee60567..2104137 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 fb3a523..3828a7a 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; + // tag::supersimple[] @Slf4j @@ -22,13 +24,20 @@ 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++) { // end::supersimple[] // tag::callback[] ListenableFuture> listenableFuture = // tag::supersimple[] - kafkaTemplate.sendDefault(Long.toString(i%10), Long.toString(i)); + kafkaTemplate.sendDefault(key, Long.toString(i)); // end::supersimple[] listenableFuture.addCallback( -- 2.20.1