/** * 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)); }
/** * Unbind this exchange from another. * * @recoil-coroutine * * This feature requires the "exchange_exchange_bindings" broker capability. * * @param Exchange $source The exchange to unbind from. * @param string $routingKey The routing key for DIRECT and TOPIC exchanges. * @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 unbind(Exchange $exchange, string $routingKey = '', Channel $channel = null) : Generator { if (!$this->features->exchangeToExchangeBindings) { return reject(NotSupportedException::missingCapability('exchange-to-exchange unbinding', 'exchange_exchange_bindings')); } elseif ($source->type()->requiresRoutingKey() && '' === $routingKey) { return reject(new InvalidArgumentException(\sprintf('Bindings on a %s exchange (%s) require a routing key.', $source->type(), $source->name()))); } $deferred = new Deferred(); $this->broker->acquireChannel(function ($exception, $brokerChannel) use($source, $routingKey, $channel, $deferred) { if ($exception) { $deferred->reject($exception); } else { $brokerChannel->call($frame = ExchangeUnbindFrame::create($this->name, $source->name(), $routingKey), ExchangeUnbindOkFrame::METHOD_ID, function ($exception) use($brokerChannel, $channel, $deferred) { if (!$channel) { $this->broker->releaseChannel($brokerChannel); } if ($exception) { $deferred->reject($exception); } else { $deferred->resolve($this); } }); } }, $channel); return $deferred->promise(); }
/** * 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(); } } }
/** * Set the pre-fetch limits for this consumer's auto-managed channel. * * @recoil-coroutine * * This feature can not be used if the consumer is using a channel managed * by the application. * * The consumer must be closed and reopened for the changes to take affect. * * The pre-fetch count is the maximum number of unacknowledged messages that * are delivered to this channel. * * The pre-fetch limit is the maximum total size of unacknowledged messages * (in bytes) that is delivered to this channel. * * 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). */ public function setQosLimits(int $count = null, int $size = null) : Generator { assert($size === null || $size > 0); assert($count === null || $count > 0); assert($this->channel === null, 'can not set QOS limits when using an application-managed channel'); if ($size !== null && !$this->features->qosSizeLimits) { throw NotSupportedException::unsupportedFeature('pre-fetch size limits'); } $this->preFetchCount = $count ?: 0; $this->preFetchSize = $size ?: 0; return; yield; // @codeCoverageIgnore }