public void run(ApplicationArguments args) throws Exception
{
log.info("Starting SimpleConsumer");
- simpleConsumer.run();
+ simpleConsumer.start();
}
@PreDestroy
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.task.TaskExecutor;
import org.springframework.kafka.core.ConsumerFactory;
{
@Bean
public SimpleConsumer endlessConsumer(
+ TaskExecutor taskExecutor,
Consumer<String, String> kafkaConsumer,
KafkaProperties kafkaProperties,
ApplicationProperties applicationProperties)
{
return
new SimpleConsumer(
+ taskExecutor,
kafkaProperties.getClientId(),
applicationProperties.getTopic(),
kafkaConsumer);
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.common.errors.WakeupException;
-import org.springframework.scheduling.annotation.Async;
+import org.springframework.core.task.TaskExecutor;
import java.time.Duration;
import java.util.Arrays;
@Slf4j
@RequiredArgsConstructor
-public class SimpleConsumer
+public class SimpleConsumer implements Runnable
{
+ private final TaskExecutor taskExecutor;
private final String id;
private final String topic;
private final Consumer<String, String> consumer;
private long consumed = 0;
- @Async
+ public void start()
+ {
+ taskExecutor.execute(this);
+ }
+
+ @Override
public void run()
{
try