1 | <?php |
||
14 | class PeclAmqpDriver implements Driver |
||
15 | { |
||
16 | const DELIVERY_MODE = 'delivery_mode'; |
||
17 | const CONTENT_TYPE = 'content_type'; |
||
18 | const APPLICATION_HEADERS = 'headers'; |
||
19 | const CORRELATION_ID = 'correlation_id'; |
||
20 | const REPLY_TO = 'reply_to'; |
||
21 | |||
22 | /** @var \AMQPConnection */ |
||
23 | private $connection; |
||
24 | |||
25 | /** @var \AMQPChannel */ |
||
26 | private $channel; |
||
27 | |||
28 | /** |
||
29 | * PeclAmqpDriver constructor. |
||
30 | * |
||
31 | * @param \AMQPConnection $connection |
||
32 | */ |
||
33 | public function __construct(\AMQPConnection $connection) |
||
37 | |||
38 | /** |
||
39 | * Declare a persistent queue |
||
40 | * |
||
41 | * @param string $queueName |
||
42 | * @param string $type |
||
43 | * |
||
44 | * @return string |
||
45 | * |
||
46 | * @throws \AMQPConnectionException |
||
47 | * @throws \AMQPChannelException |
||
48 | * @throws \AMQPQueueException |
||
49 | */ |
||
50 | public function declareSimpleQueue($queueName = '', $type = self::QUEUE_DURABLE) |
||
63 | |||
64 | /** |
||
65 | * Declare an exchange |
||
66 | * |
||
67 | * @param string $exchangeName |
||
68 | * @param string $type |
||
69 | * |
||
70 | * @return string |
||
71 | * |
||
72 | * @throws \AMQPConnectionException |
||
73 | * @throws \AMQPChannelException |
||
74 | * @throws \AMQPExchangeException |
||
75 | */ |
||
76 | public function declareExchange($exchangeName = '', $type = self::EXCHANGE_TYPE_FANOUT) |
||
85 | |||
86 | /** |
||
87 | * Bind an existing queue to an exchange |
||
88 | * |
||
89 | * @param string $exchange |
||
90 | * @param string $queueName |
||
91 | * @param string $routingKey |
||
92 | * |
||
93 | * @return void |
||
94 | * |
||
95 | * @throws \AMQPConnectionException |
||
96 | * @throws \AMQPChannelException |
||
97 | * @throws \AMQPQueueException |
||
98 | */ |
||
99 | public function bindQueue($exchange, $queueName, $routingKey = '') |
||
104 | |||
105 | /** |
||
106 | * Create a persisting queue and bind it to an exchange |
||
107 | * |
||
108 | * @param string $exchange |
||
109 | * @param string $queueName |
||
110 | * @param string $routingKey |
||
111 | * |
||
112 | * @return void |
||
113 | * |
||
114 | * @throws \AMQPConnectionException |
||
115 | * @throws \AMQPChannelException |
||
116 | * @throws \AMQPQueueException |
||
117 | */ |
||
118 | public function declareAndBindQueue($exchange, $queueName, $routingKey = '') |
||
123 | |||
124 | /** |
||
125 | * Delete a queue |
||
126 | * |
||
127 | * @param string $queueName |
||
128 | * |
||
129 | * @return void |
||
130 | * |
||
131 | * @throws \AMQPConnectionException |
||
132 | * @throws \AMQPChannelException |
||
133 | * @throws \AMQPQueueException |
||
134 | */ |
||
135 | public function deleteQueue($queueName) |
||
139 | |||
140 | /** |
||
141 | * Delete an exchange |
||
142 | * |
||
143 | * @param string $exchangeName |
||
144 | * |
||
145 | * @return void |
||
146 | * |
||
147 | * @throws \AMQPConnectionException |
||
148 | * @throws \AMQPChannelException |
||
149 | * @throws \AMQPExchangeException |
||
150 | */ |
||
151 | public function deleteExchange($exchangeName) |
||
155 | |||
156 | /** |
||
157 | * Publish a message in the exchange |
||
158 | * |
||
159 | * @param string $exchangeName |
||
160 | * @param Message $message |
||
161 | * |
||
162 | * @return void |
||
163 | * |
||
164 | * @throws \AMQPConnectionException |
||
165 | * @throws \AMQPChannelException |
||
166 | * @throws \AMQPExchangeException |
||
167 | */ |
||
168 | public function publish($exchangeName, Message $message) |
||
178 | |||
179 | /** |
||
180 | * Consume the queue |
||
181 | * |
||
182 | * @param string $queueName |
||
183 | * @param callable $callback Must return false if you want to consume only one message |
||
184 | * @param int $timeout |
||
185 | * @param bool $autoAck |
||
186 | * |
||
187 | * @return void |
||
188 | * |
||
189 | * @throws ConsumerException |
||
190 | * @throws TimeoutException |
||
191 | * @throws \AMQPConnectionException |
||
192 | * @throws \AMQPChannelException |
||
193 | * @throws \AMQPQueueException |
||
194 | * @throws \InvalidArgumentException |
||
195 | * @throws AssertionFailedException |
||
196 | */ |
||
197 | public function consume($queueName, callable $callback, $timeout = 0, $autoAck = true) |
||
228 | |||
229 | /** |
||
230 | * Acknowledge the reception of the message. |
||
231 | * |
||
232 | * @param Message $message |
||
233 | * |
||
234 | * @return void |
||
235 | * |
||
236 | * @throws \AMQPConnectionException |
||
237 | * @throws \AMQPChannelException |
||
238 | * @throws \AMQPQueueException |
||
239 | */ |
||
240 | public function ack(Message $message) |
||
245 | |||
246 | /** |
||
247 | * Acknowledge an error during the consumption of the message |
||
248 | * |
||
249 | * @param Message $message |
||
250 | * @param bool $requeue |
||
251 | * |
||
252 | * @return void |
||
253 | * |
||
254 | * @throws \AMQPConnectionException |
||
255 | * @throws \AMQPChannelException |
||
256 | * @throws \AMQPQueueException |
||
257 | */ |
||
258 | public function nack(Message $message, $requeue = true) |
||
263 | |||
264 | /** |
||
265 | * Close the connection |
||
266 | * |
||
267 | * @return void |
||
268 | */ |
||
269 | public function close() |
||
273 | |||
274 | /** |
||
275 | * @return \AMQPChannel |
||
276 | * |
||
277 | * @throws \AMQPConnectionException |
||
278 | */ |
||
279 | private function getChannel() |
||
288 | |||
289 | /** |
||
290 | * @param string $queueName |
||
291 | * |
||
292 | * @return \AMQPQueue |
||
293 | * |
||
294 | * @throws \AMQPQueueException |
||
295 | * @throws \AMQPConnectionException |
||
296 | */ |
||
297 | private function getQueue($queueName) |
||
306 | |||
307 | /** |
||
308 | * @param string $exchangeName |
||
309 | * |
||
310 | * @return \AMQPExchange |
||
311 | * |
||
312 | * @throws \AMQPExchangeException |
||
313 | * @throws \AMQPConnectionException |
||
314 | */ |
||
315 | private function getExchange($exchangeName) |
||
324 | |||
325 | /** |
||
326 | * Returns the message parameters |
||
327 | * |
||
328 | * @param Message $message |
||
329 | * |
||
330 | * @return array |
||
331 | */ |
||
332 | private static function getMessageProperties(Message $message) |
||
350 | |||
351 | private static function generateConsumerTag( |
||
358 | } |
||
359 |