From: Kai Moritz Date: Fri, 4 Nov 2022 10:05:15 +0000 (+0100) Subject: WIP:TaskExecutor-NEU X-Git-Tag: simple-consumer--json-DEPRECATED~3 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=6bf8a76c6ea35849e063941bcaa744ce50a8f99a;p=demos%2Fkafka%2Ftraining WIP:TaskExecutor-NEU --- diff --git a/src/main/java/de/juplo/kafka/Application.java b/src/main/java/de/juplo/kafka/Application.java index 705f52f..3828b1d 100644 --- a/src/main/java/de/juplo/kafka/Application.java +++ b/src/main/java/de/juplo/kafka/Application.java @@ -7,10 +7,10 @@ import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import javax.annotation.PreDestroy; import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; @@ -19,7 +19,7 @@ import java.util.concurrent.Future; public class Application implements ApplicationRunner { @Autowired - ExecutorService executorService; + ThreadPoolTaskExecutor taskExecutor; @Autowired Consumer kafkaConsumer; @Autowired @@ -31,7 +31,7 @@ public class Application implements ApplicationRunner public void run(ApplicationArguments args) throws Exception { log.info("Starting SimpleConsumer"); - consumerJob = executorService.submit(simpleConsumer); + consumerJob = taskExecutor.submit(simpleConsumer); } @PreDestroy diff --git a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java index 16926fd..de77c60 100644 --- a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java +++ b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java @@ -8,9 +8,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.kafka.core.ConsumerFactory; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - @Configuration @EnableConfigurationProperties({ KafkaProperties.class, ApplicationProperties.class }) diff --git a/src/main/java/de/juplo/kafka/ApplicationProperties.java b/src/main/java/de/juplo/kafka/ApplicationProperties.java index d46a8b3..a4cc8b8 100644 --- a/src/main/java/de/juplo/kafka/ApplicationProperties.java +++ b/src/main/java/de/juplo/kafka/ApplicationProperties.java @@ -7,7 +7,6 @@ import org.springframework.validation.annotation.Validated; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -import java.time.Duration; @ConfigurationProperties(prefix = "simple.consumer") @@ -19,5 +18,4 @@ public class ApplicationProperties @NotNull @NotEmpty private String topic; - private Duration throttle; }