消息查询过滤
This commit is contained in:
@@ -79,7 +79,7 @@ public class MessageServiceImpl implements MessageService, ApplicationContextAwa
|
||||
public static String defaultDeserializer = "String";
|
||||
|
||||
@Override public ResponseData searchByTime(QueryMessage queryMessage) {
|
||||
int maxNums = 10000;
|
||||
int maxNums = 5000;
|
||||
|
||||
Object searchContent = null;
|
||||
String headerKey = null;
|
||||
@@ -139,14 +139,17 @@ public class MessageServiceImpl implements MessageService, ApplicationContextAwa
|
||||
|
||||
Set<TopicPartition> partitions = getPartitions(queryMessage);
|
||||
long startTime = System.currentTimeMillis();
|
||||
List<ConsumerRecord<byte[], byte[]>> records = messageConsole.searchBy(partitions, queryMessage.getStartTime(), queryMessage.getEndTime(), maxNums, filter);
|
||||
Tuple2<List<ConsumerRecord<byte[], byte[]>>, Object> tuple2 = messageConsole.searchBy(partitions, queryMessage.getStartTime(), queryMessage.getEndTime(), maxNums, filter);
|
||||
List<ConsumerRecord<byte[], byte[]>> records = tuple2._1();
|
||||
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<>();
|
||||
vos = vos.subList(0, Math.min(maxNums, vos.size()));
|
||||
res.put("maxNum", maxNums);
|
||||
res.put("realNum", vos.size());
|
||||
res.put("data", vos.subList(0, Math.min(maxNums, vos.size())));
|
||||
res.put("searchNum", tuple2._2());
|
||||
res.put("data", vos);
|
||||
return ResponseData.create().data(res).success();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import scala.jdk.CollectionConverters.{CollectionHasAsScala, MapHasAsScala, SeqH
|
||||
class MessageConsole(config: KafkaConfig) extends KafkaConsole(config: KafkaConfig) with Logging {
|
||||
|
||||
def searchBy(partitions: util.Collection[TopicPartition], startTime: Long, endTime: Long,
|
||||
maxNums: Int, filter: MessageFilter): util.List[ConsumerRecord[Array[Byte], Array[Byte]]] = {
|
||||
maxNums: Int, filter: MessageFilter): (util.List[ConsumerRecord[Array[Byte], Array[Byte]]], Int) = {
|
||||
var startOffTable: immutable.Map[TopicPartition, Long] = Map.empty
|
||||
var endOffTable: immutable.Map[TopicPartition, Long] = Map.empty
|
||||
withAdminClientAndCatchError(admin => {
|
||||
@@ -154,7 +154,7 @@ class MessageConsole(config: KafkaConfig) extends KafkaConsole(config: KafkaConf
|
||||
})
|
||||
}
|
||||
|
||||
res
|
||||
(res, searchNums)
|
||||
}
|
||||
|
||||
def searchBy(
|
||||
|
||||
@@ -92,7 +92,10 @@
|
||||
<a-col :span="8">
|
||||
<a-form-item label="消息类型">
|
||||
<a-select
|
||||
v-decorator="['valueDeserializer', { initialValue: 'String' }]"
|
||||
v-decorator="[
|
||||
'valueDeserializer',
|
||||
{ initialValue: 'String' },
|
||||
]"
|
||||
class="body-type"
|
||||
>
|
||||
<a-select-option
|
||||
@@ -125,7 +128,7 @@
|
||||
placeholder="消息头对应key的value"
|
||||
/>
|
||||
<span class="hint"
|
||||
>消息头的value不是字符串类型,就不要输入用来过滤了</span
|
||||
>消息头的value不是字符串类型,就不要输入value用来过滤了,可以只输入消息头的key,过滤存在该key的消息</span
|
||||
>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
@@ -135,9 +138,11 @@
|
||||
</div>
|
||||
<p style="margin-top: 1%">
|
||||
<strong
|
||||
>检索条数:{{ data.realNum }},允许返回的最大条数:{{
|
||||
>检索消息条数:{{ data.searchNum }},实际返回条数:{{
|
||||
data.realNum
|
||||
}},允许返回的最大条数:{{
|
||||
data.maxNum
|
||||
}}</strong
|
||||
}},如果当前时间段消息量太大,可以缩小查询时间范围或指定某一个分区进行查询</strong
|
||||
>
|
||||
</p>
|
||||
<MessageList :data="data.data"></MessageList>
|
||||
@@ -262,7 +267,7 @@ export default {
|
||||
this.getDeserializerList();
|
||||
},
|
||||
};
|
||||
const defaultData = { realNum: 0, maxNum: 0 };
|
||||
const defaultData = { realNum: 0, maxNum: 0, searchNum: 0 };
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user