import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.annotation.Bean;
-import org.springframework.kafka.core.ConsumerFactory;
+import org.springframework.scheduling.annotation.EnableAsync;
import javax.annotation.PreDestroy;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.ExecutionException;
@SpringBootApplication
+@EnableAsync
@Slf4j
public class Application implements ApplicationRunner
{
@Autowired
- Consumer<String, Message> consumer;
+ Consumer<?, ?> consumer;
@Autowired
SimpleConsumer simpleConsumer;
-
@Override
public void run(ApplicationArguments args) throws Exception
{
- log.info("Starting EndlessConsumer");
+ log.info("Starting SimpleConsumer");
simpleConsumer.start();
}
@PreDestroy
- public void shutdown()
+ public void stop() throws ExecutionException, InterruptedException
{
- log.info("Signaling the consumer to quit its work");
+ log.info("Signaling SimpleConsumer to quit its work");
consumer.wakeup();
}
- @Bean(destroyMethod = "close")
- public Consumer<String, Message> kafkaConsumer(ConsumerFactory<String, Message> factory)
- {
- return factory.createConsumer();
- }
-
public static void main(String[] args)
{