123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace common\logic;
- /**
- * Created by PhpStorm.
- * User: ZhangFeng
- * Date: 2018/1/30
- * Time: 11:39
- * Description:
- */
- use components\CUrl;
- use yii\db\ActiveRecord;
- class Queue extends ActiveRecord
- {
- public $queue;
- public $passive;
- public $durable;
- public $exclusive;
- public $auto_delete;
- public $if_unused;
- public $if_empty;
- public $nowait;
- public $ticket;
- public $user;
- public $pass;
- public function rules()
- {
- return [
- ['queue','required','on' => ['delete','create'],'message' => '队列名称为空'],
- [['passive','exclusive','auto_delete'],'default','value' => false,'on' => 'create'],
- ['durable','default','value' => true,'on' => 'create'],
- [['if_unused','if_empty','nowait'],'default','on' => 'delete'],
- ['ticket','default','value' => null,'on' => 'delete'],
- [['user','pass'],'required','on' => 'list','message' => '用户名和密码不能为空']
- ];
- }
- /**
- * @return mixed
- */
- public function createQueue()
- {
- $connection = Connection::getInstance();
- $channel = $connection->channel();
- $queue = $channel->queue_declare($this->queue, $this->passive, $this->durable, $this->exclusive, $this->auto_delete);
- return isset($queue[0]) ? : null;
- }
- /**
- * @return mixed
- */
- public function deleteQueue()
- {
- $connection = Connection::getInstance();
- $channel = $connection->channel();
- $res = $channel->queue_delete($this->queue,$this->if_unused,$this->if_empty,$this->nowait,$this->ticket);
- return $res;
- }
- /**
- * @return array
- */
- public function listQueue()
- {
- $url = 'http://192.168.1.183:15672/api/queues';
- $curl = new CUrl();
- $curl->authorize = $this->user . ':' . $this->pass;
- $res = $curl->get($url);
- $res = json_decode($res,true);
- return array_column($res,'name');
- }
- }
|