Example #1
0
 /**
  * @inheritDoc
  */
 public function init()
 {
     parent::init();
     if (!$this->client) {
         throw new InvalidConfigException(\Yii::t('yii', 'AMQP client should be specified'));
     }
     if ($this->name) {
         $this->queueName = $this->queueName ?: $this->name;
         $this->exchangeName = $this->exchangeName ?: $this->name;
     }
     if (!$this->exchangeName) {
         throw new InvalidConfigException(\Yii::t('yii', 'Exchange name should be specified'));
     }
     if (!$this->queueName) {
         throw new InvalidConfigException(\Yii::t('yii', 'Queue name should be specified'));
     }
     if (!$this->client->isConnected()) {
         $this->client->connect();
     }
     $this->channel = $this->client->newChannel();
     $this->exchange = $this->client->newExchange($this->channel, $this->messageType);
     $this->queue = $this->client->newQueue($this->channel, $this->messageType);
     $this->exchange->setName($this->exchangeName);
     $this->exchange->setFlags($this->exchangeFlags);
     $this->exchange->setType($this->exchangeType);
     $this->exchange->declareExchange();
     $this->queue->setName($this->queueName);
     $this->queue->setFlags($this->queueFlags);
     $this->queue->declareQueue();
     $this->queue->bind($this->exchange, $this->routingKey, $this->queueBindArguments);
 }
Example #2
0
 /**
  * @param string $name
  * @param int    $flags
  *
  * @return \yii\amqp\client\Queue
  */
 private function declareQueueAndCheckIt($name = null, $flags = Client::NOPARAM)
 {
     $channel = $this->client->newChannel();
     $queue = $this->client->newQueue($channel);
     $queue->setName($this->getNameForEntity($name));
     $queue->setFlags($flags);
     $this->assertNotNull($queue);
     $this->assertGreaterThanOrEqual(0, $queue->declareQueue());
     $this->assertEquals($flags, $queue->getFlags());
     return $queue;
 }