12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace common\logic\Amqp;
- use PhpAmqpLib\Exception\AMQPProtocolChannelException;
- /**
- * 队列逻辑
- * Class Queue
- * @package common\logic\Amqp
- * @author libingke
- */
- class Queue extends Connect
- {
- private $_connect;
- private $_channel;
- public function __construct()
- {
- $this->_connect = self::connect();
- $this->_channel = $this->_connect->channel();
- }
- /**
- * [创建队列]
- * @author: libingke
- * @param string $queueName
- * @return array
- */
- public function create($queueName)
- {
- try {
- list($callback_queue, ,) = $this->_channel->queue_declare(
- (string) $queueName,
- false,
- 0,//持久化
- false,
- false
- );
- return ['status' => 1, 'result' => $callback_queue];
- } catch (AMQPProtocolChannelException $e) {
- return ['status' => 0, 'result' => $e->getMessage()];
- }
- }
- /**
- * [删除队列]
- * @author: libingke
- * @param string $queueName
- * @return array
- */
- public function delete($queueName)
- {
- try {
- $this->_channel->queue_delete((string) $queueName);
- return ['status' => 1, 'result' => 'OK'];
- } catch (AMQPProtocolChannelException $e) {
- return ['status' => 0, 'result' => $e->getMessage()];
- }
- }
- }
|