新建订阅
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
package com.xuxd.kafka.console.beans.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kafka-console-ui.
|
||||||
|
*
|
||||||
|
* @author xuxd
|
||||||
|
* @date 2021-10-21 15:43:56
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
public class AddSubscriptionDTO {
|
||||||
|
|
||||||
|
private String groupId;
|
||||||
|
|
||||||
|
private String topic;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xuxd.kafka.console.controller;
|
package com.xuxd.kafka.console.controller;
|
||||||
|
|
||||||
|
import com.xuxd.kafka.console.beans.dto.AddSubscriptionDTO;
|
||||||
import com.xuxd.kafka.console.beans.dto.QueryConsumerGroupDTO;
|
import com.xuxd.kafka.console.beans.dto.QueryConsumerGroupDTO;
|
||||||
import com.xuxd.kafka.console.service.ConsumerService;
|
import com.xuxd.kafka.console.service.ConsumerService;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -60,4 +61,9 @@ public class ConsumerController {
|
|||||||
public Object getConsumerDetail(@RequestParam String groupId) {
|
public Object getConsumerDetail(@RequestParam String groupId) {
|
||||||
return consumerService.getConsumerDetail(groupId);
|
return consumerService.getConsumerDetail(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/subscription")
|
||||||
|
public Object addSubscription(@RequestBody AddSubscriptionDTO subscriptionDTO) {
|
||||||
|
return consumerService.addSubscription(subscriptionDTO.getGroupId(), subscriptionDTO.getTopic());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ public class TopicController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private TopicService topicService;
|
private TopicService topicService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public Object getTopicNameList() {
|
||||||
|
return topicService.getTopicNameList(false);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public Object getTopicList(@RequestParam(required = false) String topic, @RequestParam String type) {
|
public Object getTopicList(@RequestParam(required = false) String topic, @RequestParam String type) {
|
||||||
return topicService.getTopicList(topic, TopicType.valueOf(type.toUpperCase()));
|
return topicService.getTopicList(topic, TopicType.valueOf(type.toUpperCase()));
|
||||||
|
|||||||
@@ -20,4 +20,6 @@ public interface ConsumerService {
|
|||||||
ResponseData getConsumerMembers(String groupId);
|
ResponseData getConsumerMembers(String groupId);
|
||||||
|
|
||||||
ResponseData getConsumerDetail(String groupId);
|
ResponseData getConsumerDetail(String groupId);
|
||||||
|
|
||||||
|
ResponseData addSubscription(String groupId, String topic);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import org.apache.kafka.clients.admin.NewTopic;
|
|||||||
**/
|
**/
|
||||||
public interface TopicService {
|
public interface TopicService {
|
||||||
|
|
||||||
ResponseData getTopicNameList();
|
ResponseData getTopicNameList(boolean internal);
|
||||||
|
|
||||||
ResponseData getTopicList(String topic, TopicType type);
|
ResponseData getTopicList(String topic, TopicType type);
|
||||||
|
|
||||||
|
|||||||
@@ -98,4 +98,22 @@ public class ConsumerServiceImpl implements ConsumerService {
|
|||||||
});
|
});
|
||||||
return ResponseData.create().data(res).success();
|
return ResponseData.create().data(res).success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public ResponseData addSubscription(String groupId, String topic) {
|
||||||
|
// check whether exist subscription relationship.
|
||||||
|
Collection<ConsumerConsole.TopicPartitionConsumeInfo> consumerDetail = consumerConsole.getConsumerDetail(Collections.singleton(groupId));
|
||||||
|
if (CollectionUtils.isNotEmpty(consumerDetail)) {
|
||||||
|
List<ConsumerConsole.TopicPartitionConsumeInfo> collect = consumerDetail.stream()
|
||||||
|
.filter(t -> t.getTopicPartition().topic().equals(topic)).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(collect)) {
|
||||||
|
return ResponseData.create().failed("The subscription exist.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// consumer message and commit offset.
|
||||||
|
|
||||||
|
|
||||||
|
// reset consume offset to 0.
|
||||||
|
return ResponseData.create().success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ public class TopicServiceImpl implements TopicService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private TopicConsole topicConsole;
|
private TopicConsole topicConsole;
|
||||||
|
|
||||||
@Override public ResponseData getTopicNameList() {
|
@Override public ResponseData getTopicNameList(boolean internal) {
|
||||||
return ResponseData.create().data(topicConsole.getTopicNameList(true)).success();
|
return ResponseData.create().data(topicConsole.getTopicNameList(internal)).success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public ResponseData getTopicList(String topic, TopicType type) {
|
@Override public ResponseData getTopicList(String topic, TopicType type) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class TopicServiceImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTopicNameList() {
|
public void getTopicNameList() {
|
||||||
log.info(topicService.getTopicNameList().getData().toString());
|
log.info(topicService.getTopicNameList(true).getData().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ export const KafkaConfigApi = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const KafkaTopicApi = {
|
export const KafkaTopicApi = {
|
||||||
|
getTopicNameList: {
|
||||||
|
url: "/topic",
|
||||||
|
method: "get",
|
||||||
|
},
|
||||||
getTopicList: {
|
getTopicList: {
|
||||||
url: "/topic/list",
|
url: "/topic/list",
|
||||||
method: "get",
|
method: "get",
|
||||||
@@ -96,6 +100,10 @@ export const KafkaConsumerApi = {
|
|||||||
url: "/consumer/detail",
|
url: "/consumer/detail",
|
||||||
method: "get",
|
method: "get",
|
||||||
},
|
},
|
||||||
|
addSubscription: {
|
||||||
|
url: "/consumer/subscription",
|
||||||
|
method: "post",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const KafkaClusterApi = {
|
export const KafkaClusterApi = {
|
||||||
|
|||||||
135
ui/src/views/group/AddSupscription.vue
Normal file
135
ui/src/views/group/AddSupscription.vue
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<template>
|
||||||
|
<a-modal
|
||||||
|
title="新增订阅关系"
|
||||||
|
:visible="show"
|
||||||
|
:width="800"
|
||||||
|
:mask="false"
|
||||||
|
:destroyOnClose="true"
|
||||||
|
:footer="null"
|
||||||
|
:maskClosable="false"
|
||||||
|
@cancel="handleCancel"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<a-spin :spinning="loading">
|
||||||
|
<a-form
|
||||||
|
:form="form"
|
||||||
|
:label-col="{ span: 5 }"
|
||||||
|
:wrapper-col="{ span: 12 }"
|
||||||
|
@submit="handleSubmit"
|
||||||
|
>
|
||||||
|
<a-form-item label="消费组">
|
||||||
|
<a-input
|
||||||
|
v-decorator="[
|
||||||
|
'groupId',
|
||||||
|
{ rules: [{ required: true, message: '输入消费组名称!' }] },
|
||||||
|
]"
|
||||||
|
placeholder="groupId"
|
||||||
|
/>
|
||||||
|
</a-form-item>
|
||||||
|
<a-form-item label="topic">
|
||||||
|
<a-select
|
||||||
|
show-search
|
||||||
|
option-filter-prop="children"
|
||||||
|
v-decorator="[
|
||||||
|
'topic',
|
||||||
|
{ rules: [{ required: true, message: '请选择一个topic!' }] },
|
||||||
|
]"
|
||||||
|
placeholder="请选择一个topic"
|
||||||
|
>
|
||||||
|
<a-select-option v-for="v in topicList" :key="v" :value="v">
|
||||||
|
{{ v }}
|
||||||
|
</a-select-option>
|
||||||
|
</a-select>
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
|
<a-form-item :wrapper-col="{ span: 12, offset: 5 }">
|
||||||
|
<a-button type="primary" html-type="submit"> 提交 </a-button>
|
||||||
|
</a-form-item>
|
||||||
|
</a-form>
|
||||||
|
</a-spin>
|
||||||
|
</div>
|
||||||
|
</a-modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import request from "@/utils/request";
|
||||||
|
import { KafkaTopicApi, KafkaConsumerApi } from "@/utils/api";
|
||||||
|
import notification from "ant-design-vue/es/notification";
|
||||||
|
export default {
|
||||||
|
name: "AddSubscription",
|
||||||
|
props: {
|
||||||
|
topic: {
|
||||||
|
type: String,
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
show: this.visible,
|
||||||
|
data: [],
|
||||||
|
loading: false,
|
||||||
|
form: this.$form.createForm(this, { name: "coordinated" }),
|
||||||
|
topicList: [],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
visible(v) {
|
||||||
|
this.show = v;
|
||||||
|
if (this.show) {
|
||||||
|
this.getTopicNameList();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getTopicNameList() {
|
||||||
|
request({
|
||||||
|
url: KafkaTopicApi.getTopicNameList.url,
|
||||||
|
method: KafkaTopicApi.getTopicNameList.method,
|
||||||
|
}).then((res) => {
|
||||||
|
if (res.code == 0) {
|
||||||
|
this.topicList = res.data;
|
||||||
|
} else {
|
||||||
|
notification.error({
|
||||||
|
message: "error",
|
||||||
|
description: res.msg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSubmit(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.form.validateFields((err, values) => {
|
||||||
|
if (!err) {
|
||||||
|
this.loading = true;
|
||||||
|
request({
|
||||||
|
url: KafkaConsumerApi.addSubscription.url,
|
||||||
|
method: KafkaConsumerApi.addSubscription.method,
|
||||||
|
data: values,
|
||||||
|
}).then((res) => {
|
||||||
|
this.loading = false;
|
||||||
|
if (res.code == 0) {
|
||||||
|
this.$message.success(res.msg);
|
||||||
|
this.$emit("closeAddSubscriptionDialog", { refresh: true });
|
||||||
|
} else {
|
||||||
|
notification.error({
|
||||||
|
message: "error",
|
||||||
|
description: res.msg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleCancel() {
|
||||||
|
this.data = [];
|
||||||
|
this.$emit("closeAddSubscriptionDialog", { refresh: false });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -61,7 +61,9 @@
|
|||||||
</a-form>
|
</a-form>
|
||||||
</div>
|
</div>
|
||||||
<div class="operation-row-button">
|
<div class="operation-row-button">
|
||||||
<!-- <a-button type="primary" @click="handleReset">新增/更新</a-button>-->
|
<a-button type="primary" @click="openAddSubscriptionDialog"
|
||||||
|
>新增订阅</a-button
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<a-table
|
<a-table
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
@@ -111,6 +113,11 @@
|
|||||||
@closeConsumerDetailDialog="closeConsumerDetailDialog"
|
@closeConsumerDetailDialog="closeConsumerDetailDialog"
|
||||||
>
|
>
|
||||||
</ConsumerDetail>
|
</ConsumerDetail>
|
||||||
|
<AddSupscription
|
||||||
|
:visible="showAddSubscriptionDialog"
|
||||||
|
@closeAddSubscriptionDialog="closeAddSubscriptionDialog"
|
||||||
|
>
|
||||||
|
</AddSupscription>
|
||||||
</div>
|
</div>
|
||||||
</a-spin>
|
</a-spin>
|
||||||
</div>
|
</div>
|
||||||
@@ -122,10 +129,11 @@ import { KafkaConsumerApi } from "@/utils/api";
|
|||||||
import notification from "ant-design-vue/es/notification";
|
import notification from "ant-design-vue/es/notification";
|
||||||
import Member from "@/views/group/Member";
|
import Member from "@/views/group/Member";
|
||||||
import ConsumerDetail from "@/views/group/ConsumerDetail";
|
import ConsumerDetail from "@/views/group/ConsumerDetail";
|
||||||
|
import AddSupscription from "@/views/group/AddSupscription";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ConsumerGroup",
|
name: "ConsumerGroup",
|
||||||
components: { Member, ConsumerDetail },
|
components: { Member, ConsumerDetail, AddSupscription },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
queryParam: {},
|
queryParam: {},
|
||||||
@@ -145,6 +153,7 @@ export default {
|
|||||||
loading: false,
|
loading: false,
|
||||||
showConsumerGroupDialog: false,
|
showConsumerGroupDialog: false,
|
||||||
showConsumerDetailDialog: false,
|
showConsumerDetailDialog: false,
|
||||||
|
showAddSubscriptionDialog: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -201,6 +210,12 @@ export default {
|
|||||||
closeConsumerDetailDialog() {
|
closeConsumerDetailDialog() {
|
||||||
this.showConsumerDetailDialog = false;
|
this.showConsumerDetailDialog = false;
|
||||||
},
|
},
|
||||||
|
openAddSubscriptionDialog() {
|
||||||
|
this.showAddSubscriptionDialog = true;
|
||||||
|
},
|
||||||
|
closeAddSubscriptionDialog() {
|
||||||
|
this.showAddSubscriptionDialog = false;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getConsumerGroupList();
|
this.getConsumerGroupList();
|
||||||
|
|||||||
@@ -100,15 +100,9 @@ export default {
|
|||||||
watch: {
|
watch: {
|
||||||
visible(v) {
|
visible(v) {
|
||||||
this.show = v;
|
this.show = v;
|
||||||
if (this.show) {
|
|
||||||
this.getPartitionInfo();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getPartitionInfo() {
|
|
||||||
this.loading = false;
|
|
||||||
},
|
|
||||||
handleSubmit(e) {
|
handleSubmit(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.form.validateFields((err, values) => {
|
this.form.validateFields((err, values) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user