0 follower

Final Class Yiisoft\Queue\AMQP\QueueProvider

InheritanceYiisoft\Queue\AMQP\QueueProvider
ImplementsYiisoft\Queue\AMQP\QueueProviderInterface

Constants

Hide inherited constants

Constant Value Description Defined By
EXCHANGE_NAME_DEFAULT 'yii-queue' Yiisoft\Queue\AMQP\QueueProvider

Method Details

Hide inherited methods

__clone() public method

public mixed __clone ( )

                public function __clone()
{
    $this->channelId = null;
}

            
__construct() public method

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 = [],
) {
}

            
__destruct() public method

public mixed __destruct ( )

                public function __destruct()
{
    if ($this->channelId !== null) {
        $this->connection->channel($this->channelId)->close();
    }
}

            
channelClose() public method

public void channelClose ( )

                public function channelClose(): void
{
    if ($this->channelId !== null) {
        $this->connection->channel($this->channelId)->close();
        $this->channelId = null;
    }
}

            
getChannel() public method

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;
}

            
getExchangeSettings() public method

public Yiisoft\Queue\AMQP\Settings\ExchangeSettingsInterface|null getExchangeSettings ( )

                public function getExchangeSettings(): ?ExchangeSettingsInterface
{
    return $this->exchangeSettings;
}

            
getMessageProperties() public method

public array getMessageProperties ( )

                public function getMessageProperties(): array
{
    return $this->messageProperties;
}

            
getQueueSettings() public method

public Yiisoft\Queue\AMQP\Settings\QueueSettingsInterface getQueueSettings ( )

                public function getQueueSettings(): QueueSettingsInterface
{
    return $this->queueSettings;
}

            
withChannelName() public method

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;
}

            
withExchangeSettings() public method

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;
}

            
withMessageProperties() public method

public self withMessageProperties ( array $properties )
$properties array

                public function withMessageProperties(array $properties): QueueProviderInterface
{
    $new = clone $this;
    $new->messageProperties = $properties;
    return $new;
}

            
withQueueSettings() public method

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;
}