1 package de.juplo.kafka;
3 import lombok.extern.slf4j.Slf4j;
4 import org.apache.kafka.clients.consumer.Consumer;
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.boot.ApplicationArguments;
7 import org.springframework.boot.ApplicationRunner;
8 import org.springframework.boot.SpringApplication;
9 import org.springframework.boot.autoconfigure.SpringBootApplication;
11 import javax.annotation.PreDestroy;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.ExecutorService;
14 import java.util.concurrent.Future;
17 @SpringBootApplication
19 public class Application implements ApplicationRunner
22 ExecutorService executorService;
24 Consumer<?, ?> kafkaConsumer;
26 SimpleConsumer simpleConsumer;
28 Future<?> consumerJob;
31 public void run(ApplicationArguments args) throws Exception
33 log.info("Starting SimpleConsumer");
34 consumerJob = executorService.submit(simpleConsumer);
38 public void shutdown() throws ExecutionException, InterruptedException
40 log.info("Signaling SimpleConsumer to quit its work");
41 kafkaConsumer.wakeup();
42 log.info("Waiting for SimpleConsumer to finish its work");
44 log.info("SimpleConsumer finished its work");
48 public static void main(String[] args)
50 SpringApplication.run(Application.class, args);