RocketMQ Dashboard 消息重复问题排查与修复(rocketmq-dashboard-2.0.0-source-release)
消息重复问题排查与修复
版本:rocketmq-dashboard-2.0.0-source-release
1. 消息重复问题描述
用 RocketMQMQ 生产者发送消息,发送一条
消息,通过 Dashboard 的 “消息” 页面 “搜索”,显示两条
消息,并且两条消息的 Message ID
是相同的。
1.1. 消息重复示例
1.2. 消息搜索接口的请求和响应
接口请求:
curl 'http://localhost:8080/message/queryMessagePageByTopic.query' \-H 'Accept: application/json, text/plain, */*' \-H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' \-H 'Cache-Control: no-cache' \-H 'Connection: keep-alive' \-H 'Content-Type: application/json;charset=UTF-8' \-b 'Idea-1cf71e24=46729fe7-bf13-4272-8379-df12bc6e308f; NG_TRANSLATE_LANG_KEY=%22zh%22' \-H 'Origin: http://localhost:8080' \-H 'Pragma: no-cache' \-H 'Referer: http://localhost:8080/' \-H 'Sec-Fetch-Dest: empty' \-H 'Sec-Fetch-Mode: cors' \-H 'Sec-Fetch-Site: same-origin' \-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0' \-H 'sec-ch-ua: "Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"' \-H 'sec-ch-ua-mobile: ?0' \-H 'sec-ch-ua-platform: "Windows"' \--data-raw '{"topic":"test-topic-4","begin":1735735080000,"end":1758123480000,"pageNum":1,"pageSize":20,"taskId":"A9FEED5B2E6836BAF30C5778902B0000"}'
接口响应,content 列表中包含 msgId
相同的对象:
{"status": 0,"data": {"page": {"content": [{"queueId": 6,"storeSize": 331,"queueOffset": 0,"sysFlag": 0,"bornTimestamp": 1756052661892,"bornHost": "192.168.56.1:51548","storeTimestamp": 1756052661982,"storeHost": "192.168.56.1:10911","msgId": "A9FEED5B07D436BAF30C7BAEEE820000","commitLogOffset": 1848,"bodyCRC": 1816839120,"reconsumeTimes": 0,"preparedTransactionOffset": 0,"topic": "test-topic-4","flag": 0,"properties": {"MSG_REGION": "DefaultRegion","id": "184dfa8f-d04c-6516-bbcf-66715dc274c6","UNIQ_KEY": "A9FEED5B07D436BAF30C7BAEEE820000","CLUSTER": "DefaultCluster","contentType": "text/plain;charset=UTF-8","MIN_OFFSET": "0","WAIT": "true","timestamp": "1756052661081","TRACE_ON": "true","MAX_OFFSET": "1"},"messageBody": "Hello, World!"},{"queueId": 6,"storeSize": 331,"queueOffset": 0,"sysFlag": 0,"bornTimestamp": 1756052661892,"bornHost": "192.168.56.1:51548","storeTimestamp": 1756052661982,"storeHost": "192.168.56.1:10911","msgId": "A9FEED5B07D436BAF30C7BAEEE820000","commitLogOffset": 1848,"bodyCRC": 1816839120,"reconsumeTimes": 0,"preparedTransactionOffset": 0,"topic": "test-topic-4","flag": 0,"properties": {"MSG_REGION": "DefaultRegion","id": "184dfa8f-d04c-6516-bbcf-66715dc274c6","UNIQ_KEY": "A9FEED5B07D436BAF30C7BAEEE820000","CLUSTER": "DefaultCluster","contentType": "text/plain;charset=UTF-8","MIN_OFFSET": "0","WAIT": "true","timestamp": "1756052661081","TRACE_ON": "true","MAX_OFFSET": "1"},"messageBody": "Hello, World!"},{"queueId": 4,"storeSize": 331,"queueOffset": 0,"sysFlag": 0,"bornTimestamp": 1756051562107,"bornHost": "192.168.56.1:51227","storeTimestamp": 1756051562178,"storeHost": "192.168.56.1:10911","msgId": "A9FEED5B3F9436BAF30C7B9E26790000","commitLogOffset": 1517,"bodyCRC": 1816839120,"reconsumeTimes": 0,"preparedTransactionOffset": 0,"topic": "test-topic-4","flag": 0,"properties": {"MSG_REGION": "DefaultRegion","id": "efbe275d-0298-8bed-919b-de92b53e4e9e","UNIQ_KEY": "A9FEED5B3F9436BAF30C7B9E26790000","CLUSTER": "DefaultCluster","contentType": "text/plain;charset=UTF-8","MIN_OFFSET": "0","WAIT": "true","timestamp": "1756051561125","TRACE_ON": "true","MAX_OFFSET": "1"},"messageBody": "Hello, World!"},{"queueId": 4,"storeSize": 331,"queueOffset": 0,"sysFlag": 0,"bornTimestamp": 1756051562107,"bornHost": "192.168.56.1:51227","storeTimestamp": 1756051562178,"storeHost": "192.168.56.1:10911","msgId": "A9FEED5B3F9436BAF30C7B9E26790000","commitLogOffset": 1517,"bodyCRC": 1816839120,"reconsumeTimes": 0,"preparedTransactionOffset": 0,"topic": "test-topic-4","flag": 0,"properties": {"MSG_REGION": "DefaultRegion","id": "efbe275d-0298-8bed-919b-de92b53e4e9e","UNIQ_KEY": "A9FEED5B3F9436BAF30C7B9E26790000","CLUSTER": "DefaultCluster","contentType": "text/plain;charset=UTF-8","MIN_OFFSET": "0","WAIT": "true","timestamp": "1756051561125","TRACE_ON": "true","MAX_OFFSET": "1"},"messageBody": "Hello, World!"}],"pageable": {"sort": {"sorted": false,"unsorted": true,"empty": true},"offset": 0,"pageNumber": 0,"pageSize": 20,"paged": true,"unpaged": false},"totalElements": 4,"totalPages": 1,"last": true,"size": 20,"number": 0,"sort": {"sorted": false,"unsorted": true,"empty": true},"first": true,"numberOfElements": 4,"empty": false},"taskId": "A9FEED5B2E6836BAF30C5778902B0000"},"errMsg": null
}
2. 问题原因:Dashboard 漏洞
问题原因:Dashboard漏洞,需要通过改代码修复
参考资料:
《RocketMQ查询出重复数据,两条MessageID一样的解决办法如下》:
https://blog.csdn.net/weixin_44853310/article/details/139594123
《RocketMQ中dashboard 怎么显示2条一样的消息。是配置问题?》
https://developer.aliyun.com/ask/543579
3. 修复方法
修改下面方法中的漏洞,修改方案如下:
org.apache.rocketmq.dashboard.service.impl.MessageServiceImpl#queryFirstMessagePage
// 去掉 + 1 ,避免消息重复// Long maxOffset = consumer.searchOffset(messageQueue, query.getEnd()) + 1;Long maxOffset = consumer.searchOffset(messageQueue, query.getEnd());
修改示例:
4. 修复效果:消息不再重复
5. 最新版代码中已修复
在 RocketMQ Dashboard 代码的最新版本中,这个Bug已经修复了。