1 | <?php |
||
19 | class QueueManager implements ContainerAwareInterface, QueueManagerInterface |
||
20 | { |
||
21 | protected $queueName; |
||
22 | protected $container; |
||
23 | protected $registeredQueues = array(); |
||
24 | |||
25 | 10 | public function setContainer(ContainerInterface $container = null) |
|
29 | |||
30 | /** |
||
31 | * @param string $queue |
||
32 | * @return QueueManager |
||
33 | */ |
||
34 | 9 | public function setQueueName($queue) |
|
40 | |||
41 | public function listActions() |
||
45 | |||
46 | 9 | public function executeAction($action, array $arguments=array()) |
|
47 | { |
||
48 | switch ($action) { |
||
49 | 9 | case 'list-available': |
|
50 | 1 | return $this->listAvailableQueues(); |
|
51 | |||
52 | 9 | case 'list-configured': |
|
53 | return $this->listConfiguredQueues(); |
||
54 | |||
55 | 9 | case 'create': |
|
56 | 9 | return $this->createQueue($arguments); |
|
57 | |||
58 | 9 | case 'info': |
|
59 | 1 | return $this->queueInfo(); |
|
60 | |||
61 | 9 | case 'purge': |
|
62 | 1 | return $this->purgeQueue(); |
|
63 | |||
64 | 9 | case 'delete': |
|
65 | 9 | return $this->deleteQueue(); |
|
66 | |||
67 | default: |
||
68 | throw new InvalidArgumentException("Action $action not supported"); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @return array keys are the queue names, values the queue type |
||
74 | */ |
||
75 | 1 | protected function listAvailableQueues() |
|
76 | { |
||
77 | 1 | $result = $this->getProducerService()->call('listQueues'); |
|
78 | 1 | $result = $result->get('QueueUrls'); |
|
79 | // make this slightly easier to understand by callers |
||
80 | 1 | if ($result === null) { |
|
81 | $result = array(); |
||
82 | } |
||
83 | 1 | return array_combine($result, array_fill(0, count($result), Queue::TYPE_ANY)); |
|
84 | } |
||
85 | |||
86 | protected function listConfiguredQueues() |
||
93 | |||
94 | /** |
||
95 | * NB: works only after the relevant config has been set in yml, which makes it less than ideal... |
||
96 | * See how the SQSTest does to dynamically create both the queue on the broker and the porducer + consumer |
||
97 | * @param $args allowed elements: see http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sqs-2012-11-05.html#createqueue |
||
98 | * @return the queue Url |
||
99 | * @throw \Exception on failure |
||
100 | */ |
||
101 | 9 | protected function createQueue($args) |
|
102 | { |
||
103 | 9 | $result = $this->getProducerService()->call( |
|
104 | 9 | 'CreateQueue', |
|
105 | array( |
||
106 | 9 | 'QueueName' => $this->queueName, |
|
107 | 9 | 'Attributes' => $args |
|
108 | ) |
||
109 | ); |
||
110 | 9 | return $result->get('QueueUrl'); |
|
111 | } |
||
112 | |||
113 | /** |
||
114 | * @return array |
||
115 | * @throw \Exception on failure |
||
116 | */ |
||
117 | 1 | protected function queueInfo() |
|
123 | |||
124 | /** |
||
125 | * @return array |
||
126 | * @throw \Exception on failure |
||
127 | */ |
||
128 | 1 | protected function purgeQueue() |
|
134 | |||
135 | /** |
||
136 | * @return array |
||
137 | * @throw \Exception on failure |
||
138 | */ |
||
139 | 9 | protected function deleteQueue() |
|
145 | |||
146 | 9 | protected function getProducerService() |
|
150 | |||
151 | public function registerQueue($queueName) |
||
155 | } |
||
156 |