/** * Unbind this queue from an exchange. * * @recoil-coroutine * * @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 ConnectionException The connection is closed. */ public function unbind(Exchange $source, string $routingKey = '', Channel $channel = null) : Generator { assert($routingKey !== '' || !$source->type()->requiresRoutingKey(), \sprintf('bindings on a %s exchange (%s) require a routing key', $source->type(), $source->name())); $channelManager = (yield $this->connectionManager->acquireChannel($channel)); try { (yield $channelManager->call(QueueUnbindFrame::create($this->name, $source->name(), $routingKey), QueueUnbindOkFrame::METHOD_ID)); } finally { if ($channel === null) { $channelManager->release(); } } }
/** * Bind this exchange to another. * * @recoil-coroutine * * This feature requires the "exchange_exchange_bindings" broker capability. * * @param Exchange $source The exchange to bind to. * @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 bind(Exchange $source, string $routingKey = '', Channel $channel = null) : Generator { if (!$this->features->exchangeToExchangeBindings) { return reject(NotSupportedException::missingCapability('exchange-to-exchange binding', '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 = ExchangeBindFrame::create($this->name, $source->name(), $routingKey), ExchangeBindOkFrame::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(); }