consumer group search and delete function
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
package com.xuxd.kafka.console;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-09-10 20:03:01
|
||||
**/
|
||||
public class CounterSet {
|
||||
}
|
||||
@@ -14,5 +14,5 @@ public class QueryConsumerGroupDTO {
|
||||
|
||||
private String groupId;
|
||||
|
||||
private List<String> State;
|
||||
private List<String> states;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@ import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.kafka.common.ConsumerGroupState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
@@ -29,7 +31,7 @@ public class ConsumerController {
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
@GetMapping("/group/list")
|
||||
@PostMapping("/group/list")
|
||||
public Object getGroupList(@RequestBody(required = false) QueryConsumerGroupDTO dto) {
|
||||
if (Objects.isNull(dto)) {
|
||||
return consumerService.getConsumerGroupList(null, null);
|
||||
@@ -37,9 +39,14 @@ public class ConsumerController {
|
||||
List<String> groupIdList = StringUtils.isNotBlank(dto.getGroupId()) ? Collections.singletonList(dto.getGroupId()) : Collections.emptyList();
|
||||
|
||||
Set<ConsumerGroupState> stateSet = new HashSet<>();
|
||||
if (CollectionUtils.isNotEmpty(dto.getState())) {
|
||||
dto.getState().stream().forEach(s -> stateSet.add(ConsumerGroupState.valueOf(s)));
|
||||
if (CollectionUtils.isNotEmpty(dto.getStates())) {
|
||||
dto.getStates().stream().forEach(s -> stateSet.add(ConsumerGroupState.valueOf(s.toUpperCase())));
|
||||
}
|
||||
return consumerService.getConsumerGroupList(groupIdList, stateSet);
|
||||
}
|
||||
|
||||
@DeleteMapping("/group")
|
||||
public Object deleteConsumerGroup(@RequestParam String groupId) {
|
||||
return consumerService.deleteConsumerGroup(groupId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,6 @@ import org.apache.kafka.common.ConsumerGroupState;
|
||||
public interface ConsumerService {
|
||||
|
||||
ResponseData getConsumerGroupList(List<String> groupIds, Set<ConsumerGroupState> states);
|
||||
|
||||
ResponseData deleteConsumerGroup(String groupId);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ 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.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -13,6 +14,7 @@ import kafka.console.ConsumerConsole;
|
||||
import org.apache.kafka.common.ConsumerGroupState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import scala.Tuple2;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
@@ -44,6 +46,12 @@ public class ConsumerServiceImpl implements ConsumerService {
|
||||
groupList.addAll(consumerConsole.getConsumerGroupIdList(states));
|
||||
}
|
||||
List<ConsumerGroupVO> consumerGroupVOS = consumerConsole.getConsumerGroupList(groupList).stream().map(c -> ConsumerGroupVO.from(c)).collect(Collectors.toList());
|
||||
consumerGroupVOS.sort(Comparator.comparing(ConsumerGroupVO::getGroupId));
|
||||
return ResponseData.create().data(new CounterList<>(consumerGroupVOS)).success();
|
||||
}
|
||||
|
||||
@Override public ResponseData deleteConsumerGroup(String groupId) {
|
||||
Tuple2<Object, String> tuple2 = consumerConsole.deleteConsumerGroups(Collections.singletonList(groupId));
|
||||
return (Boolean) tuple2._1 ? ResponseData.create().success() : ResponseData.create().failed(tuple2._2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user