Example #1
0
 /**
  * Set the pre-fetch limits for this connection.
  *
  * @recoil-coroutine
  *
  * The pre-fetch count is the maximum number of unacknowledged messages that
  * are delivered to this connection.
  *
  * The pre-fetch limit is the maximum total size of unacknowledge messages
  * (in bytes) that is delivered to this connection.
  *
  * This feature is incompatible with the "per_consumer_qos" broker
  * capability.
  *
  * RabbitMQ does not support per-connection limits (current as of v3.5.6).
  *
  * @param int|null     $count   The pre-fetch count limit (null = unlimited).
  * @param int|null     $size    The pre-fetch size limit (null = unlimited).
  * @param Channel|null $channel The application-managed channel to use (null = auto-managed).
  *
  * @throws NotSupportedException The broker does not support this feature.
  * @throws ConnectionException   The connection is closed.
  */
 public function setQosLimits(int $count = null, int $size = null, Channel $channel = null) : Generator
 {
     assert($size === null || $size > 0);
     assert($count === null || $count > 0);
     if ($this->connectionManager === null) {
         throw SingleConnectionException::notOpen($this->options);
     } elseif ($this->features->perConsumerQos) {
         throw NotSupportedException::incompatibleCapability('per-connection QoS limits', 'per_consumer_qos');
     } elseif ($size !== null && !$this->features->qosSizeLimits) {
         throw NotSupportedException::unsupportedFeature('pre-fetch size limits');
     }
     $channelManager = (yield $this->connectionManager->acquireChannel($channel));
     try {
         (yield $channelManager->call(BasicQosFrame::create($size ?: 0, $count ?: 0, true), BasicQosOkFrame::METHOD_ID));
     } finally {
         if ($channel === null) {
             $channelManager->release();
         }
     }
 }
Example #2
0
 /**
  * Set the pre-fetch limits for consumers on this channel.
  *
  * @recoil-coroutine
  *
  * Only consumers created after setting the limits are affected.
  *
  * The pre-fetch count is the maximum number of unacknowledged messages that
  * are delivered to each consumer on this channel.
  *
  * The pre-fetch limit is the maximum total size of unacknowledge messages
  * (in bytes) that is delivered to this channel.
  *
  * This feature requires the "per_consumer_qos" broker capability.
  *
  * RabbitMQ does not support pre-fetch size limits (current as of v3.5.6).
  *
  * @param int|null $count The pre-fetch count limit (null = unlimited).
  * @param int|null $size  The pre-fetch size limit (null = unlimited).
  *
  * @throws NotSupportedException The broker does not support this feature.
  * @throws ConnectionException   The connection is closed.
  * @throws ChannelException      The channel is closed.
  */
 public function setConsumerQosLimits(int $count = null, int $size = null) : Generator
 {
     assert($size === null || $size > 0);
     assert($count === null || $count > 0);
     if ($this->channelManager === null) {
         throw ChannelException::notOpen($this->channelId);
     } elseif (!$this->features->perConsumerQos) {
         throw NotSupportedException::missingCapability('per-consumer QoS limits', 'per_consumer_qos');
     } elseif ($size !== null && !$this->features->qosSizeLimits) {
         throw NotSupportedException::unsupportedFeature('pre-fetch size limits');
     }
     $this->channelManager->setDirty();
     (yield $this->channelManager->call(BasicQosFrame::create($size ?: 0, $count ?: 0, false), BasicQosOkFrame::METHOD_ID));
 }
Example #3
0
 /**
  * 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;
     }
 }