Esempio n. 1
0
 /**
  * Acquire an unused channel.
  *
  * @recoil-coroutine
  */
 public function acquireChannel(Channel $channel = null) : Generator
 {
     // The connection is not open ...
     if ($this->state !== ConnectionState::OPEN) {
         throw SingleConnectionException::notOpen($this->options);
     }
     if ($channel !== null) {
         $channelId = $channel->id();
         $channelManager = $this->channels[$channelId] ?? null;
         if ($channelManager === null) {
             throw ChannelException::notOpen($channelId);
         }
         return $channelManager;
     }
     // Check for previously released channels that can be used instead of
     // asking the broker for a new one ...
     foreach ($this->availableChannels as $channelId => $channelManager) {
         unset($this->availableChannels[$channelId], $this->availableChannelHeartbeats[$channelId]);
         return $channelManager;
     }
     $channelId = $this->findChannelId();
     // Open a new channel ...
     $channelManager = new ChannelManager($channelId, $this, $this->transport, $this->tune->frameMax);
     $this->channels[$channelId] = $channelManager;
     (yield $channelManager->open());
     return $channelManager;
 }
Esempio n. 2
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();
         }
     }
 }