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<?, ?> consumer;
+ @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");
+ consumer.wakeup();
}