在公司最新的項目上,由咱們技術總監搭了一套框架,其中有使用RabbitMq來監聽監聽寫事件,這也是我第一次使用RabbitMq。由於在開發的過程當中,有些事件會由於代碼的不完善消費失敗,而後就會一直消費,而後一直報錯。當bug修復,把正確的代碼上傳到開發環境,原先遺留的問題消息任然存在,而且會阻塞隊列,讓以後的正常的消息沒法讓系統正常的消費。html
想要刪除隊列中的消息,是能夠經過RabbitMq的網頁來操做的。登陸上RabbitMQ Management以後,在 Queues 中打開指定的隊列:node
而後在下方的 Delete / purge 中點擊 Delete 或者是 purge 均可以達到效果。linux
可是這種方式存在一個問題,就是當消息多的時候點擊,頁面會卡死。即便沒有卡死也會出現以下對話框:git
大概意思是找不到這個持久隊列,主節點已經關閉或者是沒法訪問。github
如今只是小白階段,而後有點搞不懂,網上也沒有搜索到什麼有用的答案。只找到一句話,來自:https://blog.csdn.net/u011973...web
若是隊列的主節點不可用,則非鏡像隊列的行爲取決於其持久性。在節點恢復正常以前,持久化隊列將不可用。在集羣中其餘節點上對主節點不可用的持久化隊列進行任何操做都將失敗
沒有深究服務器
而後我就去網上百度了一下,如何使用命令操做,而後找到了下面的解決方法:app
rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl start_app
執行了一次以後確實是有效的。重啓的RabbitMq,而後裏面的消息也確實清空了。框架
而後我當上述的狀況再次發生,須要清空消息,這樣個時候我不想用這樣一看就很粗暴的方式來操做,並且這種方式不只會清空消息,還會清空全部配置信息。因此此次我想要先清除指定隊列的消息便可。less
而後我找到了這個方法:
sudo rabbitmqctl purge_queue ${queue_name} 或 rabbitmqctl purge_queue ${queue_name} 或 rabbitmqctl -p ${vhostpath} purge_queue ${queue_name}
執行報錯,說是找不到這個命令,給出的信息以下:
Error: could not recognise command Usage: rabbitmqctl [-n <node>] [-q] <command> [<command options>] Options: -n node -q Default node is "rabbit@server", where server is the local host. On a host named "server.example.com", the node name of the RabbitMQ Erlang node will usually be rabbit@server (unless RABBITMQ_NODENAME has been set to some non-default value at broker startup time). The output of hostname -s is usually the correct suffix to use after the "@" sign. See rabbitmq-server(1) for details of configuring the RabbitMQ broker. Quiet output mode is selected with the "-q" flag. Informational messages are suppressed when quiet mode is in effect. Commands: stop [<pid_file>] stop_app start_app wait <pid_file> reset force_reset rotate_logs <suffix> join_cluster <clusternode> [--ram] cluster_status change_cluster_node_type disc | ram forget_cluster_node [--offline] update_cluster_nodes clusternode sync_queue queue cancel_sync_queue queue set_cluster_name name add_user <username> <password> delete_user <username> change_password <username> <newpassword> clear_password <username> set_user_tags <username> <tag> ... list_users add_vhost <vhostpath> delete_vhost <vhostpath> list_vhosts [<vhostinfoitem> ...] set_permissions [-p <vhostpath>] <user> <conf> <write> <read> clear_permissions [-p <vhostpath>] <username> list_permissions [-p <vhostpath>] list_user_permissions <username> set_parameter [-p <vhostpath>] <component_name> <name> <value> clear_parameter [-p <vhostpath>] <component_name> <key> list_parameters [-p <vhostpath>] set_policy [-p <vhostpath>] [--priority <priority>] [--apply-to <apply-to>] <name> <pattern> <definition> clear_policy [-p <vhostpath>] <name> list_policies [-p <vhostpath>] list_queues [-p <vhostpath>] [<queueinfoitem> ...] list_exchanges [-p <vhostpath>] [<exchangeinfoitem> ...] list_bindings [-p <vhostpath>] [<bindinginfoitem> ...] list_connections [<connectioninfoitem> ...] list_channels [<channelinfoitem> ...] list_consumers [-p <vhostpath>] status environment report eval <expr> close_connection <connectionpid> <explanation> trace_on [-p <vhost>] trace_off [-p <vhost>] set_vm_memory_high_watermark <fraction> <vhostinfoitem> must be a member of the list [name, tracing]. The list_queues, list_exchanges and list_bindings commands accept an optional virtual host parameter for which to display results. The default value is "/". <queueinfoitem> must be a member of the list [name, durable, auto_delete, arguments, policy, pid, owner_pid, exclusive_consumer_pid, exclusive_consumer_tag, messages_ready, messages_unacknowledged, messages, consumers, consumer_utilisation, memory, slave_pids, synchronised_slave_pids, status]. <exchangeinfoitem> must be a member of the list [name, type, durable, auto_delete, internal, arguments, policy]. <bindinginfoitem> must be a member of the list [source_name, source_kind, destination_name, destination_kind, routing_key, arguments]. <connectioninfoitem> must be a member of the list [pid, name, port, host, peer_port, peer_host, ssl, ssl_protocol, ssl_key_exchange, ssl_cipher, ssl_hash, peer_cert_subject, peer_cert_issuer, peer_cert_validity, state, channels, protocol, auth_mechanism, user, vhost, timeout, frame_max, channel_max, client_properties, recv_oct, recv_cnt, send_oct, send_cnt, send_pend]. <channelinfoitem> must be a member of the list [pid, connection, name, number, user, vhost, transactional, confirm, consumer_count, messages_unacknowledged, messages_uncommitted, acks_uncommitted, messages_unconfirmed, prefetch_count, global_prefetch_count].
實際上使用 rabbitmqctl -help 就能獲得這些內容。
能夠看的出來,這裏面已經 rabbitmqctl 所支持的命令都列了出來。其中並無 purge_queue 這個命令。不知道是否是版本問題仍是怎麼回事。
而後在這裏找到了 rabbitmqadmin 這個東西。官網地址:https://www.rabbitmq.com/mana... 。在上面看到了這麼一行文字
Alternatively, you can download the version of rabbitmqadmin which corresponds with the management plugin version 3.7.17 from GitHub.
打開GitHub的連接:https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/v3.7.17/bin/rabbitmqadmin
裏面好像是 rabbitmqadmin 的代碼。看了一下路徑,v3.7.17。這個應該是要對應本身版本的。
rabbitmqctl status
查看版本:
[root@iZuf635fwy8k6ubk6r9yonZ ~]# rabbitmqctl status Status of node rabbit@iZuf635fwy8k6ubk6r9yonZ ... [{pid,3261}, {running_applications, [{rabbitmq_management,"RabbitMQ Management Console","3.3.5"}, {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.3.5"}, {webmachine,"webmachine","1.10.3-rmq3.3.5-gite9359c7"}, {mochiweb,"MochiMedia Web Server","2.7.0-rmq3.3.5-git680dba8"}, {rabbitmq_management_agent,"RabbitMQ Management Agent","3.3.5"}, {rabbit,"RabbitMQ","3.3.5"}, {mnesia,"MNESIA CXC 138 12","4.11"}, {os_mon,"CPO CXC 138 46","2.2.14"}, {amqp_client,"RabbitMQ AMQP Client","3.3.5"}, {inets,"INETS CXC 138 49","5.9.8"}, {xmerl,"XML parser","1.3.6"}, {sasl,"SASL CXC 138 11","2.3.4"}, {stdlib,"ERTS CXC 138 10","1.19.4"}, {kernel,"ERTS CXC 138 10","2.16.4"}]}, {os,{unix,linux}}, {erlang_version, "Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [async-threads:30] [hipe] [kernel-poll:true]\n"}, {memory, [{total,44920360}, {connection_procs,944512}, {queue_procs,911352}, {plugins,406328}, {other_proc,13412192}, {mnesia,200144}, {mgmt_db,391944}, {msg_index,95648}, {other_ets,1174432}, {binary,2676288}, {code,20229484}, {atom,711569}, {other_system,3766467}]}, {alarms,[]}, {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]}, {vm_memory_high_watermark,0.4}, {vm_memory_limit,1654662758}, {disk_free_limit,50000000}, {disk_free,16424939520}, {file_descriptors, [{total_limit,924},{total_used,9},{sockets_limit,829},{sockets_used,2}]}, {processes,[{limit,1048576},{used,396}]}, {run_queue,0}, {uptime,3716267}] ...done.
結果發現本身的版本居然是3.3.5。修改路徑https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/v3.7.17/bin/rabbitmqadmin
爲https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/v3.3.5/bin/rabbitmqadmin
,訪問,顯示並無這個頁面。大概是版本太老了。網上搜了一下3.3.5版本的消息。發現這個版本大概是2014年左右的東西,時至今日已經五年過去了,也太老了吧。
本文章一次沒有寫完,在我寫的過程當中,項目提交給測試進行部分測試,而後同事在test環境也安裝了一個RabbitMq。我登上去看了一下,嗯,是有 purge_queue 這個命令的。看了一下test的版本,3.6.8。果真仍是版本問題。我以前一直操做的是dev服務器的東西,雖然本地也有安裝可是在本地進行簡單的時候仍是很好處理的,註釋掉代碼,而後從新運行,消費掉垃圾消息便可。
至於 rabbitmqadmin ,官網上有這麼一段話:
Obtaining rabbitmqadmin
With the management plugin installed, browse to http://{hostname}:15672/cli/rabbitmqadmin to download. The tool supports
大概意思就能夠經過訪問 http://{hostname}:15672/cli/rabbitmqadmin 來下載 rabbitmqadmin 。沒有深刻研究。到此爲止,後續可能會更新相關內容。
發佈文章的時候發現,過長的思否對過長的url省略的後面的部分,就像是這樣:https://raw.githubusercontent...。因此在上面就對url稍微處理了一下。