正在显示
3 个修改的文件
包含
79 行增加
和
26 行删除
1 | +package com.sunyo.wlpt.message.bus.service.domain.view; | ||
2 | + | ||
3 | +import com.rabbitmq.http.client.domain.QueueInfo; | ||
4 | +import lombok.AllArgsConstructor; | ||
5 | +import lombok.Builder; | ||
6 | +import lombok.Data; | ||
7 | +import lombok.NoArgsConstructor; | ||
8 | + | ||
9 | +/** | ||
10 | + * @author 子诚 | ||
11 | + * Description: | ||
12 | + * 时间:2020/8/27 14:29 | ||
13 | + */ | ||
14 | +@Data | ||
15 | +@Builder | ||
16 | +@AllArgsConstructor | ||
17 | +@NoArgsConstructor | ||
18 | +public class ViewQueueInfo { | ||
19 | + private String serverName; | ||
20 | + private QueueInfo queueInfo; | ||
21 | + | ||
22 | + /** | ||
23 | + * 排序参数,消息挤压数量 | ||
24 | + * | ||
25 | + * @return | ||
26 | + */ | ||
27 | + public long getMessageReady() | ||
28 | + { | ||
29 | + return queueInfo.getMessagesReady(); | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * 排序参数,消息总数量 | ||
34 | + * | ||
35 | + * @return | ||
36 | + */ | ||
37 | + public long getTotalMessages() | ||
38 | + { | ||
39 | + return queueInfo.getTotalMessages(); | ||
40 | + } | ||
41 | +} |
@@ -6,6 +6,7 @@ import com.rabbitmq.http.client.domain.UserPermissions; | @@ -6,6 +6,7 @@ import com.rabbitmq.http.client.domain.UserPermissions; | ||
6 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; | 6 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; |
7 | import com.sunyo.wlpt.message.bus.service.domain.UserInfo; | 7 | import com.sunyo.wlpt.message.bus.service.domain.UserInfo; |
8 | import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; | 8 | import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; |
9 | +import com.sunyo.wlpt.message.bus.service.domain.view.ViewQueueInfo; | ||
9 | import com.sunyo.wlpt.message.bus.service.utils.AESUtils; | 10 | import com.sunyo.wlpt.message.bus.service.utils.AESUtils; |
10 | 11 | ||
11 | import java.io.IOException; | 12 | import java.io.IOException; |
@@ -154,39 +155,50 @@ public class ClientUtils { | @@ -154,39 +155,50 @@ public class ClientUtils { | ||
154 | /** | 155 | /** |
155 | * 获取MQ界面的队列信息,重载 | 156 | * 获取MQ界面的队列信息,重载 |
156 | * | 157 | * |
157 | - * @param busServer | 158 | + * @param busServer MQ服务器 |
158 | * @return | 159 | * @return |
159 | * @throws IOException | 160 | * @throws IOException |
160 | * @throws URISyntaxException | 161 | * @throws URISyntaxException |
161 | */ | 162 | */ |
162 | - public static List<QueueInfo> getViewQueues(BusServer busServer) throws IOException, URISyntaxException | 163 | + public static List<ViewQueueInfo> getViewQueues(BusServer busServer) throws IOException, URISyntaxException |
163 | { | 164 | { |
164 | Client client = connectClient(busServer); | 165 | Client client = connectClient(busServer); |
165 | List<QueueInfo> queues = client.getQueues(); | 166 | List<QueueInfo> queues = client.getQueues(); |
166 | - return queues; | 167 | + return reformatQueueInfo(busServer.getServerName(), queues); |
168 | + } | ||
169 | + | ||
170 | + public static List<ViewQueueInfo> reformatQueueInfo(String serverName, List<QueueInfo> queues) | ||
171 | + { | ||
172 | + List<ViewQueueInfo> list = new ArrayList<>(); | ||
173 | + // 将获取到的队列信息,拼接一个属性,服务器名称 | ||
174 | + for (QueueInfo queueInfo : queues) { | ||
175 | + ViewQueueInfo viewQueueInfo = ViewQueueInfo.builder().queueInfo(queueInfo).serverName(serverName).build(); | ||
176 | + list.add(viewQueueInfo); | ||
177 | + } | ||
178 | + return list; | ||
167 | } | 179 | } |
168 | 180 | ||
169 | /** | 181 | /** |
170 | * 获取MQ界面的队列信息,重载 | 182 | * 获取MQ界面的队列信息,重载 |
171 | * | 183 | * |
172 | - * @param busServer | ||
173 | - * @param vHostName | 184 | + * @param busServer MQ服务器 |
185 | + * @param vHostName 虚拟主机名称 | ||
174 | * @return | 186 | * @return |
175 | * @throws IOException | 187 | * @throws IOException |
176 | * @throws URISyntaxException | 188 | * @throws URISyntaxException |
177 | */ | 189 | */ |
178 | - public static List<QueueInfo> getViewQueues(BusServer busServer, String vHostName) throws IOException, URISyntaxException | 190 | + public static List<ViewQueueInfo> getViewQueues(BusServer busServer, String vHostName) throws IOException, URISyntaxException |
179 | { | 191 | { |
180 | Client client = connectClient(busServer); | 192 | Client client = connectClient(busServer); |
181 | List<QueueInfo> queues = client.getQueues(vHostName); | 193 | List<QueueInfo> queues = client.getQueues(vHostName); |
182 | - return queues; | 194 | + return reformatQueueInfo(busServer.getServerName(), queues); |
183 | } | 195 | } |
184 | 196 | ||
185 | /** | 197 | /** |
186 | * 获取MQ界面的队列信息,重载 | 198 | * 获取MQ界面的队列信息,重载 |
187 | * | 199 | * |
188 | * @param busServer MQ服务器信息 | 200 | * @param busServer MQ服务器信息 |
189 | - * @param vHostName 虚拟主机 | 201 | + * @param vHostName 虚拟主机 |
190 | * @param queueName 队列名称 | 202 | * @param queueName 队列名称 |
191 | * @return | 203 | * @return |
192 | * @throws IOException | 204 | * @throws IOException |
1 | package com.sunyo.wlpt.message.bus.service.service.view; | 1 | package com.sunyo.wlpt.message.bus.service.service.view; |
2 | 2 | ||
3 | -import com.rabbitmq.http.client.domain.QueueInfo; | ||
4 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; | 3 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; |
5 | import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; | 4 | import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; |
5 | +import com.sunyo.wlpt.message.bus.service.domain.view.ViewQueueInfo; | ||
6 | import com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper; | 6 | import com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper; |
7 | import com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper; | 7 | import com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper; |
8 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.ClientUtils; | 8 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.ClientUtils; |
@@ -32,17 +32,16 @@ public class ViewQueueFactory { | @@ -32,17 +32,16 @@ public class ViewQueueFactory { | ||
32 | @Resource | 32 | @Resource |
33 | private VirtualHostMapper virtualHostMapper; | 33 | private VirtualHostMapper virtualHostMapper; |
34 | 34 | ||
35 | - public ResultJson getViewQueueList(String serverName, String virtualHostName, Integer pageNum, Integer pageSize) throws IOException, | ||
36 | - URISyntaxException | 35 | + public ResultJson getViewQueueList(String serverName, String virtualHostName, Integer pageNum, Integer pageSize) throws IOException, URISyntaxException |
37 | { | 36 | { |
38 | - List<QueueInfo> list = new ArrayList<>(); | 37 | + List<ViewQueueInfo> list = new ArrayList<>(); |
39 | 38 | ||
40 | // 服务器名称、虚拟主机名称,均为空 | 39 | // 服务器名称、虚拟主机名称,均为空 |
41 | if (StringUtil.isNullOrEmpty(serverName) && StringUtil.isNullOrEmpty(virtualHostName)) { | 40 | if (StringUtil.isNullOrEmpty(serverName) && StringUtil.isNullOrEmpty(virtualHostName)) { |
42 | List<BusServer> serverList = busServerMapper.getServerList(); | 41 | List<BusServer> serverList = busServerMapper.getServerList(); |
43 | for (BusServer busServer : serverList) { | 42 | for (BusServer busServer : serverList) { |
44 | - List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer); | ||
45 | - list.addAll(queueInfoList); | 43 | + List<ViewQueueInfo> viewQueueInfoList = ClientUtils.getViewQueues(busServer); |
44 | + list.addAll(viewQueueInfoList); | ||
46 | } | 45 | } |
47 | } | 46 | } |
48 | 47 | ||
@@ -52,8 +51,8 @@ public class ViewQueueFactory { | @@ -52,8 +51,8 @@ public class ViewQueueFactory { | ||
52 | if (busServer == null) { | 51 | if (busServer == null) { |
53 | return new ResultJson("400", "该服务器名称不存在,请仔细检查"); | 52 | return new ResultJson("400", "该服务器名称不存在,请仔细检查"); |
54 | } | 53 | } |
55 | - List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer); | ||
56 | - list.addAll(queueInfoList); | 54 | + List<ViewQueueInfo> viewQueueInfoList = ClientUtils.getViewQueues(busServer); |
55 | + list.addAll(viewQueueInfoList); | ||
57 | } | 56 | } |
58 | 57 | ||
59 | // 仅,虚拟主机名称不为空 | 58 | // 仅,虚拟主机名称不为空 |
@@ -63,8 +62,8 @@ public class ViewQueueFactory { | @@ -63,8 +62,8 @@ public class ViewQueueFactory { | ||
63 | return new ResultJson("400", "该虚拟主机名称不存在,请仔细检查"); | 62 | return new ResultJson("400", "该虚拟主机名称不存在,请仔细检查"); |
64 | } | 63 | } |
65 | BusServer busServer = busServerMapper.selectByPrimaryKey(virtualHost.getServerId()); | 64 | BusServer busServer = busServerMapper.selectByPrimaryKey(virtualHost.getServerId()); |
66 | - List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer, virtualHostName); | ||
67 | - list.addAll(queueInfoList); | 65 | + List<ViewQueueInfo> viewQueueInfoList = ClientUtils.getViewQueues(busServer, virtualHostName); |
66 | + list.addAll(viewQueueInfoList); | ||
68 | } | 67 | } |
69 | 68 | ||
70 | // 服务器名称、虚拟主机名称,均不为空 | 69 | // 服务器名称、虚拟主机名称,均不为空 |
@@ -80,13 +79,13 @@ public class ViewQueueFactory { | @@ -80,13 +79,13 @@ public class ViewQueueFactory { | ||
80 | if (!virtualHost.getServerId().equals(busServer.getId())) { | 79 | if (!virtualHost.getServerId().equals(busServer.getId())) { |
81 | return new ResultJson("400", "该虚拟主机不属于该服务器,请仔细检查"); | 80 | return new ResultJson("400", "该虚拟主机不属于该服务器,请仔细检查"); |
82 | } | 81 | } |
83 | - List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer, virtualHostName); | ||
84 | - list.addAll(queueInfoList); | 82 | + List<ViewQueueInfo> viewQueueInfoList = ClientUtils.getViewQueues(busServer, virtualHostName); |
83 | + list.addAll(viewQueueInfoList); | ||
85 | } | 84 | } |
86 | Integer total = list.size(); | 85 | Integer total = list.size(); |
87 | 86 | ||
88 | // 达到分页与排序效果 | 87 | // 达到分页与排序效果 |
89 | - List<QueueInfo> resultList = subList(pageNum, pageSize, list); | 88 | + List<ViewQueueInfo> resultList = subAndSortList(pageNum, pageSize, list); |
90 | return resultList.size() > 0 | 89 | return resultList.size() > 0 |
91 | ? new ResultJson<>("200", "查询队列监控,成功!", resultList, total) | 90 | ? new ResultJson<>("200", "查询队列监控,成功!", resultList, total) |
92 | : new ResultJson<>("500", "查询队列监控,失败!"); | 91 | : new ResultJson<>("500", "查询队列监控,失败!"); |
@@ -100,7 +99,7 @@ public class ViewQueueFactory { | @@ -100,7 +99,7 @@ public class ViewQueueFactory { | ||
100 | * @param list 全部的数据 | 99 | * @param list 全部的数据 |
101 | * @return List<QueueInfo> | 100 | * @return List<QueueInfo> |
102 | */ | 101 | */ |
103 | - public List<QueueInfo> subList(Integer pageNum, Integer pageSize, List<QueueInfo> list) | 102 | + public List<ViewQueueInfo> subAndSortList(Integer pageNum, Integer pageSize, List<ViewQueueInfo> list) |
104 | { | 103 | { |
105 | Integer total = list.size(); | 104 | Integer total = list.size(); |
106 | Integer start = (pageNum - 1) * pageSize; | 105 | Integer start = (pageNum - 1) * pageSize; |
@@ -112,10 +111,11 @@ public class ViewQueueFactory { | @@ -112,10 +111,11 @@ public class ViewQueueFactory { | ||
112 | if (end > total) { | 111 | if (end > total) { |
113 | end = total; | 112 | end = total; |
114 | } | 113 | } |
115 | - List<QueueInfo> pageList = list.subList(start, end); | ||
116 | - // 对总信息数,进行降序排序 | ||
117 | - List<QueueInfo> resultList = | ||
118 | - pageList.stream().sorted(Comparator.comparing(QueueInfo::getTotalMessages).reversed()).collect(Collectors.toList()); | 114 | + List<ViewQueueInfo> pageList = list.subList(start, end); |
115 | + // 对积压数,进行降序排序 | ||
116 | + List<ViewQueueInfo> resultList = | ||
117 | + pageList.stream().sorted(Comparator.comparing(ViewQueueInfo::getMessageReady).reversed()) | ||
118 | + .collect(Collectors.toList()); | ||
119 | return resultList; | 119 | return resultList; |
120 | } | 120 | } |
121 | } | 121 | } |
-
请 注册 或 登录 后发表评论