add consumer group console
This commit is contained in:
10
src/main/java/com/xuxd/kafka/console/CounterSet.java
Normal file
10
src/main/java/com/xuxd/kafka/console/CounterSet.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.xuxd.kafka.console;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-09-10 20:03:01
|
||||
**/
|
||||
public class CounterSet {
|
||||
}
|
||||
@@ -23,4 +23,11 @@ public class CounterList<T> {
|
||||
public int getTotal() {
|
||||
return list != null ? list.size() : 0;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return "CounterList{" +
|
||||
"list=" + list +
|
||||
", total=" + getTotal() +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.xuxd.kafka.console.beans.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.kafka.clients.admin.ConsumerGroupDescription;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-09-10 20:16:07
|
||||
**/
|
||||
@Data
|
||||
public class ConsumerGroupVO {
|
||||
|
||||
private String groupId;
|
||||
|
||||
private boolean isSimpleConsumerGroup;
|
||||
|
||||
private int members;
|
||||
|
||||
private String partitionAssignor;
|
||||
|
||||
private String state;
|
||||
|
||||
private String coordinator;
|
||||
|
||||
private int authorizedOperations;
|
||||
|
||||
public static ConsumerGroupVO from(ConsumerGroupDescription description) {
|
||||
ConsumerGroupVO vo = new ConsumerGroupVO();
|
||||
vo.setGroupId(description.groupId());
|
||||
vo.setSimpleConsumerGroup(description.isSimpleConsumerGroup());
|
||||
vo.setMembers(description.members().size());
|
||||
vo.setPartitionAssignor(description.partitionAssignor());
|
||||
vo.setState(description.state().name());
|
||||
vo.setCoordinator(description.coordinator() != null ? description.coordinator().toString() : "");
|
||||
vo.setAuthorizedOperations(description.authorizedOperations() != null ? description.authorizedOperations().size() : 0);
|
||||
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xuxd.kafka.console.config;
|
||||
|
||||
import kafka.console.ConsumerConsole;
|
||||
import kafka.console.KafkaAclConsole;
|
||||
import kafka.console.KafkaConfigConsole;
|
||||
import kafka.console.TopicConsole;
|
||||
@@ -29,4 +30,9 @@ public class KafkaConfiguration {
|
||||
public TopicConsole topicConsole(KafkaConfig config) {
|
||||
return new TopicConsole(config);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConsumerConsole consumerConsole(KafkaConfig config) {
|
||||
return new ConsumerConsole(config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.xuxd.kafka.console.service;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.apache.kafka.common.ConsumerGroupState;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-09-10 19:39:26
|
||||
**/
|
||||
public interface ConsumerService {
|
||||
|
||||
ResponseData getConsumerGroupList(List<String> groupIds, Set<ConsumerGroupState> states);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.xuxd.kafka.console.service.impl;
|
||||
|
||||
import com.xuxd.kafka.console.beans.CounterList;
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import com.xuxd.kafka.console.beans.vo.ConsumerGroupVO;
|
||||
import com.xuxd.kafka.console.service.ConsumerService;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import kafka.console.ConsumerConsole;
|
||||
import org.apache.kafka.common.ConsumerGroupState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-09-10 19:40:10
|
||||
**/
|
||||
@Service
|
||||
public class ConsumerServiceImpl implements ConsumerService {
|
||||
|
||||
@Autowired
|
||||
private ConsumerConsole consumerConsole;
|
||||
|
||||
@Override public ResponseData getConsumerGroupList(List<String> groupIds, Set<ConsumerGroupState> states) {
|
||||
Set<String> groupList = new HashSet<>();
|
||||
if (groupIds != null && !groupIds.isEmpty()) {
|
||||
if (states != null && !states.isEmpty()) {
|
||||
Set<String> stateGroup = consumerConsole.getConsumerGroupIdList(states);
|
||||
Set<String> filterGroupList = groupIds.stream().filter(x -> stateGroup.contains(x)).collect(Collectors.toSet());
|
||||
if (filterGroupList.isEmpty()) {
|
||||
return ResponseData.create().data(Collections.emptyList()).success();
|
||||
} else {
|
||||
groupList.addAll(filterGroupList);
|
||||
}
|
||||
} else {
|
||||
groupList.addAll(groupIds);
|
||||
}
|
||||
} else {
|
||||
groupList.addAll(consumerConsole.getConsumerGroupIdList(states));
|
||||
}
|
||||
List<ConsumerGroupVO> consumerGroupVOS = consumerConsole.getConsumerGroupList(groupList).stream().map(c -> ConsumerGroupVO.from(c)).collect(Collectors.toList());
|
||||
return ResponseData.create().data(new CounterList<>(consumerGroupVOS)).success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user