From: Kai Moritz Date: Sat, 14 Oct 2023 12:59:16 +0000 (+0200) Subject: "Endlose" Version des Super-Simplen Producers X-Git-Tag: spring/endless-producer-DEPRECATED X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=d848fcf30549f3874d90bdb5c462e1be0c5a0d0b;p=demos%2Fkafka%2Ftraining "Endlose" Version des Super-Simplen Producers * Problem: Beendet sich nicht sauber... * Grund: Die Endlosschleife läuft _in_ der Initialisierungs-Phase! --- diff --git a/README.sh b/README.sh index c39fe5b..ebafed7 100755 --- a/README.sh +++ b/README.sh @@ -1,6 +1,6 @@ #!/bin/bash -IMAGE=juplo/supersimple-producer:1.0-SNAPSHOT +IMAGE=juplo/endless-spring-producer:1.0-SNAPSHOT if [ "$1" = "cleanup" ] then @@ -27,8 +27,8 @@ docker-compose -f docker/docker-compose.yml run --rm cli cub kafka-ready -b kafk docker-compose -f docker/docker-compose.yml up -t0 -d cli docker-compose -f docker/docker-compose.yml ps -docker-compose -f docker/docker-compose.yml up producer +docker-compose -f docker/docker-compose.yml up -d producer -# tag::kafkacat[] -kafkacat -b :9092 -t test -e -f'topic=%t\tpartition=%p\toffset=%o\tkey=%k\tvalue=%s\n' -# end::kafkacat[] +kafkacat -b :9092 -t test -c 100 -f'topic=%t\tpartition=%p\toffset=%o\tkey=%k\tvalue=%s\n' + +docker-compose stop producer diff --git a/pom.xml b/pom.xml index ee60567..244f8df 100644 --- a/pom.xml +++ b/pom.xml @@ -12,9 +12,9 @@ de.juplo.kafka - supersimple-producer - Super Simple Producer - Most minimal Kafka Producer ever! + endless-spring-producer + Super Simple Endless Producer + Most minimal endless 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 5e123dd..e3a46d9 100644 --- a/src/main/java/de/juplo/kafka/Application.java +++ b/src/main/java/de/juplo/kafka/Application.java @@ -11,7 +11,6 @@ import org.springframework.kafka.support.SendResult; import org.springframework.util.concurrent.ListenableFuture; -// tag::supersimple[] @Slf4j @SpringBootApplication public class Application implements ApplicationRunner @@ -22,14 +21,10 @@ public class Application implements ApplicationRunner @Override public void run(ApplicationArguments args) { - for (int i = 0; i < 100; i++) + for (int i = 0; true; i++) { - // end::supersimple[] - // tag::callback[] ListenableFuture> listenableFuture = - // tag::supersimple[] kafkaTemplate.sendDefault(Long.toString(i%10), Long.toString(i)); - // end::supersimple[] listenableFuture.addCallback( result -> log.info( @@ -39,8 +34,6 @@ public class Application implements ApplicationRunner result.getRecordMetadata().partition(), result.getRecordMetadata().offset()), e -> log.error("ERROR sendig message", e)); - // end::callback[] - // tag::supersimple[] } } @@ -49,4 +42,3 @@ public class Application implements ApplicationRunner SpringApplication.run(Application.class, args); } } -// end::supersimple[]