From d53fff8f9365e1f49278bc312e12930c04546ca0 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 12 Nov 2022 10:49:30 +0100 Subject: [PATCH] supersimple-producer noch weiter vereinfacht --- docker-compose.yml | 1 - src/main/java/de/juplo/kafka/Application.java | 38 +------------------ 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4ddf59a..34bb5f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -106,4 +106,3 @@ services: environment: spring.kafka.bootstrap-servers: kafka:9092 spring.kafka.client-id: producer - command: --num=3 diff --git a/src/main/java/de/juplo/kafka/Application.java b/src/main/java/de/juplo/kafka/Application.java index dda9b11..91b157a 100644 --- a/src/main/java/de/juplo/kafka/Application.java +++ b/src/main/java/de/juplo/kafka/Application.java @@ -10,15 +10,12 @@ import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.support.SendResult; import org.springframework.util.concurrent.ListenableFuture; -import java.util.List; @Slf4j @SpringBootApplication public class Application implements ApplicationRunner { - public final static String ARG_NUM = "num"; - @Autowired KafkaTemplate kafkaTemplate; @@ -41,42 +38,9 @@ public class Application implements ApplicationRunner @Override public void run(ApplicationArguments args) { - int num = 10; - - if (args.containsOption(ARG_NUM)) - { - List numArgs = args.getOptionValues(ARG_NUM); - if (numArgs.size() > 1) - { - log.error( - "Only one occurence of argument {} is allowed, but found: {}", - ARG_NUM, - numArgs.size()); - return; - } - - try - { - num = Integer.parseInt(numArgs.get(0)); - } - catch (NumberFormatException e) - { - log.error("{} is not a number: {}", numArgs.get(0), e.getMessage()); - } - } - - for (int i = 0; i < num; i++) + for (int i = 0; i < 100; i++) { send(Long.toString(i%10), Long.toString(i)); - try - { - Thread.sleep(500); - } - catch (InterruptedException e) - { - log.info("Interrupted after sending {} messages", i); - return; - } } } -- 2.20.1