fix按时间查询消息bug,加长页面请求超时

This commit is contained in:
许晓东
2021-12-13 19:05:57 +08:00
parent 57a41e087f
commit b9548d1640
6 changed files with 37 additions and 27 deletions

View File

@@ -18,6 +18,7 @@ import java.util.stream.Collectors;
import kafka.console.ConsumerConsole;
import kafka.console.MessageConsole;
import kafka.console.TopicConsole;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.admin.TopicDescription;
@@ -40,6 +41,7 @@ import org.springframework.stereotype.Service;
* @author xuxd
* @date 2021-12-11 09:43:44
**/
@Slf4j
@Service
public class MessageServiceImpl implements MessageService, ApplicationContextAware {
@@ -69,7 +71,9 @@ public class MessageServiceImpl implements MessageService, ApplicationContextAwa
int maxNums = 10000;
Set<TopicPartition> partitions = getPartitions(queryMessage);
long startTime = System.currentTimeMillis();
List<ConsumerRecord<byte[], byte[]>> records = messageConsole.searchBy(partitions, queryMessage.getStartTime(), queryMessage.getEndTime(), maxNums);
log.info("search message by time, cost time: {}", (System.currentTimeMillis() - startTime));
List<ConsumerRecordVO> vos = records.stream().filter(record -> record.timestamp() <= queryMessage.getEndTime())
.map(ConsumerRecordVO::fromConsumerRecord).collect(Collectors.toList());
Map<String, Object> res = new HashMap<>();

View File

@@ -55,25 +55,26 @@ class MessageConsole(config: KafkaConfig) extends KafkaConsole(config: KafkaConf
} else {
val records = consumer.poll(Duration.ofMillis(timeoutMs))
for ((tp, endOff) <- endOffTable) {
if (!terminate) {
val recordList = records.records(tp)
if (recordList.isEmpty) {
arrive.remove(tp)
} else {
val first = recordList.get(0)
if (first.offset() >= endOff) {
arrive.remove(tp)
} else {
res.addAll(recordList)
if (recordList.get(recordList.size() - 1).offset() >= endOff) {
if (records.isEmpty) {
terminate = true
} else {
for ((tp, endOff) <- endOffTable) {
if (!terminate) {
val recordList = records.records(tp)
if (!recordList.isEmpty) {
val first = recordList.get(0)
if (first.offset() >= endOff) {
arrive.remove(tp)
} else {
res.addAll(recordList)
if (recordList.get(recordList.size() - 1).offset() >= endOff) {
arrive.remove(tp)
}
}
}
}
if (arrive.isEmpty) {
terminate = true;
if (arrive.isEmpty) {
terminate = true;
}
}
}
}

View File

@@ -6,7 +6,7 @@ import { VueAxios } from "./axios";
const request = axios.create({
// API 请求的默认前缀
baseURL: process.env.VUE_APP_API_BASE_URL,
timeout: 30000, // 请求超时时间
timeout: 120000, // 请求超时时间
});
// 异常拦截处理器

View File

@@ -150,7 +150,7 @@ export default {
},
methods: {
getMessageDetail() {
this.loading = false;
this.loading = true;
const params = Object.assign({}, this.record, {
keyDeserializer: this.keyDeserializer,
valueDeserializer: this.valueDeserializer,

View File

@@ -8,10 +8,10 @@
@submit="handleSearch"
>
<a-row :gutter="24">
<a-col :span="6">
<a-col :span="9">
<a-form-item label="topic">
<a-select
class="type-select"
class="topic-select"
@change="handleTopicChange"
show-search
option-filter-prop="children"
@@ -44,7 +44,7 @@
</a-select>
</a-form-item>
</a-col>
<a-col :span="10">
<a-col :span="7">
<a-form-item label="偏移">
<a-input
v-decorator="[
@@ -185,7 +185,9 @@ const defaultData = [];
text-align: center;
padding-top: 80px;
}
.topic-select {
width: 400px !important;
}
.type-select {
width: 200px !important;
}

View File

@@ -8,10 +8,10 @@
@submit="handleSearch"
>
<a-row :gutter="24">
<a-col :span="6">
<a-col :span="9">
<a-form-item label="topic">
<a-select
class="type-select"
class="topic-select"
@change="handleTopicChange"
show-search
option-filter-prop="children"
@@ -29,7 +29,7 @@
</a-select>
</a-form-item>
</a-col>
<a-col :span="6">
<a-col :span="5">
<a-form-item label="分区">
<a-select
class="type-select"
@@ -44,7 +44,7 @@
</a-select>
</a-form-item>
</a-col>
<a-col :span="10">
<a-col :span="8">
<a-form-item label="时间">
<a-range-picker
v-decorator="['time', rangeConfig]"
@@ -190,8 +190,11 @@ const defaultData = { realNum: 0, maxNum: 0 };
text-align: center;
padding-top: 80px;
}
.topic-select {
width: 400px !important;
}
.type-select {
width: 200px !important;
width: 150px !important;
}
</style>