1 package de.juplo.kafka;
3 import lombok.extern.slf4j.Slf4j;
4 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.boot.ApplicationArguments;
6 import org.springframework.boot.ApplicationRunner;
7 import org.springframework.boot.SpringApplication;
8 import org.springframework.boot.autoconfigure.SpringBootApplication;
10 import javax.annotation.PreDestroy;
11 import java.util.concurrent.ExecutorService;
12 import java.util.concurrent.TimeUnit;
15 @SpringBootApplication
17 public class Application implements ApplicationRunner
20 EndlessConsumer endlessConsumer;
22 ExecutorService executor;
26 public void run(ApplicationArguments args) throws Exception
28 log.info("Starting EndlessConsumer");
29 endlessConsumer.start();
33 public void shutdown()
37 log.info("Stopping EndlessConsumer");
38 endlessConsumer.stop();
40 catch (IllegalStateException e)
42 log.info("Was already stopped: {}", e.toString());
46 log.error("Unexpected exception while stopping EndlessConsumer: {}", e);
51 log.info("Shutting down the ExecutorService.");
53 log.info("Waiting 5 seconds for the ExecutorService to terminate...");
54 executor.awaitTermination(5, TimeUnit.SECONDS);
56 catch (InterruptedException e)
58 log.error("Exception while waiting for the termination of the ExecutorService: {}", e);
62 if (!executor.isTerminated())
64 log.warn("Forcing shutdown of ExecutorService!");
67 .forEach(runnable -> log.warn("Unprocessed task: {}", runnable.getClass().getSimpleName()));
69 log.info("Shutdow of ExecutorService finished");
74 public static void main(String[] args)
76 SpringApplication.run(Application.class, args);