summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrzysztof Kuzmicki <krzysztof.kuzmicki@nokia.com>2020-04-21 13:12:44 +0000
committerGerrit Code Review <gerrit@onap.org>2020-04-21 13:12:44 +0000
commit97f8bd5ea5ecaea4b0ea10f51698ebfb4d9f5052 (patch)
tree579032c26010ba4f1ca5f7f791083abb0a69e561
parent33b6b4e0fc3e9502d1f79c7efd54a4e437eb7b22 (diff)
parent37622e3c6acaf455a9a4a5874f190e8ff17a693e (diff)
Merge "Remove deprecated method"
-rw-r--r--netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java11
1 files changed, 8 insertions, 3 deletions
diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java
index 1b99220..6bd8390 100644
--- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java
+++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java
@@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.stereotype.Service;
+import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
@@ -53,7 +54,7 @@ public class StoreService {
String clientId = Long.toString(Instant.now().getEpochSecond());
try (Consumer<String, String> consumer = consumerFactory.createConsumer(clientId, clientId)) {
consumer.subscribe(TOPICS_TO_SUBSCRIBE);
- ConsumerRecords<String, String> consumerRecords = consumer.poll(CONSUMING_DURATION_IN_MS);
+ ConsumerRecords<String, String> consumerRecords = pollConsumerRecords(consumer);
consumerRecords.forEach(
consumerRecord ->
messages.add(new Message(consumerRecord.timestamp(), consumerRecord.value())));
@@ -65,7 +66,7 @@ public class StoreService {
List<Message> getLastMessages(long offset) {
List<Message> messages = new ArrayList<>();
try (Consumer<String, String> consumer = createConsumer(offset)) {
- ConsumerRecords<String, String> consumerRecords = consumer.poll(CONSUMING_DURATION_IN_MS);
+ ConsumerRecords<String, String> consumerRecords = pollConsumerRecords(consumer);
consumerRecords.forEach(consumerRecord ->
messages.add(new Message(consumerRecord.timestamp(), consumerRecord.value())));
}
@@ -82,10 +83,14 @@ public class StoreService {
private void seekConsumerTo(Consumer<String, String> consumer, long offsetFromLastIndex) {
consumer.seekToEnd(consumer.assignment());
- consumer.poll(CONSUMING_DURATION_IN_MS);
+ pollConsumerRecords(consumer);
TopicPartition topicPartition = consumer.assignment().iterator().next();
long topicCurrentSize = consumer.position(topicPartition);
long indexToSeek = offsetFromLastIndex > topicCurrentSize ? 0 : topicCurrentSize - offsetFromLastIndex;
consumer.seek(topicPartition, indexToSeek);
}
+
+ private ConsumerRecords<String, String> pollConsumerRecords(Consumer<String, String> consumer) {
+ return consumer.poll(Duration.ofMillis(CONSUMING_DURATION_IN_MS));
+ }
}