Final Class Yiisoft\Queue\AMQP\QueueProvider
| Inheritance | Yiisoft\Queue\AMQP\QueueProvider |
|---|---|
| Implements | Yiisoft\Queue\AMQP\QueueProviderInterface |
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| EXCHANGE_NAME_DEFAULT | 'yii-queue' | Yiisoft\Queue\AMQP\QueueProvider |
Method Details
| public mixed __construct ( \PhpAmqpLib\Connection\AbstractConnection $connection, Yiisoft\Queue\AMQP\Settings\QueueSettingsInterface $queueSettings, Yiisoft\Queue\AMQP\Settings\ExchangeSettingsInterface|null $exchangeSettings = null, array $messageProperties = [] ) | ||
| $connection | \PhpAmqpLib\Connection\AbstractConnection | |
| $queueSettings | Yiisoft\Queue\AMQP\Settings\QueueSettingsInterface | |
| $exchangeSettings | Yiisoft\Queue\AMQP\Settings\ExchangeSettingsInterface|null | |
| $messageProperties | array | |
public function __construct(
private readonly AbstractConnection $connection,
private QueueSettingsInterface $queueSettings,
private ?ExchangeSettingsInterface $exchangeSettings = null,
private array $messageProperties = [],
) {
}
| public mixed __destruct ( ) |
public function __destruct()
{
if ($this->channelId !== null) {
$this->connection->channel($this->channelId)->close();
}
}
| public void channelClose ( ) |
public function channelClose(): void
{
if ($this->channelId !== null) {
$this->connection->channel($this->channelId)->close();
$this->channelId = null;
}
}
Returns an AMQPChannel instance.
IMPORTANT: Do NOT memorise the channel instance, as this will cause memory leaks on channel close!
| public \PhpAmqpLib\Channel\AMQPChannel getChannel ( ) |
public function getChannel(): AMQPChannel
{
if ($this->channelId !== null) {
return $this->connection->channel($this->channelId);
}
$this->channelId = $this->connection->get_free_channel_id();
$channel = $this->connection->channel($this->getChannelId());
$channel->queue_declare(...$this->queueSettings->getPositionalSettings());
if ($this->exchangeSettings !== null) {
$channel->exchange_declare(...$this->exchangeSettings->getPositionalSettings());
$channel->queue_bind($this->queueSettings->getName(), $this->exchangeSettings->getName());
}
return $channel;
}
| public Yiisoft\Queue\AMQP\Settings\ExchangeSettingsInterface|null getExchangeSettings ( ) |
public function getExchangeSettings(): ?ExchangeSettingsInterface
{
return $this->exchangeSettings;
}
| public array getMessageProperties ( ) |
public function getMessageProperties(): array
{
return $this->messageProperties;
}
| public Yiisoft\Queue\AMQP\Settings\QueueSettingsInterface getQueueSettings ( ) |
public function getQueueSettings(): QueueSettingsInterface
{
return $this->queueSettings;
}
| public self withChannelName ( string $channel ) | ||
| $channel | string | |
public function withChannelName(string $channel): self
{
if ($channel === $this->queueSettings->getName()) {
return $this;
}
if ($this->exchangeSettings !== null) {
throw new ExchangeDeclaredException();
}
$instance = clone $this;
$instance->queueSettings = $instance->queueSettings->withName($channel);
if ($this->channelId !== null) {
$instance->channelId = null;
}
return $instance;
}
| public self withExchangeSettings ( Yiisoft\Queue\AMQP\Settings\ExchangeSettingsInterface|null $exchangeSettings ) | ||
| $exchangeSettings | Yiisoft\Queue\AMQP\Settings\ExchangeSettingsInterface|null | |
public function withExchangeSettings(?ExchangeSettingsInterface $exchangeSettings): QueueProviderInterface
{
$new = clone $this;
$new->exchangeSettings = $exchangeSettings;
return $new;
}
| public self withMessageProperties ( array $properties ) | ||
| $properties | array | |
public function withMessageProperties(array $properties): QueueProviderInterface
{
$new = clone $this;
$new->messageProperties = $properties;
return $new;
}
| public self withQueueSettings ( Yiisoft\Queue\AMQP\Settings\QueueSettingsInterface $queueSettings ) | ||
| $queueSettings | Yiisoft\Queue\AMQP\Settings\QueueSettingsInterface | |
public function withQueueSettings(QueueSettingsInterface $queueSettings): QueueProviderInterface
{
$new = clone $this;
$new->queueSettings = $queueSettings;
return $new;
}
Signup or Login in order to comment.