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;
10 import org.springframework.scheduling.annotation.EnableAsync;
12 import javax.annotation.PreDestroy;
13 import java.util.concurrent.ExecutionException;
16 @SpringBootApplication
19 public class Application implements ApplicationRunner
22 Consumer<?, ?> kafkaConsumer;
24 SimpleConsumer simpleConsumer;
27 public void run(ApplicationArguments args) throws Exception
29 log.info("Starting SimpleConsumer");
34 public void stop() throws ExecutionException, InterruptedException
36 log.info("Signaling SimpleConsumer to quit its work");
37 kafkaConsumer.wakeup();
39 while (simpleConsumer.isRunning())
41 log.info("Waiting for SimpleConsumer to finish its work");
46 catch (InterruptedException e) {}
48 log.info("SimpleConsumer finished its work");
52 public static void main(String[] args)
54 SpringApplication.run(Application.class, args);