import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
public class Application implements ApplicationRunner
{
@Autowired
- Executor executor;
+ ExecutorService executorService;
@Autowired
Consumer<?, ?> kafkaConsumer;
@Autowired
SimpleConsumer simpleConsumer;
+ Future<?> consumerJob;
+
@Override
public void run(ApplicationArguments args) throws Exception
{
log.info("Starting SimpleConsumer");
- executor.execute(simpleConsumer);
+ consumerJob = executorService.submit(simpleConsumer);
}
@PreDestroy
{
log.info("Signaling SimpleConsumer to quit its work");
kafkaConsumer.wakeup();
+ log.info("Waiting for SimpleConsumer to finish its work");
+ consumerJob.get();
+ log.info("SimpleConsumer finished its work");
}
import org.springframework.kafka.core.ConsumerFactory;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
@Configuration
@EnableConfigurationProperties({ KafkaProperties.class, ApplicationProperties.class })