Skip to content

Commit b2f5d47

Browse files
author
dushixiang
committed
- 增加topic配置管理功能 close # 29
- 关闭延时消息时自动删除内置topic - 优化国际化
1 parent aa90432 commit b2f5d47

File tree

13 files changed

+252
-59
lines changed

13 files changed

+252
-59
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>cn.typesafe</groupId>
1212
<artifactId>kafka-map</artifactId>
13-
<version>1.2.0</version>
13+
<version>1.2.1</version>
1414
<name>kafka-map</name>
1515
<description>a simple kafka manager</description>
1616
<properties>

src/main/java/cn/typesafe/km/controller/TopicController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import javax.annotation.Resource;
1111
import java.util.ArrayList;
1212
import java.util.List;
13+
import java.util.Map;
1314
import java.util.Set;
1415
import java.util.concurrent.ExecutionException;
1516

@@ -105,5 +106,9 @@ public List<TopicConfig> getConfigs(@PathVariable String topic, @RequestParam St
105106
return topicService.getConfigs(topic, clusterId);
106107
}
107108

109+
@PutMapping("/{topic}/configs")
110+
public void updateConfigs(@PathVariable String topic, @RequestParam String clusterId, @RequestBody Map<String, String> configs) throws ExecutionException, InterruptedException {
111+
topicService.setConfigs(topic, clusterId, configs);
112+
}
108113

109114
}

src/main/java/cn/typesafe/km/controller/handle/GlobalExceptionHandler.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cn.typesafe.km.controller.handle;
22

