本文共 4168 字,大约阅读时间需要 13 分钟。
目录
在测试区,经常因为测试导致测试区很多队列里面堆积很多消息。这一方面对测试区MQ的性能造成问题,dashboard这个插件经常卡主。此外消息过多也不方便debug。
mq的dashbnoard插件提供了puege单个队列的所有消息。如下图
[root@P1QMSARC01 ~]# rabbitmqctl stop_appStopping rabbit application on node rabbit@P1QMSARC01 ...#检查是否关闭[root@P1QMSARC01 ~]# lsof -i:5672[root@P1QMSARC01 ~]# #清除所有队列以及消息[root@P1QMSARC01 ~]# rabbitmqctl resetResetting node rabbit@P1QMSARC01 ...
清空后的overview 的Queues为0.
#启动[root@P1QMSARC01 ~]# rabbitmqctl start_app Starting node rabbit@P1QMSARC01 ... completed with 3 plugins.
使用rabbitmqctl reset 之前切记一定要将队列的定义信息导出。待清空完成后再导入。
导出的队列是一个json格式的文件。
"rabbit_version": "3.7.10", "users": [{ "name": "guest", "password_hash": "AgvI76xv7Z7x8GgygqtqM75S3TkqfcuwmndHpeFRuPaNZkTN", "hashing_algorithm": "rabbit_password_hashing_sha256", "tags": "administrator" }], "vhosts": [{ "name": "/" }], "permissions": [{ "user": "guest", "vhost": "/", "configure": ".*", "write": ".*", "read": ".*" }], "topic_permissions": [], "parameters": [], "global_parameters": [{ "name": "cluster_name", "value": "rabbit@P1QMSARC01" }], "policies": [{ "vhost": "/", "name": "ha-all", "pattern": "^", "apply-to": "all", "definition": { "ha-mode": "all" }, "priority": 0 }], "queues": [{ "name": "466XPNRP0300", "vhost": "/", "durable": true, "auto_delete": false, "arguments": {} },
将这个json文件从dashboard导入,之前所有的队列都恢复了,但消息再也回不来了。所以正式区还是慎用,除非消息被备份了。
测试代码如下:
@Test public void testpurgeRabbitMQ() throws IOException {// 快捷情况MQ 的消息 String queueName = "A_GLASS,A_PANEL,A_DEFECT,F_GLASS,F_PANEL,F_DEFECT,C_GLASS,C_PANEL,C_DEFECT"; ListqueueStrList = Arrays.asList(queueName.split(","));// final List jsonObjectList = buildJsonString(); try { for(int i= 0; i< queueStrList.size(); i++){ channel.queuePurge(queueStrList.get(i)); log.info("QueueName:{},had purged",queueStrList.get(i)); } } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); }
2021年6月22日01:01:12
public void testpurgeRabbitMQ() throws IOException { String queueName = "A1311ILDM05,A1311ILDM05,A1311ILDM05,A1311ILDM12,A1311ILDM12,A1311ILDM12,A1350AOIL05,A1350AOIL05,A1350AOIL05,A1350AOIL06,A1350AOIL06,A1350AOIL06,A135JSADJ01,A135JSADJ01,A135JSADJ01,A135JSADJ05,A135JSADJ05,A135JSADJ05,A135JSADJ08,A135JSADJ08,A135JSADJ09,A135JSADJ09,A135JSADJ09,A1850AOIL13,A1850AOIL13,A1850AOIL13,A1853IMRV02,A185JSADJ15,A185JSADJ15,A185JSADJ15,A2311ILDM03,A2311ILDM03,A2311ILDM03,A2311ILDM10,A2311ILDM10,A2311ILDM10,A2353IMRV02,A2353IMRV02,A2353IMRV02,A3311ILDM08,A3311ILDM08,A3311ILDM08,A3311ILDM09,A3311ILDM09,A3311ILDM09,A3350AOIL02,A3350AOIL02,A3350AOIL02,A3350AOIL09,A3350AOIL09,A3350AOIL09,A3353IMRV02,A3353IMRV02,A3353IMRV02,A335JSADJ04,A335JSADJ04,A335JSADJ04,A335JSADJ13,A385JSADJ19,A385JSADJ19,A385JSADJ19,A4311ILDM06,A4311ILDM06,A4311ILDM06,A4311ILDM07,A4311ILDM07,A4311ILDM07,A4350AOIL10,A4350AOIL10,A4350AOIL10,A4353IMRV02,A4353IMRV02,A4353IMRV02,A5350AOIL03,A5350AOIL03,A5350AOIL03,A5353IMRV02,A5353IMRV02,A5353IMRV02,A535JSADJ04,A535JSADJ04,A535JSADJ04,A77107710,A77107710,A77107710"; ListqueueStrList = Arrays.asList(queueName.split(",")); try (Connection connection = connectionFactory.newConnection()) { final Channel channel = connection.createChannel();// final List jsonObjectList = buildJsonString(); try { for(int i= 0; i< queueStrList.size(); i++){ channel.queuePurge(queueStrList.get(i)); System.out.println("QueueName:{},had purged" + queueStrList.get(i));// logger.info("QueueName:{},had purged",queueStrList.get(i)); } } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } } catch (TimeoutException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
转载地址:http://sjhqj.baihongyu.com/