- Properties props = new Properties();
-
- props.put("bootstrap.servers", properties.getBootstrapServer());
- props.put("group.id", properties.getGroupId());
- props.put("client.id", properties.getClientId());
- props.put("auto.offset.reset", properties.getAutoOffsetReset());
- props.put("metadata.max.age.ms", "1000");
- props.put("key.deserializer", StringDeserializer.class.getName());
- props.put("value.deserializer", LongDeserializer.class.getName());
-
- return new KafkaConsumer<>(props);
+ try
+ {
+ log.info("Shutting down the ExecutorService.");
+ executor.shutdown();
+ log.info("Waiting 5 seconds for the ExecutorService to terminate...");
+ executor.awaitTermination(5, TimeUnit.SECONDS);
+ }
+ catch (InterruptedException e)
+ {
+ log.error("Exception while waiting for the termination of the ExecutorService: {}", e.toString());
+ }
+ finally
+ {
+ if (!executor.isShutdown())
+ {
+ log.warn("Forcing shutdown of ExecutorService!");
+ executor
+ .shutdownNow()
+ .forEach(runnable -> log.warn("Unfinished task: {}", runnable.getClass().getSimpleName()));
+ }
+ log.info("Shutdow of ExecutorService finished");
+ }