import java.util.Optional;
import java.util.Properties;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
@SpringBootApplication
return new KafkaConsumer<>(props);
}
- @Bean(destroyMethod = "shutdown")
- ExecutorService executorService()
- {
- return Executors.newFixedThreadPool(1);
- }
-
@Bean(destroyMethod = "shutdown")
TransferConsumer transferConsumer(
TransferServiceProperties properties,
KafkaConsumer<String, String> consumer,
- ExecutorService executorService,
ObjectMapper mapper,
TransferService productionTransferService,
TransferService restoreTransferService)
new TransferConsumer(
properties.topic,
consumer,
- executorService,
mapper,
new TransferConsumer.ConsumerUseCases() {
@Override
import java.time.Duration;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
{
private final String topic;
private final KafkaConsumer<String, String> consumer;
- private final ExecutorService executorService;
private final ObjectMapper mapper;
private final ConsumerUseCases productionUseCases, restoreUseCases;
// in the same thread, it would block the completion of the initialization.
// Hence, the app would not react to any signal (CTRL-C, for example) except
// a KILL until the restoring is finished.
- future = executorService.submit(() -> restore());
+ future = CompletableFuture.runAsync(() -> restore());
}
private void restore()
}
running = true;
- future = executorService.submit(this);
+ future = CompletableFuture.runAsync(this);
log.info("started");
return result;