import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import javax.annotation.PreDestroy;
public class Application implements ApplicationRunner
{
@Autowired
- Consumer<?, ?> consumer;
+ Consumer<?, ?> kafkaConsumer;
@Autowired
SimpleConsumer simpleConsumer;
@Override
public void run(ApplicationArguments args) throws Exception
- {
- start();
- }
-
- @Async
- public void start()
{
log.info("Starting SimpleConsumer");
simpleConsumer.run();
public void stop() throws ExecutionException, InterruptedException
{
log.info("Signaling SimpleConsumer to quit its work");
- consumer.wakeup();
+ kafkaConsumer.wakeup();
+
+ while (simpleConsumer.isRunning())
+ {
+ log.info("Waiting for SimpleConsumer to finish its work");
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException e) {}
+ }
+ log.info("SimpleConsumer finished its work");
}