获取配置
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
# kafka可视化管理平台
|
# kafka可视化管理平台
|
||||||
|
一款轻量级的kafka可视化管理平台,安装配置快捷、简单易用。
|
||||||
|
为了开发的省事,没有多语言支持,只支持中文展示。
|
||||||
|
用过rocketmq-console吧,对,前端展示风格跟那个有点类似。
|
||||||
## 功能支持
|
## 功能支持
|
||||||
* 集群信息
|
* 集群信息
|
||||||
* Topic管理
|
* Topic管理
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package com.xuxd.kafka.console.controller;
|
|||||||
|
|
||||||
import com.xuxd.kafka.console.beans.ResponseData;
|
import com.xuxd.kafka.console.beans.ResponseData;
|
||||||
import com.xuxd.kafka.console.config.KafkaConfig;
|
import com.xuxd.kafka.console.config.KafkaConfig;
|
||||||
|
import com.xuxd.kafka.console.service.ConfigService;
|
||||||
import com.xuxd.kafka.console.utils.ConvertUtil;
|
import com.xuxd.kafka.console.utils.ConvertUtil;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -19,15 +21,29 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
public class ConfigController {
|
public class ConfigController {
|
||||||
|
|
||||||
private final KafkaConfig config;
|
private final KafkaConfig config;
|
||||||
|
|
||||||
private final Map<String, Object> configMap;
|
private final Map<String, Object> configMap;
|
||||||
|
|
||||||
public ConfigController(KafkaConfig config) {
|
private final ConfigService configService;
|
||||||
|
|
||||||
|
public ConfigController(KafkaConfig config, ConfigService configService) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.configMap = ConvertUtil.toMap(config);
|
this.configMap = ConvertUtil.toMap(config);
|
||||||
|
this.configService = configService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public Object getConfig() {
|
public Object getConfig() {
|
||||||
return ResponseData.create().data(configMap).success();
|
return ResponseData.create().data(configMap).success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/topic")
|
||||||
|
public Object getTopicConfig(String topic) {
|
||||||
|
return configService.getTopicConfig(topic);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/broker")
|
||||||
|
public Object getTopicConfig() {
|
||||||
|
return configService.getBrokerConfig();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.xuxd.kafka.console.service;
|
||||||
|
|
||||||
|
import com.xuxd.kafka.console.beans.ResponseData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kafka-console-ui.
|
||||||
|
*
|
||||||
|
* @author xuxd
|
||||||
|
* @date 2021-11-02 19:57:43
|
||||||
|
**/
|
||||||
|
public interface ConfigService {
|
||||||
|
|
||||||
|
ResponseData getTopicConfig(String topic);
|
||||||
|
|
||||||
|
ResponseData getBrokerConfig();
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.xuxd.kafka.console.service.impl;
|
||||||
|
|
||||||
|
import com.xuxd.kafka.console.beans.ResponseData;
|
||||||
|
import com.xuxd.kafka.console.service.ConfigService;
|
||||||
|
import java.util.List;
|
||||||
|
import kafka.console.ConfigConsole;
|
||||||
|
import org.apache.kafka.clients.admin.ConfigEntry;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kafka-console-ui.
|
||||||
|
*
|
||||||
|
* @author xuxd
|
||||||
|
* @date 2021-11-02 19:57:57
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class ConfigServiceImpl implements ConfigService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigConsole configConsole;
|
||||||
|
|
||||||
|
@Override public ResponseData getTopicConfig(String topic) {
|
||||||
|
List<ConfigEntry> configEntries = configConsole.getTopicConfig(topic);
|
||||||
|
return ResponseData.create().success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public ResponseData getBrokerConfig() {
|
||||||
|
List<ConfigEntry> configEntries = configConsole.getBrokerConfig();
|
||||||
|
return ResponseData.create().success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,10 @@ class ConfigConsole(config: KafkaConfig) extends KafkaConsole(config: KafkaConfi
|
|||||||
getConfig(ConfigType.Topic, topic)
|
getConfig(ConfigType.Topic, topic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getBrokerConfig() : List[ConfigEntry] = {
|
||||||
|
getConfig(ConfigType.Broker, "0")
|
||||||
|
}
|
||||||
|
|
||||||
def getConfig(entityType: String, entityName: String): List[ConfigEntry] = {
|
def getConfig(entityType: String, entityName: String): List[ConfigEntry] = {
|
||||||
getResourceConfig(entityType, entityName, true, false).asJava
|
getResourceConfig(entityType, entityName, true, false).asJava
|
||||||
}
|
}
|
||||||
@@ -49,7 +53,7 @@ class ConfigConsole(config: KafkaConfig) extends KafkaConsole(config: KafkaConfi
|
|||||||
(ConfigResource.Type.BROKER, Some(ConfigEntry.ConfigSource.DYNAMIC_DEFAULT_BROKER_CONFIG))
|
(ConfigResource.Type.BROKER, Some(ConfigEntry.ConfigSource.DYNAMIC_DEFAULT_BROKER_CONFIG))
|
||||||
case _ =>
|
case _ =>
|
||||||
validateBrokerId()
|
validateBrokerId()
|
||||||
(ConfigResource.Type.BROKER, Some(ConfigEntry.ConfigSource.DYNAMIC_BROKER_CONFIG))
|
(ConfigResource.Type.BROKER, Some(ConfigEntry.ConfigSource.STATIC_BROKER_CONFIG))
|
||||||
}
|
}
|
||||||
case BrokerLoggerConfigType =>
|
case BrokerLoggerConfigType =>
|
||||||
if (!entityName.isEmpty)
|
if (!entityName.isEmpty)
|
||||||
|
|||||||
Reference in New Issue
Block a user