https://www.rabbitmq.com/management-cli.html
wget http://{mq_addr}:15672/cli/rabbitmqadmin
chmod +x rabbitmqadmin
mv rabbitmqadmin /usr/bin/rabbitmqadmin
rabbitmqadmin --bash-completion > /etc/bash_completion.d/rabbitmqadmin
## 查看支持的子命令
rabbitmqadmin help subcommands
列出当前的 exchanges
rabbitmqadmin list exchanges
# Get a list of queues, with some columns specified
rabbitmqadmin list queues vhost name node messages message_stats.publish_details.rate
# Get a list of queues, with all the detail we can take
rabbitmqadmin -f long -d 3 list queues
# 列出当前的queue
rabbitmqadmin list queues
# 列出当前的vhosts
rabbitmqadmin list vhosts
# 查看rabbitmq的消息
rabbitmqadmin get queue="qqqq1" count=20 -f pretty_json # 或者 -f table 格式输出(建议使用pretty_json)
# 清空某个queue
rabbitmqadmin purge queue name="qqqq1"
原理: 使用rabbitmqadmin这个python命令行去执行相关的命令获取mq的信息(建议在mq机器上执行)
# 查看rabbitmq的消息: rabbitmqadmin get queue="qqqq1" count=20 -f pretty_json
# 清空某个queue: rabbitmqadmin purge queue name="qqqq1"
#!/bin/bash
source /etc/profile
# 这里生成对应的脚本,然后通过ansible下发到mq-01上去执行,并获取返回值
echo ${CHOICE}
echo ${QUEUE_NAME}
echo ${NUMBER}
echo ${confirm}
workspace='/tmp'/
cd ${workspace}
if [ "${confirm}" == 'NO' ]; then
echo "您刚才选择的是NO, 脚本将不再往下执行。"
exit 10
fi
if [[ "${CHOICE}" == 'GET_MESSAGE' ]]; then
echo "rabbitmqadmin get queue=\"${QUEUE_NAME}\" count=${NUMBER} -f pretty_json" > task.sh
elif [[ "${CHOICE}" == 'PURGE_MESSAGE' ]]; then
echo "rabbitmqadmin purge queue name=\"${QUEUE_NAME}\"" > task.sh
fi
cat task.sh
# 使用ansible将脚本推送到mq机器去执行(或者本地执行也行,只要rabbitmqadmin命令行里面配置下mq的连接参数即可)
# ansible推送并执行的命令,这里我就不贴了。。。。