use of org.apache.kafka.clients.admin.ListConsumerGroupOffsetsResult in project kafka by apache.
the class EosTestDriver method getCommittedOffsets.
private static Map<TopicPartition, Long> getCommittedOffsets(final Admin adminClient, final boolean withRepartitioning) {
final Map<TopicPartition, OffsetAndMetadata> topicPartitionOffsetAndMetadataMap;
try {
final ListConsumerGroupOffsetsResult listConsumerGroupOffsetsResult = adminClient.listConsumerGroupOffsets(EosTestClient.APP_ID);
topicPartitionOffsetAndMetadataMap = listConsumerGroupOffsetsResult.partitionsToOffsetAndMetadata().get(10, TimeUnit.SECONDS);
} catch (final Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
final Map<TopicPartition, Long> committedOffsets = new HashMap<>();
for (final Map.Entry<TopicPartition, OffsetAndMetadata> entry : topicPartitionOffsetAndMetadataMap.entrySet()) {
final String topic = entry.getKey().topic();
if (topic.equals("data") || withRepartitioning && topic.equals("repartition")) {
committedOffsets.put(entry.getKey(), entry.getValue().offset());
}
}
return committedOffsets;
}
use of org.apache.kafka.clients.admin.ListConsumerGroupOffsetsResult in project flink by apache.
the class KafkaTableTestBase method getConsumerOffset.
public Map<TopicPartition, OffsetAndMetadata> getConsumerOffset(String groupId) {
Map<String, Object> properties = new HashMap<>();
properties.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, getBootstrapServers());
try (AdminClient admin = AdminClient.create(properties)) {
ListConsumerGroupOffsetsResult result = admin.listConsumerGroupOffsets(groupId);
return result.partitionsToOffsetAndMetadata().get(20, TimeUnit.SECONDS);
} catch (Exception e) {
throw new IllegalStateException(String.format("Fail to get consumer offsets with the group id [%s].", groupId), e);
}
}
Aggregations