Skip to content

Instantly share code, notes, and snippets.

@hiroakis
Last active August 21, 2023 13:33
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hiroakis/5088513 to your computer and use it in GitHub Desktop.
Save hiroakis/5088513 to your computer and use it in GitHub Desktop.
Calling the RabbitMQ api from Python sample
#!/usr/local/bin/python
import requests
import json
def call_rabbitmq_api(host, port, user, passwd):
url = 'http://%s:%s/api/queues' % (host, port)
r = requests.get(url, auth=(user,passwd))
return r
def get_queue_name(json_list):
res = []
for json in json_list:
res.append(json["name"])
return res
if __name__ == '__main__':
host = 'rabbitmq_host'
port = 55672
user = 'basic_auth_user'
passwd = 'basic_auth_password'
res = call_rabbitmq_api(host, port, user, passwd)
print "--- dump json ---"
print json.dumps(res.json(), indent=4)
print "--- get queue name ---"
q_name = get_queue_name(res.json())
print q_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment