add topic console
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.xuxd.kafka.console.beans.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.kafka.clients.admin.TopicDescription;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-09-08 21:12:36
|
||||
**/
|
||||
@Data
|
||||
public class TopicDescriptionVO {
|
||||
|
||||
private String name;
|
||||
private boolean internal;
|
||||
private int partitions;
|
||||
|
||||
public static TopicDescriptionVO from(TopicDescription description) {
|
||||
TopicDescriptionVO vo = new TopicDescriptionVO();
|
||||
vo.setName(description.name());
|
||||
vo.setInternal(description.isInternal());
|
||||
vo.setPartitions(description.partitions().size());
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.xuxd.kafka.console.config;
|
||||
|
||||
import kafka.console.KafkaAclConsole;
|
||||
import kafka.console.KafkaConfigConsole;
|
||||
import kafka.console.TopicConsole;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -23,4 +24,9 @@ public class KafkaConfiguration {
|
||||
public KafkaAclConsole kafkaAclConsole(KafkaConfig config) {
|
||||
return new KafkaAclConsole(config);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TopicConsole topicConsole(KafkaConfig config) {
|
||||
return new TopicConsole(config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.xuxd.kafka.console.controller;
|
||||
|
||||
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.RestController;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-09-08 20:28:35
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/topic")
|
||||
public class TopicController {
|
||||
|
||||
@Autowired
|
||||
private TopicService topicService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Object getTopicList() {
|
||||
return topicService.getTopicList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.xuxd.kafka.console.service;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-09-08 20:01:49
|
||||
**/
|
||||
public interface TopicService {
|
||||
|
||||
ResponseData getTopicNameList();
|
||||
|
||||
ResponseData getTopicList();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.xuxd.kafka.console.service.impl;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import com.xuxd.kafka.console.beans.vo.TopicDescriptionVO;
|
||||
import com.xuxd.kafka.console.service.TopicService;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import kafka.console.TopicConsole;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.kafka.clients.admin.TopicDescription;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-09-08 20:02:56
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TopicServiceImpl implements TopicService {
|
||||
|
||||
@Autowired
|
||||
private TopicConsole topicConsole;
|
||||
|
||||
@Override public ResponseData getTopicNameList() {
|
||||
return ResponseData.create().data(topicConsole.getTopicNameList()).success();
|
||||
}
|
||||
|
||||
@Override public ResponseData getTopicList() {
|
||||
List<TopicDescription> topicDescriptions = topicConsole.getTopicList(topicConsole.getTopicNameList());
|
||||
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