Queue.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace common\logic\Amqp;
  3. use PhpAmqpLib\Exception\AMQPProtocolChannelException;
  4. /**
  5. * 队列逻辑
  6. * Class Queue
  7. * @package common\logic\Amqp
  8. * @author libingke
  9. */
  10. class Queue extends Connect
  11. {
  12. private $_connect;
  13. private $_channel;
  14. public function __construct()
  15. {
  16. $this->_connect = self::connect();
  17. $this->_channel = $this->_connect->channel();
  18. }
  19. /**
  20. * [创建队列]
  21. * @author: libingke
  22. * @param string $queueName
  23. * @return array
  24. */
  25. public function create($queueName)
  26. {
  27. try {
  28. list($callback_queue, ,) = $this->_channel->queue_declare(
  29. (string) $queueName,
  30. false,
  31. 0,//持久化
  32. false,
  33. false
  34. );
  35. return ['status' => 1, 'result' => $callback_queue];
  36. } catch (AMQPProtocolChannelException $e) {
  37. return ['status' => 0, 'result' => $e->getMessage()];
  38. }
  39. }
  40. /**
  41. * [删除队列]
  42. * @author: libingke
  43. * @param string $queueName
  44. * @return array
  45. */
  46. public function delete($queueName)
  47. {
  48. try {
  49. $this->_channel->queue_delete((string) $queueName);
  50. return ['status' => 1, 'result' => 'OK'];
  51. } catch (AMQPProtocolChannelException $e) {
  52. return ['status' => 0, 'result' => $e->getMessage()];
  53. }
  54. }
  55. }