Final Class Yiisoft\Queue\Amqp\QueueProvider
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| EXCHANGE_NAME_DEFAULT | 'yii-queue' | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $connection | \ |
|
| $queueSettings | Yiisoft\ |
|
| $exchangeSettings | ?\ |
|
| $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 \ |
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->channelId);
$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 ?\ |
public function getExchangeSettings(): ?ExchangeSettingsInterface
{
return $this->exchangeSettings;
}
| public array getMessageProperties ( ) |
public function getMessageProperties(): array
{
return $this->messageProperties;
}
| public Yiisoft\ |
public function getQueueSettings(): QueueSettingsInterface
{
return $this->queueSettings;
}
| public self withExchangeSettings ( ?\ | ||
| $exchangeSettings | ?\ |
|
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 withQueueName ( string $queue ) | ||
| $queue | string | |
public function withQueueName(string $queue): self
{
if ($queue === $this->queueSettings->getName()) {
return $this;
}
if ($this->exchangeSettings !== null) {
throw new ExchangeDeclaredException();
}
$instance = clone $this;
$instance->queueSettings = $instance->queueSettings->withName($queue);
return $instance;
}
| public self withQueueSettings ( Yiisoft\ | ||
| $queueSettings | Yiisoft\ |
|
public function withQueueSettings(QueueSettingsInterface $queueSettings): QueueProviderInterface
{
$new = clone $this;
$new->queueSettings = $queueSettings;
return $new;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.