Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #30]Supports batch resending and batch exporting dlq messages. #37

Merged
merged 2 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@
package org.apache.rocketmq.dashboard.controller;

import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.dashboard.exception.ServiceException;
import org.apache.rocketmq.dashboard.model.DlqMessageExcelModel;
import org.apache.rocketmq.dashboard.model.DlqMessageRequest;
import org.apache.rocketmq.dashboard.model.request.MessageQuery;
import org.apache.rocketmq.dashboard.permisssion.Permission;
import org.apache.rocketmq.dashboard.service.DlqMessageService;
import org.apache.rocketmq.dashboard.util.ExcelUtil;
import org.apache.rocketmq.tools.admin.MQAdminExt;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -39,6 +44,7 @@
@Controller
@RequestMapping("/dlqMessage")
@Permission
@Slf4j
public class DlqMessageController {

@Resource
Expand Down Expand Up @@ -70,4 +76,33 @@ public void exportDlqMessage(HttpServletResponse response, @RequestParam String
throw new ServiceException(-1, String.format("export dlq message failed!"));
}
}

@PostMapping(value = "/batchResendDlqMessage.do")
@ResponseBody
public Object batchResendDlqMessage(@RequestBody List<DlqMessageRequest> dlqMessages) {
return dlqMessageService.batchResendDlqMessage(dlqMessages);
}

