|
|
package com.sunyo.wlpt.message.bus.service.service.view;
|
|
|
|
|
|
import com.rabbitmq.http.client.domain.QueueInfo;
|
|
|
import com.sunyo.wlpt.message.bus.service.domain.BusServer;
|
|
|
import com.sunyo.wlpt.message.bus.service.domain.VirtualHost;
|
|
|
import com.sunyo.wlpt.message.bus.service.domain.view.ViewQueueInfo;
|
|
|
import com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper;
|
|
|
import com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper;
|
|
|
import com.sunyo.wlpt.message.bus.service.rabbit.utils.ClientUtils;
|
...
|
...
|
@@ -32,17 +32,16 @@ public class ViewQueueFactory { |
|
|
@Resource
|
|
|
private VirtualHostMapper virtualHostMapper;
|
|
|
|
|
|
public ResultJson getViewQueueList(String serverName, String virtualHostName, Integer pageNum, Integer pageSize) throws IOException,
|
|
|
URISyntaxException
|
|
|
public ResultJson getViewQueueList(String serverName, String virtualHostName, Integer pageNum, Integer pageSize) throws IOException, URISyntaxException
|
|
|
{
|
|
|
List<QueueInfo> list = new ArrayList<>();
|
|
|
List<ViewQueueInfo> list = new ArrayList<>();
|
|
|
|
|
|
// 服务器名称、虚拟主机名称,均为空
|
|
|
if (StringUtil.isNullOrEmpty(serverName) && StringUtil.isNullOrEmpty(virtualHostName)) {
|
|
|
List<BusServer> serverList = busServerMapper.getServerList();
|
|
|
for (BusServer busServer : serverList) {
|
|
|
List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer);
|
|
|
list.addAll(queueInfoList);
|
|
|
List<ViewQueueInfo> viewQueueInfoList = ClientUtils.getViewQueues(busServer);
|
|
|
list.addAll(viewQueueInfoList);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -52,8 +51,8 @@ public class ViewQueueFactory { |
|
|
if (busServer == null) {
|
|
|
return new ResultJson("400", "该服务器名称不存在,请仔细检查");
|
|
|
}
|
|
|
List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer);
|
|
|
list.addAll(queueInfoList);
|
|
|
List<ViewQueueInfo> viewQueueInfoList = ClientUtils.getViewQueues(busServer);
|
|
|
list.addAll(viewQueueInfoList);
|
|
|
}
|
|
|
|
|
|
// 仅,虚拟主机名称不为空
|
...
|
...
|
@@ -63,8 +62,8 @@ public class ViewQueueFactory { |
|
|
return new ResultJson("400", "该虚拟主机名称不存在,请仔细检查");
|
|
|
}
|
|
|
BusServer busServer = busServerMapper.selectByPrimaryKey(virtualHost.getServerId());
|
|
|
List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer, virtualHostName);
|
|
|
list.addAll(queueInfoList);
|
|
|
List<ViewQueueInfo> viewQueueInfoList = ClientUtils.getViewQueues(busServer, virtualHostName);
|
|
|
list.addAll(viewQueueInfoList);
|
|
|
}
|
|
|
|
|
|
// 服务器名称、虚拟主机名称,均不为空
|
...
|
...
|
@@ -80,13 +79,13 @@ public class ViewQueueFactory { |
|
|
if (!virtualHost.getServerId().equals(busServer.getId())) {
|
|
|
return new ResultJson("400", "该虚拟主机不属于该服务器,请仔细检查");
|
|
|
}
|
|
|
List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer, virtualHostName);
|
|
|
list.addAll(queueInfoList);
|
|
|
List<ViewQueueInfo> viewQueueInfoList = ClientUtils.getViewQueues(busServer, virtualHostName);
|
|
|
list.addAll(viewQueueInfoList);
|
|
|
}
|
|
|
Integer total = list.size();
|
|
|
|
|
|
// 达到分页与排序效果
|
|
|
List<QueueInfo> resultList = subList(pageNum, pageSize, list);
|
|
|
List<ViewQueueInfo> resultList = subAndSortList(pageNum, pageSize, list);
|
|
|
return resultList.size() > 0
|
|
|
? new ResultJson<>("200", "查询队列监控,成功!", resultList, total)
|
|
|
: new ResultJson<>("500", "查询队列监控,失败!");
|
...
|
...
|
@@ -100,7 +99,7 @@ public class ViewQueueFactory { |
|
|
* @param list 全部的数据
|
|
|
* @return List<QueueInfo>
|
|
|
*/
|
|
|
public List<QueueInfo> subList(Integer pageNum, Integer pageSize, List<QueueInfo> list)
|
|
|
public List<ViewQueueInfo> subAndSortList(Integer pageNum, Integer pageSize, List<ViewQueueInfo> list)
|
|
|
{
|
|
|
Integer total = list.size();
|
|
|
Integer start = (pageNum - 1) * pageSize;
|
...
|
...
|
@@ -112,10 +111,11 @@ public class ViewQueueFactory { |
|
|
if (end > total) {
|
|
|
end = total;
|
|
|
}
|
|
|
List<QueueInfo> pageList = list.subList(start, end);
|
|
|
// 对总信息数,进行降序排序
|
|
|
List<QueueInfo> resultList =
|
|
|
pageList.stream().sorted(Comparator.comparing(QueueInfo::getTotalMessages).reversed()).collect(Collectors.toList());
|
|
|
List<ViewQueueInfo> pageList = list.subList(start, end);
|
|
|
// 对积压数,进行降序排序
|
|
|
List<ViewQueueInfo> resultList =
|
|
|
pageList.stream().sorted(Comparator.comparing(ViewQueueInfo::getMessageReady).reversed())
|
|
|
.collect(Collectors.toList());
|
|
|
return resultList;
|
|
|
}
|
|
|
} |
...
|
...
|
|