org.apache.kafka.clients.admin.DescribeConsumerGroupsResult Java Examples

The following examples show how to use org.apache.kafka.clients.admin.DescribeConsumerGroupsResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KafkaAdminClientImpl.java    From vertx-kafka-client with Apache License 2.0 4 votes vote down vote up
@Override
public Future<Map<String, ConsumerGroupDescription>> describeConsumerGroups(List<String> groupIds) {
  ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext();
  Promise<Map<String, ConsumerGroupDescription>> promise = ctx.promise();

  DescribeConsumerGroupsResult describeConsumerGroupsResult = this.adminClient.describeConsumerGroups(groupIds);
  describeConsumerGroupsResult.all().whenComplete((cg, ex) -> {
    if (ex == null) {
      Map<String, ConsumerGroupDescription> consumerGroups = new HashMap<>();

      for (Map.Entry<String, org.apache.kafka.clients.admin.ConsumerGroupDescription> cgDescriptionEntry: cg.entrySet()) {
        List<MemberDescription> members = new ArrayList<>();

        for (org.apache.kafka.clients.admin.MemberDescription memberDescription : cgDescriptionEntry.getValue().members()) {
          MemberDescription m = new MemberDescription();
          m.setConsumerId(memberDescription.consumerId())
            .setClientId(memberDescription.clientId())
            .setAssignment(Helper.from(memberDescription.assignment()))
            .setHost(memberDescription.host());

          members.add(m);
        }

        ConsumerGroupDescription consumerGroupDescription = new ConsumerGroupDescription();

        consumerGroupDescription.setGroupId(cgDescriptionEntry.getValue().groupId())
          .setCoordinator(Helper.from(cgDescriptionEntry.getValue().coordinator()))
          .setMembers(members)
          .setPartitionAssignor(cgDescriptionEntry.getValue().partitionAssignor())
          .setSimpleConsumerGroup(cgDescriptionEntry.getValue().isSimpleConsumerGroup())
          .setState(cgDescriptionEntry.getValue().state());

        consumerGroups.put(cgDescriptionEntry.getKey(), consumerGroupDescription);
      }
      promise.complete(consumerGroups);
    } else {
      promise.fail(ex);
    }
  });
  return promise.future();
}