@PostMapping(value = "/batchExportDlqMessage.do")
public void batchExportDlqMessage(HttpServletResponse response, @RequestBody List<DlqMessageRequest> dlqMessages) {
List<DlqMessageExcelModel> dlqMessageExcelModelList = new ArrayList<>(dlqMessages.size());
for (DlqMessageRequest dlqMessage : dlqMessages) {
DlqMessageExcelModel excelModel = new DlqMessageExcelModel();
try {
String topic = MixAll.DLQ_GROUP_TOPIC_PREFIX + dlqMessage.getConsumerGroup();
MessageExt messageExt = mqAdminExt.viewMessage(topic, dlqMessage.getMsgId());
excelModel = new DlqMessageExcelModel(messageExt);
} catch (Exception e) {
log.error("Failed to query message by Id:{}", dlqMessage.getMsgId(), e);
excelModel.setMsgId(dlqMessage.getMsgId());
excelModel.setException(e.getMessage());
}
dlqMessageExcelModelList.add(excelModel);
}
try {
ExcelUtil.writeExcel(response, dlqMessageExcelModelList, "dlqs", "dlqs", DlqMessageExcelModel.class);
} catch (Exception e) {
throw new ServiceException(-1, String.format("export dlq message failed!"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.rocketmq.common.message.MessageExt;

@Data
@NoArgsConstructor
public class DlqMessageExcelModel extends BaseRowModel implements Serializable {

@ExcelProperty(value = "topic", index = 0)
Expand Down Expand Up @@ -66,6 +68,10 @@ public class DlqMessageExcelModel extends BaseRowModel implements Serializable {
@ColumnWidth(value = 15)
private int bodyCRC;

@ExcelProperty(value = "exception", index = 9)
@ColumnWidth(value = 30)
private String exception;

public DlqMessageExcelModel(MessageExt messageExt) {
this.topic = messageExt.getTopic();
this.msgId = messageExt.getMsgId();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.dashboard.model;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getters/setters can be generated by @Data

import lombok.Data;

@Data
public class DlqMessageRequest {

private String topicName;

private String consumerGroup;

private String msgId;

private String clientId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.dashboard.model;

import lombok.Data;
import org.apache.rocketmq.common.protocol.body.CMResult;
import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult;

@Data
public class DlqMessageResendResult {
private CMResult consumeResult;
private String remark;
private String msgId;

public DlqMessageResendResult(ConsumeMessageDirectlyResult consumeMessageDirectlyResult, String msgId) {
this.consumeResult = consumeMessageDirectlyResult.getConsumeResult();
this.remark = consumeMessageDirectlyResult.getRemark();
this.msgId = msgId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@

package org.apache.rocketmq.dashboard.service;

import java.util.List;
import org.apache.rocketmq.dashboard.model.DlqMessageResendResult;
import org.apache.rocketmq.dashboard.model.DlqMessageRequest;
import org.apache.rocketmq.dashboard.model.MessagePage;
import org.apache.rocketmq.dashboard.model.request.MessageQuery;

public interface DlqMessageService {

MessagePage queryDlqMessageByPage(MessageQuery query);

List<DlqMessageResendResult> batchResendDlqMessage(List<DlqMessageRequest> dlqMessages);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@

import com.google.common.base.Throwables;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.protocol.ResponseCode;
import org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult;
import org.apache.rocketmq.dashboard.model.DlqMessageResendResult;
import org.apache.rocketmq.dashboard.model.DlqMessageRequest;
import org.apache.rocketmq.dashboard.model.MessagePage;
import org.apache.rocketmq.dashboard.model.MessageView;
import org.apache.rocketmq.dashboard.model.request.MessageQuery;
Expand Down Expand Up @@ -65,4 +69,17 @@ public MessagePage queryDlqMessageByPage(MessageQuery query) {
}
return messageService.queryMessageByPage(query);
}

@Override
public List<DlqMessageResendResult> batchResendDlqMessage(List<DlqMessageRequest> dlqMessages) {
List<DlqMessageResendResult> batchResendResults = new LinkedList<>();
for (DlqMessageRequest dlqMessage : dlqMessages) {
ConsumeMessageDirectlyResult result = messageService.consumeMessageDirectly(dlqMessage.getTopicName(),
dlqMessage.getMsgId(), dlqMessage.getConsumerGroup(),
dlqMessage.getClientId());
DlqMessageResendResult resendResult = new DlqMessageResendResult(result, dlqMessage.getMsgId());
batchResendResults.add(resendResult);
}
return batchResendResults;
}
}
107 changes: 107 additions & 0 deletions src/main/resources/static/src/dlqMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ module.controller('dlqMessageController', ['$scope', 'ngDialog', '$http', 'Notif
if ($scope.messageShowList.length == 0){
$("#noMsgTip").removeAttr("style");
}
for (const message of $scope.messageShowList) {
message.checked = false;
}
console.log($scope.messageShowList);
if (resp.data.page.first) {
$scope.paginationConf.currentPage = 1;
Expand Down Expand Up @@ -180,5 +183,109 @@ module.controller('dlqMessageController', ['$scope', 'ngDialog', '$http', 'Notif

$scope.exportDlqMessage = function (msgId, consumerGroup) {
window.location.href = "dlqMessage/exportDlqMessage.do?msgId=" + msgId + "&consumerGroup=" + consumerGroup;
};

$scope.selectedDlqMessage = [];
$scope.batchResendDlqMessage = function (consumerGroup) {
for (const message of $scope.messageCheckedList) {
const dlqMessage = {};
dlqMessage.topic = message.properties.RETRY_TOPIC;
dlqMessage.msgId = message.properties.ORIGIN_MESSAGE_ID;
dlqMessage.consumerGroup = consumerGroup;
$scope.selectedDlqMessage.push(dlqMessage);
}
$http({
method: "POST",
url: "dlqMessage/batchResendDlqMessage.do",
data: $scope.selectedDlqMessage
}).success(function (resp) {
$scope.selectedDlqMessage = [];
if (resp.status == 0) {
ngDialog.open({
template: 'operationResultDialog',
data: {
result: resp.data
}
});
} else {
ngDialog.open({
template: 'operationResultDialog',
data: {
result: resp.errMsg
}
});
}
});
};

$scope.batchExportDlqMessage = function (consumerGroup) {
for (const message of $scope.messageCheckedList) {
const dlqMessage = {};
dlqMessage.msgId = message.msgId;
dlqMessage.consumerGroup = consumerGroup;
$scope.selectedDlqMessage.push(dlqMessage);
}
$http({
method: "POST",
url: "dlqMessage/batchExportDlqMessage.do",
data: $scope.selectedDlqMessage,
headers: {
'Content-type': 'application/json'
},
responseType: "arraybuffer"
}).success(function (resp) {
$scope.selectedDlqMessage = [];
const blob = new Blob([resp], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
const objectUrl = URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.download = 'dlqs.xlsx';
a.href = objectUrl;
a.click();
document.body.removeChild(a)
});
};

$scope.checkedAll = false;
$scope.messageCheckedList = [];
$scope.selectAll = function () {
$scope.messageCheckedList = [];
if ($scope.checkedAll == true) {
angular.forEach($scope.messageShowList, function (item, index) {
item.checked = true;
$scope.messageCheckedList.push(item);
});
} else {
angular.forEach($scope.messageShowList, function (item, index) {
item.checked = false;
});
}
checkBtn($scope.messageCheckedList)
console.log($scope.messageCheckedList)
}

$scope.selectItem = function () {
var flag = true;
$scope.messageCheckedList = [];
angular.forEach($scope.messageShowList, function (item, index) {
if (item.checked) {
$scope.messageCheckedList.push(item);
} else {
flag = false;
}
})
$scope.checkedAll = flag;
checkBtn($scope.messageCheckedList)
console.log($scope.messageCheckedList);
}

function checkBtn(messageCheckList) {
if (messageCheckList.length == 0) {
$("#batchResendBtn").addClass("disabled");
$("#batchExportBtn").addClass("disabled");
} else {
$("#batchResendBtn").removeClass("disabled");
$("#batchExportBtn").removeClass("disabled");
}
}
}]);
4 changes: 3 additions & 1 deletion src/main/resources/static/src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,7 @@ var en = {
"TRACE_TOPIC":"TraceTopic",
"SELECT_TRACE_TOPIC":"selectTraceTopic",
"EXPORT": "export",
"NO_MATCH_RESULT": "no match result"
"NO_MATCH_RESULT": "no match result",
"BATCH_RESEND": "batchReSend",
"BATCH_EXPORT": "batchExport"
}
4 changes: 3 additions & 1 deletion src/main/resources/static/src/i18n/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@ var zh = {
"TRACE_TOPIC":"消息轨迹主题",
"SELECT_TRACE_TOPIC":"选择消息轨迹主题",
"EXPORT": "导出",
"NO_MATCH_RESULT": "没有查到符合条件的结果"
"NO_MATCH_RESULT": "没有查到符合条件的结果",
"BATCH_RESEND": "批量重发",
"BATCH_EXPORT": "批量导出"
}
18 changes: 17 additions & 1 deletion src/main/resources/static/view/pages/dlqMessage.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,22 @@ <h5 class="md-display-5">Total {{paginationConf.totalItems}} Messages</h5>
ng-click="queryDlqMessageByConsumerGroup()">
<span class="glyphicon glyphicon-search"></span> {{ 'SEARCH' | translate}}
</button>
<button type="button" id="batchResendBtn"
class="btn btn-raised btn-sm btn-primary disabled"
data-toggle="modal"
ng-click="batchResendDlqMessage(selectedConsumerGroup)">
<span class="glyphicon glyphicon-send"></span> {{ 'BATCH_RESEND' | translate}}
</button>
<button type="button" id="batchExportBtn"
class="btn btn-raised btn-sm btn-primary disabled"
data-toggle="modal"
ng-click="batchExportDlqMessage(selectedConsumerGroup)">
<span class="glyphicon glyphicon-export"></span> {{ 'BATCH_EXPORT' | translate}}
</button>
</form>
<table class="table table-bordered text-middle">
<tr>
<th class="text-center"><input type="checkbox" ng-model='checkedAll' ng-change="selectAll()"/></th>
<th class="text-center">Message ID</th>
<th class="text-center">Tag</th>
<th class="text-center">Key</th>
Expand All @@ -77,6 +90,9 @@ <h5 class="md-display-5">Total {{paginationConf.totalItems}} Messages</h5>
<td colspan="6" style="text-align: center">{{'NO_MATCH_RESULT' | translate}}</td>
</tr>
<tr ng-repeat="item in messageShowList">
<td class="text-center">
<input type="checkbox" ng-model='item.checked' ng-change="selectItem()"/>
</td>
<td class="text-center">{{item.msgId}}</td>
<td class="text-center">{{item.properties.TAGS}}</td>
<td class="text-center">{{item.properties.KEYS}}</td>
Expand Down Expand Up @@ -192,7 +208,7 @@ <h5 class="md-display-5">topic can't be empty if you producer client version>=v3
<label class="control-label col-sm-2">Properties:</label>
<div class="col-sm-10">
<textarea class="form-control"
style="min-height:60px; resize: none"
style="min-height:100px; resize: none"
readonly>{{ngDialogData.messageView.properties}}</textarea>
</div>
</div>
Expand Down
Loading