コード例 #1
0
ファイル: Amqp091Queue.php プロジェクト: recoilphp/amqp
 /**
  * Create this queue.
  *
  * @recoil-coroutine
  *
  * @param Channel|null $channel The application-managed channel to use (null = auto-managed).
  *
  * @return tuple<int,int>          A 2-tuple containing the queue's current message and consumer count.
  * @throws ResourceLockedException Another connection has exclusive access to the queue.
  * @throws DeclareException        The queue already exists with different options.
  * @throws ConnectionException     The connection is closed.
  * @throws ChannelException        The channel is closed.
  */
 public function create(Channel $channel = null) : Generator
 {
     try {
         return (yield $this->declareQueue(false, $channel));
     } catch (AmqpException $e) {
         if ($e->getCode() === Constants::PRECONDITION_FAILED) {
             throw DeclareException::queueOptionMismatch($this->name, $this->options, $e);
         }
         throw $e;
     }
 }
コード例 #2
0
ファイル: Amqp091Exchange.php プロジェクト: recoilphp/amqp
 /**
  * Declare this exchange.
  *
  * @recoil-coroutine
  *
  * @param boolean      $passive True to use a "passive" declare mode.
  * @param Channel|null $channel The application-managed channel to use (null = auto-managed).
  *
  * @throws ResourceNotFoundException The exchange does not exist.
  * @throws DeclareException          The exchange already exists with different a type or options.
  * @throws DeclareException          A reserved exchange name was used.
  * @throws ConnectionException       The connection is closed.
  * @throws ChannelException          The channel is closed.
  */
 private function declareExchange($passive, Channel $channel = null) : Generator
 {
     if ('amq.' === substr($this->name, 0, 4)) {
         return reject(DeclareException::exchangeNameIsReserved($this->name));
     }
     $deferred = new Deferred();
     $this->broker->acquireChannel(function ($exception, $brokerChannel) use($channel, $passive, $deferred) {
         if ($exception) {
             $deferred->reject($exception);
         } else {
             $brokerChannel->call(ExchangeDeclareFrame::create($this->name, $this->type->value(), $passive, $this->options->durable, $this->options->autoDelete, $this->options->internal, false, $this->arguments), ExchangeDeclareOkFrame::METHOD_ID, function ($exception, $frame) use($brokerChannel, $channel, $deferred) {
                 if (!$channel) {
                     $this->broker->releaseChannel($brokerChannel);
                 }
                 if ($exception) {
                     if ($exception instanceof AmqpException) {
                         if ($exception->getCode() === Constants::PRECONDITION_FAILED) {
                             $exception = DeclareException::exchangeTypeOrOptionMismatch($this->name, $this->type, $this->options, $exception);
                         } elseif ($exception->getCode() === Constants::NOT_FOUND) {
                             $exception = ResourceNotFoundException::exchangeNotFound($this->name, $exception);
                         }
                     }
                     $deferred->reject($exception);
                 } else {
                     $deferred->resolve($this);
                 }
             });
         }
     }, $channel);
     return $deferred->promise();
 }