2017/09/11更新 Python request get 更简单抓取
API
安装有rabbitmq_management(web管理插件)访问web首页(一般是localhost:15672)时在首页底部有个httpAPI链接。
API接口
该页面列出来了很多API接口
看一下其中的exchanges和queues
查看api是需要登录认证的
红色框框是延时队列
例子
有了API就可以抓取其中的数据
我是通过curl抓取的,下面是一个抓取exchanges列表的例子
抓取queues例子
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# author=He
import json
import subprocess
from log import log_base
from config import mq
class Exchanges:
def __new__(cls):
command = 'curl -u %s:%s http://localhost:15672/api/exchanges' % (mq.mq_user, mq.mq_pwd)
result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
r = []
name = {}
try:
r = json.loads(result.stdout.readlines()[3].decode('utf-8'))
except IndexError as e:
log_base.Error(e, mark='exchange')
try:
for line in r:
if line['name']:
name[line['name']] = line['name']
except KeyError as e:
log_base.Error(e, mark='exchange')
return name
看一下结果
/usr/bin/python3.5 /home/he/dev/rabbit/rabbit/rabbit_base/exchanges.py
{'amq.direct': 'amq.direct', 'amq.fanout': 'amq.fanout', 'amq.topic': 'amq.topic', 'jit.tests': 'jit.tests', 'amq.headers': 'amq.headers', 'amq.match': 'amq.match', 'amq.rabbitmq.log': 'amq.rabbitmq.log', 'delay.in.test': 'delay.in.test', 'amq.rabbitmq.trace': 'amq.rabbitmq.trace', 'delay.test': 'delay.test'}
Process finished with exit code 0
版权声明:本文为qq_26656329原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。