3+
import org.apache.kafka.common.errors.InvalidRequestException;
34
import org.apache.kafka.common.errors.TimeoutException;
45
import org.apache.kafka.common.errors.TopicExistsException;
56
import org.springframework.http.HttpStatus;
@@ -17,7 +18,17 @@ public class GlobalExceptionHandler {
1718
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
1819
@ResponseBody
1920
@ExceptionHandler(value = TopicExistsException.class)
20-
public Map<String, Object> exceptionHandler(TopicExistsException e) {
21+
public Map<String, Object> topicExistsException(TopicExistsException e) {
22+
String message = e.getMessage();
23+
Map<String, Object> data = new HashMap<>();
24+
data.put("message", message);
25+
return data;
26+
}
27+
28+
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
29+
@ResponseBody
30+
@ExceptionHandler(value = InvalidRequestException.class)
31+
public Map<String, Object> invalidRequestException(InvalidRequestException e) {
2132
String message = e.getMessage();
2233
Map<String, Object> data = new HashMap<>();
2334
data.put("message", message);

src/main/java/cn/typesafe/km/service/ClusterService.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,32 @@ public void disableDelayMessage(String id) {
204204
delayMessageHelper.stop();
205205
cluster.setDelayMessageStatus(Constant.DELAY_MESSAGE_DISABLED);
206206
clusterRepository.saveAndFlush(cluster);
207+
208+
List<String> topics = List.of(
209+
"delay-message",
210+
"__delay-seconds-1",
211+
"__delay-seconds-5",
212+
"__delay-seconds-10",
213+
"__delay-seconds-30",
214+
"__delay-minutes-1",
215+
"__delay-minutes-2",
216+
"__delay-minutes-3",
217+
"__delay-minutes-4",
218+
"__delay-minutes-5",
219+
"__delay-minutes-6",
220+
"__delay-minutes-7",
221+
"__delay-minutes-8",
222+
"__delay-minutes-9",
223+
"__delay-minutes-10",
224+
"__delay-minutes-20",
225+
"__delay-minutes-30",
226+
"__delay-hours-1",
227+
"__delay-hours-2");
228+
try {
229+
topicService.deleteTopic(id, topics);
230+
} catch (ExecutionException | InterruptedException ignored) {
231+
232+
}
207233
}
208234

209235
public void restore() {

src/main/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kafka-map",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"private": true,
55
"dependencies": {
66
"@testing-library/jest-dom": "^5.11.4",

src/main/web/src/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import en_US from './locales/en_US';
1818
import dayjs from "dayjs";
1919
import relativeTime from "dayjs/plugin/relativeTime";
2020
import 'dayjs/locale/zh-cn';
21-
import {IntlProvider} from 'react-intl';
21+
import {FormattedMessage, IntlProvider} from 'react-intl';
2222
import Login from "./components/Login";
2323
import request from "./common/request";
2424
import {
@@ -105,14 +105,14 @@ class App extends Component {
105105
<Menu>
106106
<Menu.Item>
107107
<Link to={`/info`}>
108-
修改密码
108+
<FormattedMessage id="change-password"/>
109109
</Link>
110110
</Menu.Item>
111111
<Menu.Item>
112112
<a href="/#" onClick={() => {
113113
this.logout();
114114
}}>
115-
退出登录
115+
<FormattedMessage id="logout"/>
116116
</a>
117117
</Menu.Item>
118118
</Menu>

src/main/web/src/common/request.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {getHeaders} from "../utils/utils";
99
axios.defaults.baseURL = server;
1010

1111
const handleError = (error) => {
12+
console.log(error)
1213
if ("Network Error" === error.toString()) {
1314
message.error('网络异常');
1415
return false;
@@ -17,6 +18,7 @@ const handleError = (error) => {
1718
window.location.href = '#/login';
1819
return false;
1920
}
21+
2022
if (error.response !== undefined) {
2123
let data = error.response.data;
2224
message.error(`${data.message}`, 10);

src/main/web/src/components/Cluster.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
Input,
1313
Divider,
1414
Popconfirm,
15-
Switch, Popover
15+
Switch, Popover, Alert
1616
} from "antd";
1717
import dayjs from "dayjs";
1818
import request from "../common/request";
@@ -34,15 +34,16 @@ const {Title, Text} = Typography;
3434

3535
const content = (
3636
<div>
37-
<p>基于kafka的延迟消息服务,支持18个级别,1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h。</p>
38-
<p>向主题:delay-message 投递以下格式的消息即可,level 范围:0-17 。</p>
37+
<Alert style={{marginTop: 5, marginBottom: 10}} message={<FormattedMessage id="delay-message-information1"/>} type="info" showIcon/>
38+
<p><FormattedMessage id="delay-message-information2"/></p>
39+
<p><FormattedMessage id="delay-message-information3"/></p>
3940
<pre>
4041
{JSON.stringify({
4142
"level": 0,
4243
"topic": "target",
4344
"key": "key",
4445
"value": "value"
45-
}, null,4)}
46+
}, null, 4)}
4647
</pre>
4748
</div>
4849
);
@@ -262,8 +263,8 @@ class Cluster extends Component {
262263
dataIndex: 'delayMessageStatus',
263264
key: 'delayMessageStatus',
264265
render: (delayMessageStatus, record, index) => {
265-
return <Popover content={content} title="如何使用延迟消息服务?">
266-
<Switch checkedChildren="开启" unCheckedChildren="关闭" checked={delayMessageStatus === 'enabled'}
266+
return <Popover content={content}>
267+
<Switch checked={delayMessageStatus === 'enabled'}
267268
onChange={async (checked) => {
268269
let url = `/clusters/${record['id']}/disableDelayMessage`;
269270
if (checked) {
@@ -396,8 +397,8 @@ class Cluster extends Component {
396397
loading={this.state.delBtnLoading}
397398
onClick={() => {
398399
const content = <div>
399-
您确定要删除选中的<Text style={{color: '#1890FF'}}
400-
strong>{this.state.selectedRowKeys.length}</Text>条记录吗?
400+
Are you sure delete <Text style={{color: '#1890FF'}}
401+
strong>{this.state.selectedRowKeys.length}</Text> items?
401402
</div>;
402403
confirm({
403404
icon: <ExclamationCircleOutlined/>,

src/main/web/src/components/ClusterModal.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const ClusterModal = ({title, handleOk, handleCancel, confirmLoading, model}) =>
5959
</Form.Item> : undefined
6060
}
6161

62-
<Form.Item label={'安全协议'} name='securityProtocol'>
62+
<Form.Item label={<FormattedMessage id="security-protocol"/>} name='securityProtocol'>
6363
<Select allowClear>
6464
<Select.Option value="PLAINTEXT">PLAINTEXT</Select.Option>
6565
<Select.Option value="SSL">SSL</Select.Option>
@@ -68,7 +68,7 @@ const ClusterModal = ({title, handleOk, handleCancel, confirmLoading, model}) =>
6868
</Select>
6969
</Form.Item>
7070

71-
<Form.Item label={'协议机制'} name='saslMechanism'>
71+
<Form.Item label={<FormattedMessage id="sasl-mechanism"/>} name='saslMechanism'>
7272
<Select allowClear>
7373
<Select.Option value="GSSAPI">GSSAPI</Select.Option>
7474
<Select.Option value="PLAIN">PLAIN</Select.Option>
@@ -78,11 +78,11 @@ const ClusterModal = ({title, handleOk, handleCancel, confirmLoading, model}) =>
7878
</Select>
7979
</Form.Item>
8080

81-
<Form.Item label={'username'} name='authUsername'>
81+
<Form.Item label={<FormattedMessage id="username"/>} name='authUsername'>
8282
<Input placeholder="" maxLength={200}/>
8383
</Form.Item>
8484

85-
<Form.Item label={'password'} name='authPassword'>
85+
<Form.Item label={<FormattedMessage id="password"/>} name='authPassword'>
8686
<Input placeholder="" maxLength={200}/>
8787
</Form.Item>
8888
</Form>

0 commit comments

Comments
 (0)