topic search
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.xuxd.kafka.console.beans.enums;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-09-09 17:42:38
|
||||
**/
|
||||
public enum TopicType {
|
||||
ALL, SYSTEM, NORMAL;
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.xuxd.kafka.console.controller;
|
||||
|
||||
import com.xuxd.kafka.console.beans.enums.TopicType;
|
||||
import com.xuxd.kafka.console.service.TopicService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
@@ -20,7 +22,7 @@ public class TopicController {
|
||||
private TopicService topicService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Object getTopicList() {
|
||||
return topicService.getTopicList();
|
||||
public Object getTopicList(@RequestParam(required = false) String topic, @RequestParam String type) {
|
||||
return topicService.getTopicList(topic, TopicType.valueOf(type.toUpperCase()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.xuxd.kafka.console.service;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import com.xuxd.kafka.console.beans.enums.TopicType;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
@@ -12,6 +13,6 @@ public interface TopicService {
|
||||
|
||||
ResponseData getTopicNameList();
|
||||
|
||||
ResponseData getTopicList();
|
||||
ResponseData getTopicList(String topic, TopicType type);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.xuxd.kafka.console.service.impl;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import com.xuxd.kafka.console.beans.enums.TopicType;
|
||||
import com.xuxd.kafka.console.beans.vo.TopicDescriptionVO;
|
||||
import com.xuxd.kafka.console.service.TopicService;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import kafka.console.TopicConsole;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.kafka.clients.admin.TopicDescription;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -25,11 +30,36 @@ public class TopicServiceImpl implements TopicService {
|
||||
private TopicConsole topicConsole;
|
||||
|
||||
@Override public ResponseData getTopicNameList() {
|
||||
return ResponseData.create().data(topicConsole.getTopicNameList()).success();
|
||||
return ResponseData.create().data(topicConsole.getTopicNameList(true)).success();
|
||||
}
|
||||
|
||||
@Override public ResponseData getTopicList() {
|
||||
List<TopicDescription> topicDescriptions = topicConsole.getTopicList(topicConsole.getTopicNameList());
|
||||
@Override public ResponseData getTopicList(String topic, TopicType type) {
|
||||
Set<String> topicSet = new HashSet<>();
|
||||
switch (type) {
|
||||
case SYSTEM:
|
||||
Set<String> internalTopicSet = topicConsole.getInternalTopicNameList();
|
||||
if (StringUtils.isEmpty(topic)) {
|
||||
topicSet.addAll(internalTopicSet);
|
||||
} else {
|
||||
if (internalTopicSet.contains(topic)) {
|
||||
topicSet.add(topic);
|
||||
} else {
|
||||
return ResponseData.create().data(Collections.emptyList()).success();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NORMAL:
|
||||
Set<String> internalTopicS = topicConsole.getInternalTopicNameList();
|
||||
if (internalTopicS.contains(topic)) {
|
||||
return ResponseData.create().data(Collections.emptyList()).success();
|
||||
}
|
||||
topicSet.addAll(StringUtils.isEmpty(topic) ? topicConsole.getTopicNameList(false) : Collections.singleton(topic));
|
||||
break;
|
||||
default:
|
||||
topicSet.addAll(StringUtils.isEmpty(topic) ? topicConsole.getTopicNameList(true) : Collections.singleton(topic));
|
||||
break;
|
||||
}
|
||||
List<TopicDescription> topicDescriptions = topicConsole.getTopicList(topicSet);
|
||||
topicDescriptions.sort(Comparator.comparing(TopicDescription::name));
|
||||
|
||||
return ResponseData.create().data(topicDescriptions.stream().map(d -> TopicDescriptionVO.from(d))).success();
|
||||
|
||||
Reference in New Issue
Block a user