consumer group list

This commit is contained in:
许晓东
2021-09-11 11:55:10 +08:00
parent 098af95dc7
commit d36791e600
5 changed files with 293 additions and 7 deletions

View File

@@ -0,0 +1,18 @@
package com.xuxd.kafka.console.beans.dto;
import java.util.List;
import lombok.Data;
/**
* kafka-console-ui.
*
* @author xuxd
* @date 2021-09-11 11:26:47
**/
@Data
public class QueryConsumerGroupDTO {
private String groupId;
private List<String> State;
}

View File

@@ -0,0 +1,45 @@
package com.xuxd.kafka.console.controller;
import com.xuxd.kafka.console.beans.dto.QueryConsumerGroupDTO;
import com.xuxd.kafka.console.service.ConsumerService;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* kafka-console-ui.
*
* @author xuxd
* @date 2021-09-11 11:16:09
**/
@RestController
@RequestMapping("/consumer")
public class ConsumerController {
@Autowired
private ConsumerService consumerService;
@GetMapping("/group/list")
public Object getGroupList(@RequestBody(required = false) QueryConsumerGroupDTO dto) {
if (Objects.isNull(dto)) {
return consumerService.getConsumerGroupList(null, null);
}
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)));
}
return consumerService.getConsumerGroupList(groupIdList, stateSet);
}
}