/** * Check that this queue exists and that the options match the broker. * * @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 ResourceNotFoundException The queue does not exist. * @throws ResourceLockedException Another connection has exclusive access to the queue. * @throws ConnectionException The connection is closed. * @throws ChannelException The channel is closed. */ public function check(Channel $channel = null) : Generator { try { return (yield $this->declareQueue(true, $channel)); } catch (AmqpException $e) { if ($e->getCode() === Constants::NOT_FOUND) { throw ResourceNotFoundException::queueNotFound($this->name, $e); } throw $e; } }
/** * Open the consumer. * * @recoil-coroutine * * While a consumer is open, it will consume messages from the queue. * Messages are read by using the consumer as a readable channel. * * The consumer may be reopened after it has been closed. * * @throws ResourceLockedException Another connection has exclusive access to the queue. * @throws ResourceNotFoundException The queue does not exist. * @throws ConnectionException The connection is closed. * @throws ChannelException The channel is closed. */ public function open() : Generator { assert($this->state === self::STATE_CLOSED); try { $this->state = self::STATE_OPENING; $this->channelManager = (yield $this->connectionManager->acquireChannel($this->channel)); if ($this->preFetchCount !== null || $this->preFetchSize !== null) { $this->channelManager->setDirty(); (yield $this->channelManager->call(BasicQosFrame::create($this->preFetchSize, $this->preFetchCount, false), BasicQosOkFrame::METHOD_ID)); } try { $frame = (yield $this->channelManager->call(BasicConsumeFrame::create($this->queue->name(), $this->tag, $this->options->noLocal, $this->options->noAck, $this->options->exclusive), BasicConsumeOkFrame::METHOD_ID)); } catch (AmqpException $e) { if ($e->getCode() === Constants::ACCESS_REFUSED) { throw ResourceLockedException::queueHasExclusiveConsumer($this->queue->name(), $e); } elseif ($e->getCode() === Constants::NOT_FOUND) { throw ResourceNotFoundException::queueNotFound($this->queue->name(), $e); } else { throw $e; } } $this->tag = $frame->consumerTag; $this->state = self::STATE_OPEN; $this->channelManager->addDeliverListener($this->tag, $this); } catch (Throwable $e) { $this->cleanup(); throw $e; } }