WIP:TaskExecutor-NEU
[demos/kafka/training] / src / main / java / de / juplo / kafka / Application.java
index f227bbe..a9b466d 100644 (file)
@@ -1,26 +1,42 @@
 package de.juplo.kafka;
 
 import lombok.extern.slf4j.Slf4j;
+import org.apache.kafka.clients.consumer.Consumer;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
+import javax.annotation.PreDestroy;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Future;
+
 
 @SpringBootApplication
 @Slf4j
 public class Application implements ApplicationRunner
 {
   @Autowired
-  EndlessConsumer endlessConsumer;
-
+  Executor executor;
+  @Autowired
+  Consumer<?, ?> kafkaConsumer;
+  @Autowired
+  SimpleConsumer simpleConsumer;
 
   @Override
   public void run(ApplicationArguments args) throws Exception
   {
-    log.info("Starting EndlessConsumer");
-    endlessConsumer.start();
+    log.info("Starting SimpleConsumer");
+    executor.execute(simpleConsumer);
+  }
+
+  @PreDestroy
+  public void shutdown() throws ExecutionException, InterruptedException
+  {
+    log.info("Signaling SimpleConsumer to quit its work");
+    kafkaConsumer.wakeup();
   }