Last active
November 14, 2024 17:21
-
-
Save pavel-rossinsky/3728131b572cd247642b3ed9cadfe625 to your computer and use it in GitHub Desktop.
PHP script to list and purge all queues in a local ElasticMQ instance running on Docker. It uses Symfony's HttpClient to interact with the service, sending ListQueues and PurgeQueue requests, and outputs the results to the console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\HttpClient\HttpClient; | |
require __DIR__ . '/vendor/autoload.php'; | |
$client = HttpClient::create(); | |
$endpoint = 'http://localhost:9424'; | |
try { | |
$response = $client->request('POST', "$endpoint", [ | |
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], | |
'body' => [ | |
'Action' => 'ListQueues', | |
] | |
]); | |
$rawContent = $response->getContent(); | |
echo "Raw Response: $rawContent\n"; // For debugging | |
$xml = new SimpleXMLElement($rawContent); | |
$queueUrls = $xml->ListQueuesResult->QueueUrl ?? []; | |
if (empty($queueUrls)) { | |
echo "No queues found.\n"; | |
exit; | |
} | |
foreach ($queueUrls as $queueUrl) { | |
$client->request('POST', $queueUrl, [ | |
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], | |
'body' => [ | |
'Action' => 'PurgeQueue', | |
] | |
]); | |
echo "Purged queue: $queueUrl\n"; | |
} | |
} catch (Throwable $e) { | |
echo "Error: " . $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment