1.节点消息队列服务发生异常
rabbitmqadmin -u rabbitmq -p 77jJ4gwo -H rabbitmq list exchanges| grep reply| awk '{print $2}'| while read line ; do rabbitmqadmin -u rabbitmq -p 77jJ4gwo -H rabbitmq delete exchange name=${line}; done
注:恢复的话,需要重启rabbitmq服务,若是微服务,delete rabbitmq pod
2.消息队列负载高场景构建
(1) 定义queue
rabbitmqadmin -u rabbitmq -p 77jJ4gwo -H rabbitmq declare queue name="test"
(2) 定义exchange
rabbitmqadmin -u rabbitmq -p 77jJ4gwo -H rabbitmq declare exchange name="test-exchange" type="direct"
(3) 绑定exchange
rabbitmqadmin -u rabbitmq -p 77jJ4gwo -H rabbitmq declare binding source=test-exchange destination=test routing_key=test
(4) 发送message
for i in $(seq 1 20000); do rabbitmqadmin -u rabbitmq -p 77jJ4gwo -H rabbitmq publish routing_key=test exchange=test-exchange payload='this is testingXXXXXXX'; done
3.消息队列未应答过多,场景构建
import pika
import logging
import time, datetime
COUNT=1
def callback(ch, method, properties, body):
print method.routing_key
global COUNT
print COUNT
COUNT=COUNT+1
if COUNT > 1000:
print COUNT
time.sleep(1000000)
# ch.basic_ack()
if __name__ == "__main__":
credentials = pika.PlainCredentials(username='rabbitmq', password='77jJ4gwo')
connection = pika.BlockingConnection(
pika.ConnectionParameters(
host='127.0.0.1', port=5672, virtual_host='/',
credentials=credentials
)
)
channel = connection.channel()
# channel.exchange_declare(exchange='amq.rabbitmq.event',type='topic')
#channel.queue_declare(queue='test', durable=False)
channel.queue_bind(exchange='amq.rabbitmq.event',queue='test',routing_key='#')
channel.basic_consume(callback,
queue='test',
)
channel.start_consuming()