Files
Stanislav Hejny 4fc81edc62
Unit test coverage / pytest (push) Failing after 57s
Unit test coverage / pytest (pull_request) Failing after 1m23s
#35 - move CLI tools to dedicated directory so it is not partr of the distributable code
2025-05-01 18:26:09 +01:00

49 lines
1.4 KiB
Python

import requests
def delete_queues_with_prefix_http(
host="localhost",
port=15672,
username="springuser",
password="TheCleverWho",
prefix="cm-",
):
"""
CLI utility. Delete queues using RabbitMQ HTTP API.
"""
base_url = f"http://{host}:{port}/api/queues/%2F"
try:
response = requests.get(base_url, auth=(username, password))
response.raise_for_status()
queues = [q["name"] for q in response.json() if q["name"].startswith(prefix)]
if not queues:
print(f"No queues found with prefix '{prefix}'")
return
print(f"Found {len(queues)} queues with prefix '{prefix}':")
for queue in queues:
print(f" - {queue}")
for queue in queues:
try:
delete_url = f"{base_url}/{queue}"
response = requests.delete(delete_url, auth=(username, password))
response.raise_for_status()
print(f"Successfully deleted queue: {queue}")
except Exception as e:
print(f"Failed to delete queue {queue}: {str(e)}")
print("Queue deletion process completed.")
except Exception as e:
print(f"An error occurred: {str(e)}")
if __name__ == "__main__":
delete_queues_with_prefix_http()
delete_queues_with_prefix_http(prefix="amq.gen--")
delete_queues_with_prefix_http(prefix="amq_")