-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRabbitManagementExtensionTrait.php
76 lines (62 loc) · 2.23 KB
/
RabbitManagementExtensionTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Enqueue\Test;
use Enqueue\Dsn\Dsn;
trait RabbitManagementExtensionTrait
{
/**
* @param string $queueName
*/
private function removeQueue($queueName)
{
$dsn = Dsn::parseFirst(getenv('RABBITMQ_AMQP_DSN'));
$url = sprintf(
'http://%s:15672/api/queues/%s/%s',
$dsn->getHost(),
urlencode(ltrim($dsn->getPath(), '/')),
$queueName
);
$ch = curl_init();
curl_setopt($ch, \CURLOPT_URL, $url);
curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, \CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, \CURLOPT_HTTPAUTH, \CURLAUTH_BASIC);
curl_setopt($ch, \CURLOPT_USERPWD, $dsn->getUser().':'.$dsn->getPassword());
curl_setopt($ch, \CURLOPT_HTTPHEADER, [
'Content-Type' => 'application/json',
]);
curl_exec($ch);
$httpCode = curl_getinfo($ch, \CURLINFO_HTTP_CODE);
curl_close($ch);
if (false == in_array($httpCode, [204, 404], true)) {
throw new \LogicException('Failed to remove queue. The response status is '.$httpCode);
}
}
/**
* @param string $exchangeName
*/
private function removeExchange($exchangeName)
{
$dsn = Dsn::parseFirst(getenv('RABBITMQ_AMQP_DSN'));
$url = sprintf(
'http://%s:15672/api/exchanges/%s/%s',
$dsn->getHost(),
urlencode(ltrim($dsn->getPath(), '/')),
$exchangeName
);
$ch = curl_init();
curl_setopt($ch, \CURLOPT_URL, $url);
curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, \CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, \CURLOPT_HTTPAUTH, \CURLAUTH_BASIC);
curl_setopt($ch, \CURLOPT_USERPWD, $dsn->getUser().':'.$dsn->getPassword());
curl_setopt($ch, \CURLOPT_HTTPHEADER, [
'Content-Type' => 'application/json',
]);
curl_exec($ch);
$httpCode = curl_getinfo($ch, \CURLINFO_HTTP_CODE);
curl_close($ch);
if (false == in_array($httpCode, [204, 404], true)) {
throw new \LogicException('Failed to remove queue. The response status is '.$httpCode);
}
}
}