QueueManager::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
namespace Metfan\RabbitSetup\Manager\RabbitMq;
3
4
use Metfan\RabbitSetup\Http\ClientInterface;
5
6
/**
7
 * Queue manager, create, retrieve, delete queue and bind queues to exchange
8
 *
9
 * @author Ulrich
10
 * @package Metfan\RabbitSetup\Manager
11
 */
12
class QueueManager extends BaseManager
13
{
14
    /**
15
     * Create a queue
16
     *
17
     * @param $queueName
18
     * @param array $options
19
     * @return void
20
     */
21
    public function create($queueName, array $options)
22
    {
23
        if (empty($options['arguments'])) {
24
            unset($options['arguments']);
25
        }
26
27
        $bindings = $options['bindings'];
28
        unset($options['bindings']);
29
30
        $this->client->query(
31
            ClientInterface::METHOD_PUT,
32
            sprintf('/api/queues/%s/%s', $this->vhost, $queueName),
33
            $options);
34
        $this->logger->info(sprintf('Create queue: <info>%s</info>', $queueName));
35
36
        foreach($bindings as $binding) {
37
            $this->client->query(
38
                ClientInterface::METHOD_POST,
39
                sprintf('/api/bindings/%s/e/%s/q/%s', $this->vhost, $binding['exchange'], $queueName),
40
                ['routing_key' => $binding['routing_key']]);
41
            $this->logger->info(sprintf(
42
                'Bind exchange <info>%s</info> with queue <info>%s</info> using routing key <info>%s</info>',
43
                $binding['exchange'],
44
                $queueName,
45
                $binding['routing_key']));
46
        }
47
48
    }
49
50
    /**
51
     * Get all queue from a vhost or all queue in your rabbitmq
52
     *
53
     * @param string|null $vhost
54
     * @return mixed
55
     */
56
    public function getAll($vhost = null)
57
    {
58
        return $this->findAllElements('/api/queues', $vhost);
59
    }
60
61
    /**
62
     * Delete a queue from a vhost
63
     *
64
     * @param $vhost
65
     * @param $name
66
     * @return mixed
67
     */
68
    public function delete($vhost, $name)
69
    {
70
        return $this->deleteElement('/api/queues', $vhost, $name, 'queue');
71
    }
72
}
73