From f9756163ffa923bf272aad1599a955f7e1b4eeb9 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 11 Aug 2026 16:47:01 +0300 Subject: [PATCH 1/2] Rename `name`/`queueName` identifiers to `queue` --- README.md | 6 +- docs/guide/en/console-commands.md | 12 +-- docs/guide/en/queue-capabilities.md | 2 +- docs/guide/en/queue-names-advanced.md | 4 +- docs/guide/en/queue-names.md | 8 +- docs/guide/en/usage.md | 6 +- src/AsyncQueueProducer.php | 10 +-- src/Command/ListenAllCommand.php | 22 +++--- src/Command/ListenCommand.php | 10 +-- src/Command/RunCommand.php | 12 +-- src/Debug/QueueCollector.php | 8 +- src/Debug/QueueConsumerProviderProxy.php | 12 +-- src/Debug/QueueProducerDecorator.php | 6 +- src/Debug/QueueProducerProviderProxy.php | 12 +-- src/Debug/QueueWorkerInterfaceProxy.php | 6 +- src/DefaultQueue.php | 13 ---- src/Defaults.php | 13 ++++ src/Middleware/Consume/ConsumeRequest.php | 12 +-- .../FailureHandlingRequest.php | 12 +-- .../FailureMiddlewareDispatcher.php | 14 ++-- .../ExponentialDelayMiddleware.php | 6 +- .../Implementation/SendAgainMiddleware.php | 6 +- .../Push/SynchronousPushHandler.php | 2 +- src/Provider/CompositeQueueProvider.php | 40 +++++----- src/Provider/PredefinedQueueProvider.php | 74 +++++++++--------- .../QueueConsumerProviderInterface.php | 12 +-- src/Provider/QueueFactoryProvider.php | 78 +++++++++---------- src/Provider/QueueNotFoundException.php | 4 +- .../QueueProducerProviderInterface.php | 12 +-- src/QueueConsumer.php | 8 +- src/QueueProducerInterface.php | 4 +- src/SyncQueueProducer.php | 10 +-- src/Worker/Worker.php | 6 +- src/Worker/WorkerInterface.php | 4 +- stubs/StubQueueProducer.php | 6 +- stubs/StubWorker.php | 2 +- tests/Integration/MiddlewareTest.php | 2 +- tests/Integration/QueueProviderTest.php | 16 ++-- tests/TestCase.php | 8 +- tests/Unit/Command/RunCommandTest.php | 4 +- tests/Unit/Debug/QueueDecoratorTest.php | 2 +- .../Debug/QueueProviderInterfaceProxyTest.php | 4 +- .../Middleware/Consume/ConsumeRequestTest.php | 2 +- .../Consume/MiddlewareDispatcherTest.php | 2 +- .../FailureHandlingRequestTest.php | 2 +- .../Provider/CompositeQueueProviderTest.php | 4 +- .../Provider/PredefinedQueueProviderTest.php | 4 +- .../Provider/QueueFactoryProviderTest.php | 4 +- tests/Unit/QueueTest.php | 2 +- 49 files changed, 265 insertions(+), 265 deletions(-) delete mode 100644 src/DefaultQueue.php create mode 100644 src/Defaults.php diff --git a/README.md b/README.md index 5c11189f..968f0293 100644 --- a/README.md +++ b/README.md @@ -160,13 +160,13 @@ By default, Yii Framework uses [yiisoft/yii-console](https://github.com/yiisoft/ ```bash ./yii queue:run # Handle all existing messages in the queue -./yii queue:listen [queueName] # Start a daemon listening for new messages permanently from the specified queue -./yii queue:listen-all [queueName [queueName2 [...]]] # Start a daemon listening for new messages permanently from all consumer-capable queues or specified list of queues (use with caution in production, recommended for dev only) +./yii queue:listen [queue] # Start a daemon listening for new messages permanently from the specified queue +./yii queue:listen-all [queue [queue2 [...]]] # Start a daemon listening for new messages permanently from all consumer-capable queues or specified list of queues (use with caution in production, recommended for dev only) ``` See [Console commands](docs/guide/en/console-commands.md) for more details. -Producers use `Yiisoft\Queue\QueueProducerInterface` (`push()`, `status()`, `getName()`); consumers use `Yiisoft\Queue\QueueConsumerInterface` (`run()`, `listen()`). See [capability configuration](docs/guide/en/queue-capabilities.md) for the strict role map used when named queues are configured. +Producers use `Yiisoft\Queue\QueueProducerInterface` (`push()`, `status()`, `getQueue()`); consumers use `Yiisoft\Queue\QueueConsumerInterface` (`run()`, `listen()`). See [capability configuration](docs/guide/en/queue-capabilities.md) for the strict role map used when named queues are configured. > In case you're running the queue in synchronous mode (no adapter), `queue:listen` logs an info message and exits. The messages are processed immediately when pushed. diff --git a/docs/guide/en/console-commands.md b/docs/guide/en/console-commands.md index 041bf0c1..04e49419 100644 --- a/docs/guide/en/console-commands.md +++ b/docs/guide/en/console-commands.md @@ -6,7 +6,7 @@ If you are using [yiisoft/config](https://github.com/yiisoft/config) and [yiisof If you are using [symfony/console](https://github.com/symfony/console) directly, you should register the commands manually. -> **Note:** `queue:run` and `queue:listen-all` use `QueueConsumerProviderInterface::getConsumerNames()` when no queue names are passed. Explicitly passed names are resolved with `getConsumer()` and must have a consumer role. +> **Note:** `queue:run` and `queue:listen-all` use `QueueConsumerProviderInterface::getConsumerQueues()` when no queue names are passed. Explicitly passed names are resolved with `getConsumer()` and must have a consumer role. In [yiisoft/app](https://github.com/yiisoft/app) the `yii` console binary is provided out of the box. If you are using [yiisoft/yii-console](https://github.com/yiisoft/yii-console) or `symfony/console` without that template, invoke these commands the same way you invoke other console commands in your application. @@ -22,15 +22,15 @@ You can also narrow the scope of processed messages by specifying queue name(s) The full command signature is: ```sh -yii queue:run [queueName1 [queueName2 [...]]] --limit=100 +yii queue:run [queue1 [queue2 [...]]] --limit=100 ``` ## 2. Listen for queued messages and process them continuously -The following command launches a daemon, which infinitely consumes messages from a single queue. This command receives an optional `queueName` argument to specify which queue to listen to, defaults to the queue name `yii-queue`. +The following command launches a daemon, which infinitely consumes messages from a single queue. This command receives an optional `queue` argument to specify which queue to listen to, defaults to the queue name `yii-queue`. ```sh -yii queue:listen [queueName] +yii queue:listen [queue] ``` > **Note:** If the queue is not configured with an adapter (synchronous mode), the command logs an info message and exits gracefully. @@ -39,13 +39,13 @@ yii queue:listen [queueName] The following command iterates through multiple queues and is meant to be used in development environment only, as it consumes a lot of CPU for iterating through queues. You can pass to it: -- `queueName` argument(s). Specify one or more queue names to process. Messages from other queues will be ignored. Defaults to all registered consumer-capable queue names. +- `queue` argument(s). Specify one or more queue names to process. Messages from other queues will be ignored. Defaults to all registered consumer-capable queue names. - `--limit` option to limit the number of messages processed before switching to another queue. E.g. you set `--limit` to 500 and right now you have 1000 messages in `queue1`. This command will consume only 500 of them, then it will switch to `queue2` to see if there are any messages there. Defaults to `0` (no limit). - `--pause` option to specify the number of seconds to pause between checking queues when no messages are found. Defaults to `1`. The full command signature is: ```sh -yii queue:listen-all [queueName1 [queueName2 [...]]] --pause=1 --limit=0 +yii queue:listen-all [queue1 [queue2 [...]]] --pause=1 --limit=0 ``` For long-running processes, graceful shutdown is controlled by `LoopInterface`. When `ext-pcntl` is available, diff --git a/docs/guide/en/queue-capabilities.md b/docs/guide/en/queue-capabilities.md index 5ee4ac8d..eb86d1b3 100644 --- a/docs/guide/en/queue-capabilities.md +++ b/docs/guide/en/queue-capabilities.md @@ -2,7 +2,7 @@ A logical queue name can independently expose a producer, a consumer, or both. Inject `QueueProducerInterface` to push/status messages and `QueueConsumerInterface` to run/listen. Console commands use only `QueueConsumerProviderInterface`; retry middleware uses a direct `QueueProducerInterface` or `QueueProducerProviderInterface`. -Named providers use a strict nested role map. `getProducerNames()` and `getConsumerNames()` return only names with that role. Role definitions are created lazily and cached per name and role; failed lazy creation is cached and repeated lookups rethrow the same configuration error. +Named providers use a strict nested role map. `getProducerQueues()` and `getConsumerQueues()` return only names with that role. Role definitions are created lazily and cached per name and role; failed lazy creation is cached and repeated lookups rethrow the same configuration error. ```php use Yiisoft\Queue\QueueConsumer; diff --git a/docs/guide/en/queue-names-advanced.md b/docs/guide/en/queue-names-advanced.md index 0734118e..10e155e3 100644 --- a/docs/guide/en/queue-names-advanced.md +++ b/docs/guide/en/queue-names-advanced.md @@ -10,11 +10,11 @@ Providers translate a queue name into the capability the caller needs: - `QueueProducerProviderInterface::getProducer($name)` returns a `QueueProducerInterface` for pushing messages and obtaining their status. - `QueueConsumerProviderInterface::getConsumer($name)` returns a `QueueConsumerInterface` for running or listening for messages. -- `hasProducer()` / `hasConsumer()` check whether a name exposes a role. `getProducerNames()` / `getConsumerNames()` list names for only that role. +- `hasProducer()` / `hasConsumer()` check whether a name exposes a role. `getProducerQueues()` / `getConsumerQueues()` list names for only that role. Both lookup methods accept a string or `BackedEnum`. They throw `QueueNotFoundException` when the name is unknown or does not have the requested role. This separation prevents a producer-only queue from accidentally being used by a worker, and vice versa. -The default name is `DefaultQueue::NAME`, whose value is `yii-queue`. +The default name is `Defaults::QUEUE`, whose value is `yii-queue`. ## Role-map configuration diff --git a/docs/guide/en/queue-names.md b/docs/guide/en/queue-names.md index 1895c3bc..3cede7a2 100644 --- a/docs/guide/en/queue-names.md +++ b/docs/guide/en/queue-names.md @@ -6,7 +6,7 @@ A *queue name* is a logical identifier for independently configured producer and - Use `QueueProducerProviderInterface` to obtain a named producer with `getProducer()`. - Use `QueueConsumerProviderInterface` to obtain a named consumer with `getConsumer()`; console commands use this provider. -The default name is `DefaultQueue::NAME`, whose value is `yii-queue`. +The default name is `Defaults::QUEUE`, whose value is `yii-queue`. ## When to use named queues @@ -18,7 +18,7 @@ Named queues use a strict role map under `yiisoft/queue.queues`. Each name must ```php use Yiisoft\Queue\Adapter\AdapterInterface; -use Yiisoft\Queue\DefaultQueue; +use Yiisoft\Queue\Defaults; use Yiisoft\Queue\QueueConsumer; use Yiisoft\Queue\AsyncQueueProducer; @@ -26,7 +26,7 @@ return [ 'yiisoft/queue' => [ 'queues' => [ // A queue with both capabilities. - DefaultQueue::NAME => [ + Defaults::QUEUE => [ 'producer' => ['class' => AsyncQueueProducer::class, '__construct()' => ['adapter' => AdapterInterface::class]], 'consumer' => ['class' => QueueConsumer::class, '__construct()' => ['adapter' => AdapterInterface::class]], ], @@ -78,7 +78,7 @@ final readonly class SendTransactionalEmail } ``` -Both typed providers accept strings and `BackedEnum` values. Use `getProducerNames()` or `getConsumerNames()` when enumerating only that role. +Both typed providers accept strings and `BackedEnum` values. Use `getProducerQueues()` or `getConsumerQueues()` when enumerating only that role. ## Running workers diff --git a/docs/guide/en/usage.md b/docs/guide/en/usage.md index ba4de48c..2d64fe6f 100644 --- a/docs/guide/en/usage.md +++ b/docs/guide/en/usage.md @@ -73,9 +73,9 @@ Most adapters can be consumed using [console commands](./console-commands.md) re If you configured multiple [queue names](./queue-names.md), you can choose which queue to consume with console commands: ```sh -yii queue:listen [queueName] -yii queue:run [queueName1 [queueName2 [...]]] -yii queue:listen-all [queueName1 [queueName2 [...]]] +yii queue:listen [queue] +yii queue:run [queue1 [queue2 [...]]] +yii queue:listen-all [queue1 [queue2 [...]]] ``` diff --git a/src/AsyncQueueProducer.php b/src/AsyncQueueProducer.php index 38c8a3c0..7158d1eb 100644 --- a/src/AsyncQueueProducer.php +++ b/src/AsyncQueueProducer.php @@ -18,7 +18,7 @@ */ final class AsyncQueueProducer implements QueueProducerInterface { - private string $name; + private string $queue; private PushMiddlewareDispatcher $dispatcher; /** @@ -28,10 +28,10 @@ public function __construct( private readonly LoggerInterface $logger, PushMiddlewareConfig $middlewareConfig, private readonly AdapterInterface $adapter, - string|BackedEnum $name = DefaultQueue::NAME, + string|BackedEnum $queue = Defaults::QUEUE, array $middlewareDefinitions = [], ) { - $this->name = StringNormalizer::normalize($name); + $this->queue = StringNormalizer::normalize($queue); $this->dispatcher = new PushMiddlewareDispatcher( middlewareFactory: $middlewareConfig->middlewareFactory, middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions], @@ -39,9 +39,9 @@ public function __construct( ); } - public function getName(): string + public function getQueue(): string { - return $this->name; + return $this->queue; } public function push(MessageInterface $message): MessageInterface diff --git a/src/Command/ListenAllCommand.php b/src/Command/ListenAllCommand.php index da3d53bd..c1290e19 100644 --- a/src/Command/ListenAllCommand.php +++ b/src/Command/ListenAllCommand.php @@ -37,7 +37,7 @@ public function configure(): void $this->addArgument( 'queue', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, - 'Queue name list to connect to', + 'Queue list to connect to', [], ) ->addOption( @@ -61,19 +61,19 @@ public function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - /** @var string[] $queueNames */ - $queueNames = $input->getArgument('queue'); - if ($queueNames === []) { - $queueNames = $this->queueProvider->getConsumerNames(); + /** @var string[] $queues */ + $queues = $input->getArgument('queue'); + if ($queues === []) { + $queues = $this->queueProvider->getConsumerQueues(); } - $queues = []; + $consumers = []; /** @var string $queue */ - foreach ($queueNames as $queue) { - $queues[] = $this->queueProvider->getConsumer($queue); + foreach ($queues as $queue) { + $consumers[] = $this->queueProvider->getConsumer($queue); } - if ($queues === []) { + if ($consumers === []) { $output->writeln('No consumers are configured.'); return Command::SUCCESS; @@ -86,8 +86,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int while ($this->loop->canContinue()) { $hasMessages = false; - foreach ($queues as $queue) { - $hasMessages = $queue->run((int) $input->getOption('limit')) > 0 || $hasMessages; + foreach ($consumers as $consumer) { + $hasMessages = $consumer->run((int) $input->getOption('limit')) > 0 || $hasMessages; } if (!$hasMessages) { diff --git a/src/Command/ListenCommand.php b/src/Command/ListenCommand.php index 14b9e04c..7046b906 100644 --- a/src/Command/ListenCommand.php +++ b/src/Command/ListenCommand.php @@ -9,7 +9,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Yiisoft\Queue\DefaultQueue; +use Yiisoft\Queue\Defaults; use Yiisoft\Queue\Provider\QueueConsumerProviderInterface; #[AsCommand( @@ -29,16 +29,16 @@ public function configure(): void $this->addArgument( 'queue', InputArgument::OPTIONAL, - 'Queue name to connect to', - DefaultQueue::NAME, + 'Queue to connect to', + Defaults::QUEUE, ); } protected function execute(InputInterface $input, OutputInterface $output): int { - $queueName = (string) $input->getArgument('queue'); + $queue = (string) $input->getArgument('queue'); - $this->queueProvider->getConsumer($queueName)->listen(); + $this->queueProvider->getConsumer($queue)->listen(); return Command::SUCCESS; } diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index 71f4c3c1..70a8e081 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -29,7 +29,7 @@ public function configure(): void $this->addArgument( 'queue', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, - 'Queue name list to connect to.', + 'Queue list to connect to.', [], ) ->addOption( @@ -44,14 +44,14 @@ public function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - /** @var string[] $queueNames */ - $queueNames = $input->getArgument('queue'); - if ($queueNames === []) { - $queueNames = $this->queueProvider->getConsumerNames(); + /** @var string[] $queues */ + $queues = $input->getArgument('queue'); + if ($queues === []) { + $queues = $this->queueProvider->getConsumerQueues(); } /** @var string $queue */ - foreach ($queueNames as $queue) { + foreach ($queues as $queue) { $queueConsumer = $this->queueProvider->getConsumer($queue); $output->write("Processing queue $queue... "); diff --git a/src/Debug/QueueCollector.php b/src/Debug/QueueCollector.php index 92ddba5c..47458a04 100644 --- a/src/Debug/QueueCollector.php +++ b/src/Debug/QueueCollector.php @@ -52,24 +52,24 @@ public function collectStatus(string $id, MessageStatus $status, string $line): ]; } - public function collectPush(string $queueName, MessageInterface $message, string $line): void + public function collectPush(string $queue, MessageInterface $message, string $line): void { if (!$this->isActive()) { return; } - $this->pushes[$queueName][] = [ + $this->pushes[$queue][] = [ 'message' => $message, 'line' => $line, ]; } - public function collectWorkerProcessing(MessageInterface $message, string $queueName): void + public function collectWorkerProcessing(MessageInterface $message, string $queue): void { if (!$this->isActive()) { return; } - $this->processingMessages[$queueName][] = $message; + $this->processingMessages[$queue][] = $message; } public function getSummary(): array diff --git a/src/Debug/QueueConsumerProviderProxy.php b/src/Debug/QueueConsumerProviderProxy.php index c842c5ad..fd970063 100644 --- a/src/Debug/QueueConsumerProviderProxy.php +++ b/src/Debug/QueueConsumerProviderProxy.php @@ -12,18 +12,18 @@ final class QueueConsumerProviderProxy implements QueueConsumerProviderInterface { public function __construct(private readonly QueueConsumerProviderInterface $provider, private readonly QueueCollector $collector) {} - public function getConsumer(string|BackedEnum $name): QueueConsumerInterface + public function getConsumer(string|BackedEnum $queue): QueueConsumerInterface { - return new QueueConsumerDecorator($this->provider->getConsumer($name), $this->collector); + return new QueueConsumerDecorator($this->provider->getConsumer($queue), $this->collector); } - public function hasConsumer(string|BackedEnum $name): bool + public function hasConsumer(string|BackedEnum $queue): bool { - return $this->provider->hasConsumer($name); + return $this->provider->hasConsumer($queue); } - public function getConsumerNames(): array + public function getConsumerQueues(): array { - return $this->provider->getConsumerNames(); + return $this->provider->getConsumerQueues(); } } diff --git a/src/Debug/QueueProducerDecorator.php b/src/Debug/QueueProducerDecorator.php index f973c48d..e9c19f35 100644 --- a/src/Debug/QueueProducerDecorator.php +++ b/src/Debug/QueueProducerDecorator.php @@ -22,12 +22,12 @@ public function status(string|int $id): MessageStatus public function push(MessageInterface $message): MessageInterface { /** @psalm-var array{file: string, line: int} $stack */ $stack = debug_backtrace()[0]; $message = $this->queue->push($message); - $this->collector->collectPush($this->queue->getName(), $message, $stack['file'] . ':' . $stack['line']); + $this->collector->collectPush($this->queue->getQueue(), $message, $stack['file'] . ':' . $stack['line']); return $message; } - public function getName(): string + public function getQueue(): string { - return $this->queue->getName(); + return $this->queue->getQueue(); } } diff --git a/src/Debug/QueueProducerProviderProxy.php b/src/Debug/QueueProducerProviderProxy.php index ed929f6d..297e9e32 100644 --- a/src/Debug/QueueProducerProviderProxy.php +++ b/src/Debug/QueueProducerProviderProxy.php @@ -12,18 +12,18 @@ final class QueueProducerProviderProxy implements QueueProducerProviderInterface { public function __construct(private readonly QueueProducerProviderInterface $provider, private readonly QueueCollector $collector) {} - public function getProducer(string|BackedEnum $name): QueueProducerInterface + public function getProducer(string|BackedEnum $queue): QueueProducerInterface { - return new QueueProducerDecorator($this->provider->getProducer($name), $this->collector); + return new QueueProducerDecorator($this->provider->getProducer($queue), $this->collector); } - public function hasProducer(string|BackedEnum $name): bool + public function hasProducer(string|BackedEnum $queue): bool { - return $this->provider->hasProducer($name); + return $this->provider->hasProducer($queue); } - public function getProducerNames(): array + public function getProducerQueues(): array { - return $this->provider->getProducerNames(); + return $this->provider->getProducerQueues(); } } diff --git a/src/Debug/QueueWorkerInterfaceProxy.php b/src/Debug/QueueWorkerInterfaceProxy.php index b26c5cd5..f40dc873 100644 --- a/src/Debug/QueueWorkerInterfaceProxy.php +++ b/src/Debug/QueueWorkerInterfaceProxy.php @@ -17,10 +17,10 @@ public function __construct( public function process( MessageInterface $message, - string $queueName, + string $queue, ?QueueProducerInterface $retryProducer = null, ): MessageInterface { - $this->collector->collectWorkerProcessing($message, $queueName); - return $this->worker->process($message, $queueName, $retryProducer); + $this->collector->collectWorkerProcessing($message, $queue); + return $this->worker->process($message, $queue, $retryProducer); } } diff --git a/src/DefaultQueue.php b/src/DefaultQueue.php deleted file mode 100644 index 07eb52a1..00000000 --- a/src/DefaultQueue.php +++ /dev/null @@ -1,13 +0,0 @@ -message; } - /** Logical name of the queue currently executing this message. */ - public function getQueueName(): string + /** Logical queue currently executing this message. */ + public function getQueue(): string { - return $this->queueName; + return $this->queue; } public function withMessage(MessageInterface $message): self @@ -28,10 +28,10 @@ public function withMessage(MessageInterface $message): self return $instance; } - public function withQueueName(string $queueName): self + public function withQueue(string $queue): self { $instance = clone $this; - $instance->queueName = $queueName; + $instance->queue = $queue; return $instance; } } diff --git a/src/Middleware/FailureHandling/FailureHandlingRequest.php b/src/Middleware/FailureHandling/FailureHandlingRequest.php index 03dc9888..50a5c4c7 100644 --- a/src/Middleware/FailureHandling/FailureHandlingRequest.php +++ b/src/Middleware/FailureHandling/FailureHandlingRequest.php @@ -13,7 +13,7 @@ final class FailureHandlingRequest public function __construct( private MessageInterface $message, private Throwable $exception, - private string $queueName, + private string $queue, private ?QueueProducerInterface $retryProducer = null, ) {} @@ -27,10 +27,10 @@ public function getException(): Throwable return $this->exception; } - /** Logical name of the queue which executed the message. */ - public function getQueueName(): string + /** Logical queue which executed the message. */ + public function getQueue(): string { - return $this->queueName; + return $this->queue; } /** Direct retry target used by synchronous producer execution, if any. */ @@ -53,10 +53,10 @@ public function withException(Throwable $exception): self return $instance; } - public function withQueueName(string $queueName): self + public function withQueue(string $queue): self { $instance = clone $this; - $instance->queueName = $queueName; + $instance->queue = $queue; return $instance; } } diff --git a/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php b/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php index 3647e6ad..76225b4b 100644 --- a/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php +++ b/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php @@ -37,17 +37,17 @@ public function dispatch( FailureHandlingRequest $request, FailureHandlerInterface $finishHandler, ): FailureHandlingRequest { - $queueName = $request->getQueueName(); - if (!isset($this->middlewareDefinitions[$queueName]) || $this->middlewareDefinitions[$queueName] === []) { - $queueName = self::DEFAULT_PIPELINE; + $queue = $request->getQueue(); + if (!isset($this->middlewareDefinitions[$queue]) || $this->middlewareDefinitions[$queue] === []) { + $queue = self::DEFAULT_PIPELINE; } - $definitions = array_reverse($this->middlewareDefinitions[$queueName]); + $definitions = array_reverse($this->middlewareDefinitions[$queue]); - if (!isset($this->stack[$queueName])) { - $this->stack[$queueName] = new FailureMiddlewareStack($this->buildMiddlewares(...$definitions), $finishHandler); + if (!isset($this->stack[$queue])) { + $this->stack[$queue] = new FailureMiddlewareStack($this->buildMiddlewares(...$definitions), $finishHandler); } - return $this->stack[$queueName]->handleFailure($request); + return $this->stack[$queue]->handleFailure($request); } /** diff --git a/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php b/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php index 524461c6..40b3bcf0 100644 --- a/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php +++ b/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php @@ -67,12 +67,12 @@ private function producer(FailureHandlingRequest $request): QueueProducerInterfa return $request->getRetryProducer(); } if ($this->producerProvider === null) { - throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": configure a producer target or QueueProducerProviderInterface.', $request->getQueueName())); + throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": configure a producer target or QueueProducerProviderInterface.', $request->getQueue())); } try { - return $this->producerProvider->getProducer($request->getQueueName()); + return $this->producerProvider->getProducer($request->getQueue()); } catch (Throwable $exception) { - throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": no producer capability is available.', $request->getQueueName()), previous: $exception); + throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": no producer capability is available.', $request->getQueue()), previous: $exception); } } diff --git a/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php b/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php index 1de2074d..0870be80 100644 --- a/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php +++ b/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php @@ -48,12 +48,12 @@ public function processFailure(FailureHandlingRequest $request, FailureHandlerIn private function sourceProducer(FailureHandlingRequest $request): QueueProducerInterface { if ($this->producerProvider === null) { - throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": configure a producer target or QueueProducerProviderInterface.', $request->getQueueName())); + throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": configure a producer target or QueueProducerProviderInterface.', $request->getQueue())); } try { - return $this->producerProvider->getProducer($request->getQueueName()); + return $this->producerProvider->getProducer($request->getQueue()); } catch (Throwable $exception) { - throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": no producer capability is available.', $request->getQueueName()), previous: $exception); + throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": no producer capability is available.', $request->getQueue()), previous: $exception); } } diff --git a/src/Middleware/Push/SynchronousPushHandler.php b/src/Middleware/Push/SynchronousPushHandler.php index f35c1009..2b017d41 100644 --- a/src/Middleware/Push/SynchronousPushHandler.php +++ b/src/Middleware/Push/SynchronousPushHandler.php @@ -20,7 +20,7 @@ public function __construct( public function handlePush(MessageInterface $message): MessageInterface { - $this->worker->process($message, $this->queue->getName(), $this->queue); + $this->worker->process($message, $this->queue->getQueue(), $this->queue); return $message; } diff --git a/src/Provider/CompositeQueueProvider.php b/src/Provider/CompositeQueueProvider.php index 6218da60..4f548909 100644 --- a/src/Provider/CompositeQueueProvider.php +++ b/src/Provider/CompositeQueueProvider.php @@ -29,65 +29,65 @@ public function __construct(QueueProducerProviderInterface|QueueConsumerProvider } } - public function getProducer(string|BackedEnum $name): QueueProducerInterface + public function getProducer(string|BackedEnum $queue): QueueProducerInterface { foreach ($this->producerProviders as $provider) { - if ($provider->hasProducer($name)) { - return $provider->getProducer($name); + if ($provider->hasProducer($queue)) { + return $provider->getProducer($queue); } } - throw new QueueNotFoundException(StringNormalizer::normalize($name)); + throw new QueueNotFoundException(StringNormalizer::normalize($queue)); } - public function hasProducer(string|BackedEnum $name): bool + public function hasProducer(string|BackedEnum $queue): bool { foreach ($this->producerProviders as $p) { - if ($p->hasProducer($name)) { + if ($p->hasProducer($queue)) { return true; } } return false; } /** @return list */ - public function getProducerNames(): array + public function getProducerQueues(): array { $result = []; foreach ($this->producerProviders as $provider) { - foreach ($provider->getProducerNames() as $name) { - if (!in_array($name, $result, true)) { - $result[] = $name; + foreach ($provider->getProducerQueues() as $queue) { + if (!in_array($queue, $result, true)) { + $result[] = $queue; } } } return $result; } - public function getConsumer(string|BackedEnum $name): QueueConsumerInterface + public function getConsumer(string|BackedEnum $queue): QueueConsumerInterface { foreach ($this->consumerProviders as $provider) { - if ($provider->hasConsumer($name)) { - return $provider->getConsumer($name); + if ($provider->hasConsumer($queue)) { + return $provider->getConsumer($queue); } } - throw new QueueNotFoundException(StringNormalizer::normalize($name)); + throw new QueueNotFoundException(StringNormalizer::normalize($queue)); } - public function hasConsumer(string|BackedEnum $name): bool + public function hasConsumer(string|BackedEnum $queue): bool { foreach ($this->consumerProviders as $p) { - if ($p->hasConsumer($name)) { + if ($p->hasConsumer($queue)) { return true; } } return false; } /** @return list */ - public function getConsumerNames(): array + public function getConsumerQueues(): array { $result = []; foreach ($this->consumerProviders as $provider) { - foreach ($provider->getConsumerNames() as $name) { - if (!in_array($name, $result, true)) { - $result[] = $name; + foreach ($provider->getConsumerQueues() as $queue) { + if (!in_array($queue, $result, true)) { + $result[] = $queue; } } } return $result; diff --git a/src/Provider/PredefinedQueueProvider.php b/src/Provider/PredefinedQueueProvider.php index 7bb7335a..0e8bf667 100644 --- a/src/Provider/PredefinedQueueProvider.php +++ b/src/Provider/PredefinedQueueProvider.php @@ -24,91 +24,91 @@ final class PredefinedQueueProvider implements QueueProducerProviderInterface, Q /** @var array> */ private array $queues = []; /** @var list */ - private array $producerNames = []; + private array $producerQueues = []; /** @var list */ - private array $consumerNames = []; + private array $consumerQueues = []; /** @param array $queues */ public function __construct(array $queues) { - foreach ($queues as $name => $roles) { + foreach ($queues as $queue => $roles) { if (!is_array($roles) || $roles === []) { - throw new InvalidQueueConfigException(sprintf('Queue "%s" must be a non-empty role map containing ready "producer" and/or "consumer" instances.', $name)); + throw new InvalidQueueConfigException(sprintf('Queue "%s" must be a non-empty role map containing ready "producer" and/or "consumer" instances.', $queue)); } $unknown = array_diff(array_keys($roles), ['producer', 'consumer']); if ($unknown !== []) { - throw new InvalidQueueConfigException(sprintf('Queue "%s" has unknown role key(s) "%s". Only "producer" and "consumer" are allowed.', $name, implode('", "', $unknown))); + throw new InvalidQueueConfigException(sprintf('Queue "%s" has unknown role key(s) "%s". Only "producer" and "consumer" are allowed.', $queue, implode('", "', $unknown))); } - foreach ($roles as $role => $queue) { + foreach ($roles as $role => $instance) { $expected = $role === 'producer' ? QueueProducerInterface::class : QueueConsumerInterface::class; - if (!$queue instanceof $expected) { - $hint = is_array($queue) || is_string($queue) ? ' Use QueueFactoryProvider for factory definitions.' : ''; + if (!$instance instanceof $expected) { + $hint = is_array($instance) || is_string($instance) ? ' Use QueueFactoryProvider for factory definitions.' : ''; throw new InvalidQueueConfigException(sprintf( 'Queue "%s" role "%s" must be a ready instance of "%s"; got "%s" (configuration path queues.%s.%s).%s', - $name, + $queue, $role, $expected, - get_debug_type($queue), - $name, + get_debug_type($instance), + $queue, $role, $hint, )); } } /** @var array $roles */ - $this->queues[$name] = $roles; + $this->queues[$queue] = $roles; if (array_key_exists('producer', $roles)) { - $this->producerNames[] = $name; + $this->producerQueues[] = $queue; } if (array_key_exists('consumer', $roles)) { - $this->consumerNames[] = $name; + $this->consumerQueues[] = $queue; } } } - public function getProducer(string|BackedEnum $name): QueueProducerInterface + public function getProducer(string|BackedEnum $queue): QueueProducerInterface { - $queue = $this->get($name, 'producer'); - assert($queue instanceof QueueProducerInterface); - return $queue; + $instance = $this->get($queue, 'producer'); + assert($instance instanceof QueueProducerInterface); + return $instance; } - public function hasProducer(string|BackedEnum $name): bool + public function hasProducer(string|BackedEnum $queue): bool { - return array_key_exists('producer', $this->queues[StringNormalizer::normalize($name)] ?? []); + return array_key_exists('producer', $this->queues[StringNormalizer::normalize($queue)] ?? []); } - public function getProducerNames(): array + public function getProducerQueues(): array { - return $this->producerNames; + return $this->producerQueues; } - public function getConsumer(string|BackedEnum $name): QueueConsumerInterface + public function getConsumer(string|BackedEnum $queue): QueueConsumerInterface { - $queue = $this->get($name, 'consumer'); - assert($queue instanceof QueueConsumerInterface); - return $queue; + $instance = $this->get($queue, 'consumer'); + assert($instance instanceof QueueConsumerInterface); + return $instance; } - public function hasConsumer(string|BackedEnum $name): bool + public function hasConsumer(string|BackedEnum $queue): bool { - return array_key_exists('consumer', $this->queues[StringNormalizer::normalize($name)] ?? []); + return array_key_exists('consumer', $this->queues[StringNormalizer::normalize($queue)] ?? []); } - public function getConsumerNames(): array + public function getConsumerQueues(): array { - return $this->consumerNames; + return $this->consumerQueues; } - private function get(string|BackedEnum $name, string $role): QueueProducerInterface|QueueConsumerInterface + private function get(string|BackedEnum $queue, string $role): QueueProducerInterface|QueueConsumerInterface { - $name = StringNormalizer::normalize($name); - if (!array_key_exists($name, $this->queues)) { - throw new QueueNotFoundException($name); + $queue = StringNormalizer::normalize($queue); + if (!array_key_exists($queue, $this->queues)) { + throw new QueueNotFoundException($queue); } - if (!array_key_exists($role, $this->queues[$name])) { - throw new QueueNotFoundException(sprintf('Queue "%s" does not have the "%s" capability.', $name, $role)); + if (!array_key_exists($role, $this->queues[$queue])) { + throw new QueueNotFoundException(sprintf('Queue "%s" does not have the "%s" capability.', $queue, $role)); } - return $this->queues[$name][$role]; + return $this->queues[$queue][$role]; } } diff --git a/src/Provider/QueueConsumerProviderInterface.php b/src/Provider/QueueConsumerProviderInterface.php index 56aed416..1f537fa0 100644 --- a/src/Provider/QueueConsumerProviderInterface.php +++ b/src/Provider/QueueConsumerProviderInterface.php @@ -7,15 +7,15 @@ use BackedEnum; use Yiisoft\Queue\QueueConsumerInterface; -/** Finds consumer capabilities by logical queue name. */ +/** Finds consumer capabilities by logical queue. */ interface QueueConsumerProviderInterface { /** @throws InvalidQueueConfigException|QueueNotFoundException|QueueProviderException */ - public function getConsumer(string|BackedEnum $name): QueueConsumerInterface; + public function getConsumer(string|BackedEnum $queue): QueueConsumerInterface; - /** Whether this name has a configured consumer role. */ - public function hasConsumer(string|BackedEnum $name): bool; + /** Whether this queue has a configured consumer role. */ + public function hasConsumer(string|BackedEnum $queue): bool; - /** @return list Names which have a configured consumer role. */ - public function getConsumerNames(): array; + /** @return list Queues which have a configured consumer role. */ + public function getConsumerQueues(): array; } diff --git a/src/Provider/QueueFactoryProvider.php b/src/Provider/QueueFactoryProvider.php index ed414653..1e8a4184 100644 --- a/src/Provider/QueueFactoryProvider.php +++ b/src/Provider/QueueFactoryProvider.php @@ -29,9 +29,9 @@ final class QueueFactoryProvider implements QueueProducerProviderInterface, Queu /** @var array> */ private array $resolved = []; /** @var list */ - private array $producerNames = []; + private array $producerQueues = []; /** @var list */ - private array $consumerNames = []; + private array $consumerQueues = []; /** @param array $definitions */ public function __construct( @@ -42,98 +42,98 @@ public function __construct( /** @var array> $validatedDefinitions */ $validatedDefinitions = $this->validateRoleMaps($definitions); $this->definitions = $validatedDefinitions; - foreach ($this->definitions as $name => $roles) { + foreach ($this->definitions as $queue => $roles) { if (array_key_exists('producer', $roles)) { - $this->producerNames[] = $name; + $this->producerQueues[] = $queue; } if (array_key_exists('consumer', $roles)) { - $this->consumerNames[] = $name; + $this->consumerQueues[] = $queue; } } } - public function getProducer(string|BackedEnum $name): QueueProducerInterface + public function getProducer(string|BackedEnum $queue): QueueProducerInterface { - $producer = $this->get($name, 'producer', QueueProducerInterface::class); + $producer = $this->get($queue, 'producer', QueueProducerInterface::class); assert($producer instanceof QueueProducerInterface); return $producer; } - public function hasProducer(string|BackedEnum $name): bool + public function hasProducer(string|BackedEnum $queue): bool { - return array_key_exists('producer', $this->definitions[StringNormalizer::normalize($name)] ?? []); + return array_key_exists('producer', $this->definitions[StringNormalizer::normalize($queue)] ?? []); } - public function getProducerNames(): array + public function getProducerQueues(): array { - return $this->producerNames; + return $this->producerQueues; } - public function getConsumer(string|BackedEnum $name): QueueConsumerInterface + public function getConsumer(string|BackedEnum $queue): QueueConsumerInterface { - $consumer = $this->get($name, 'consumer', QueueConsumerInterface::class); + $consumer = $this->get($queue, 'consumer', QueueConsumerInterface::class); assert($consumer instanceof QueueConsumerInterface); return $consumer; } - public function hasConsumer(string|BackedEnum $name): bool + public function hasConsumer(string|BackedEnum $queue): bool { - return array_key_exists('consumer', $this->definitions[StringNormalizer::normalize($name)] ?? []); + return array_key_exists('consumer', $this->definitions[StringNormalizer::normalize($queue)] ?? []); } - public function getConsumerNames(): array + public function getConsumerQueues(): array { - return $this->consumerNames; + return $this->consumerQueues; } /** @template T of QueueProducerInterface|QueueConsumerInterface @param class-string $expected @return T */ - private function get(string|BackedEnum $name, string $role, string $expected): QueueProducerInterface|QueueConsumerInterface + private function get(string|BackedEnum $queue, string $role, string $expected): QueueProducerInterface|QueueConsumerInterface { - $name = StringNormalizer::normalize($name); - if (!array_key_exists($name, $this->definitions)) { - throw new QueueNotFoundException($name); + $queue = StringNormalizer::normalize($queue); + if (!array_key_exists($queue, $this->definitions)) { + throw new QueueNotFoundException($queue); } - if (!array_key_exists($role, $this->definitions[$name])) { - throw new QueueNotFoundException(sprintf('Queue "%s" does not have the "%s" capability.', $name, $role)); + if (!array_key_exists($role, $this->definitions[$queue])) { + throw new QueueNotFoundException(sprintf('Queue "%s" does not have the "%s" capability.', $queue, $role)); } - if (isset($this->resolved[$name][$role])) { - $result = $this->resolved[$name][$role]; + if (isset($this->resolved[$queue][$role])) { + $result = $this->resolved[$queue][$role]; if ($result instanceof Throwable) { throw $result; } return $result; } try { - $key = $name . ':' . $role; - $factory = new StrictFactory([$key => $this->definitions[$name][$role]], $this->container, $this->validate); + $key = $queue . ':' . $role; + $factory = new StrictFactory([$key => $this->definitions[$queue][$role]], $this->container, $this->validate); $result = $factory->create($key); if (!$result instanceof $expected) { throw new InvalidQueueConfigException(sprintf( 'Queue "%s" role "%s" must implement "%s"; got "%s" (configuration path queues.%s.%s).', - $name, + $queue, $role, $expected, get_debug_type($result), - $name, + $queue, $role, )); } assert($result instanceof QueueProducerInterface || $result instanceof QueueConsumerInterface); - $this->resolved[$name][$role] = $result; + $this->resolved[$queue][$role] = $result; return $result; } catch (InvalidQueueConfigException $exception) { - $this->resolved[$name][$role] = $exception; + $this->resolved[$queue][$role] = $exception; throw $exception; } catch (InvalidConfigException $exception) { $wrapped = new InvalidQueueConfigException(sprintf( 'Invalid queue "%s" role "%s" definition (configuration path queues.%s.%s): %s', - $name, + $queue, $role, - $name, + $queue, $role, $exception->getMessage(), ), previous: $exception); - $this->resolved[$name][$role] = $wrapped; + $this->resolved[$queue][$role] = $wrapped; throw $wrapped; } } @@ -143,20 +143,20 @@ private function validateRoleMaps(array $definitions): array { /** @var array> $result */ $result = []; - foreach ($definitions as $name => $roles) { + foreach ($definitions as $queue => $roles) { if (!is_array($roles)) { - throw new InvalidQueueConfigException(sprintf('Queue "%s" must be a role map containing "producer" and/or "consumer"; got "%s".', $name, get_debug_type($roles))); + throw new InvalidQueueConfigException(sprintf('Queue "%s" must be a role map containing "producer" and/or "consumer"; got "%s".', $queue, get_debug_type($roles))); } $keys = array_keys($roles); $unknown = array_diff($keys, ['producer', 'consumer']); if ($unknown !== []) { - throw new InvalidQueueConfigException(sprintf('Queue "%s" has unknown role key(s) "%s". Only "producer" and "consumer" are allowed.', $name, implode('", "', $unknown))); + throw new InvalidQueueConfigException(sprintf('Queue "%s" has unknown role key(s) "%s". Only "producer" and "consumer" are allowed.', $queue, implode('", "', $unknown))); } if ($roles === []) { - throw new InvalidQueueConfigException(sprintf('Queue "%s" role map must contain "producer" and/or "consumer".', $name)); + throw new InvalidQueueConfigException(sprintf('Queue "%s" role map must contain "producer" and/or "consumer".', $queue)); } /** @var array $roles */ - $result[$name] = $roles; + $result[$queue] = $roles; } return $result; } diff --git a/src/Provider/QueueNotFoundException.php b/src/Provider/QueueNotFoundException.php index 08acbe40..836481e8 100644 --- a/src/Provider/QueueNotFoundException.php +++ b/src/Provider/QueueNotFoundException.php @@ -16,10 +16,10 @@ */ final class QueueNotFoundException extends LogicException implements QueueProviderException { - public function __construct(string|BackedEnum $name, int $code = 0, ?Throwable $previous = null) + public function __construct(string|BackedEnum $queue, int $code = 0, ?Throwable $previous = null) { parent::__construct( - sprintf('Queue with name "%s" not found.', StringNormalizer::normalize($name)), + sprintf('Queue "%s" not found.', StringNormalizer::normalize($queue)), $code, $previous, ); diff --git a/src/Provider/QueueProducerProviderInterface.php b/src/Provider/QueueProducerProviderInterface.php index a83ab001..069e6735 100644 --- a/src/Provider/QueueProducerProviderInterface.php +++ b/src/Provider/QueueProducerProviderInterface.php @@ -7,15 +7,15 @@ use BackedEnum; use Yiisoft\Queue\QueueProducerInterface; -/** Finds producer capabilities by logical queue name. */ +/** Finds producer capabilities by logical queue. */ interface QueueProducerProviderInterface { /** @throws InvalidQueueConfigException|QueueNotFoundException|QueueProviderException */ - public function getProducer(string|BackedEnum $name): QueueProducerInterface; + public function getProducer(string|BackedEnum $queue): QueueProducerInterface; - /** Whether this name has a configured producer role. */ - public function hasProducer(string|BackedEnum $name): bool; + /** Whether this queue has a configured producer role. */ + public function hasProducer(string|BackedEnum $queue): bool; - /** @return list Names which have a configured producer role. */ - public function getProducerNames(): array; + /** @return list Queues which have a configured producer role. */ + public function getProducerQueues(): array; } diff --git a/src/QueueConsumer.php b/src/QueueConsumer.php index eddb0d9a..43bd82c6 100644 --- a/src/QueueConsumer.php +++ b/src/QueueConsumer.php @@ -14,16 +14,16 @@ /** Consumes messages for one logical queue. */ final class QueueConsumer implements QueueConsumerInterface { - private string $name; + private string $queue; public function __construct( private readonly WorkerInterface $worker, private readonly LoopInterface $loop, private readonly LoggerInterface $logger, private readonly ?AdapterInterface $adapter = null, - string|BackedEnum $name = DefaultQueue::NAME, + string|BackedEnum $queue = Defaults::QUEUE, ) { - $this->name = StringNormalizer::normalize($name); + $this->queue = StringNormalizer::normalize($queue); } public function run(int $max = 0): int @@ -58,7 +58,7 @@ public function listen(): void private function handle(MessageInterface $message): bool { - $this->worker->process($message, $this->name); + $this->worker->process($message, $this->queue); return $this->loop->canContinue(); } } diff --git a/src/QueueProducerInterface.php b/src/QueueProducerInterface.php index 21906bc2..578b11ba 100644 --- a/src/QueueProducerInterface.php +++ b/src/QueueProducerInterface.php @@ -15,6 +15,6 @@ public function push(MessageInterface $message): MessageInterface; /** Returns the status of a message ID. */ public function status(string|int $id): MessageStatus; - /** Returns the logical queue name. */ - public function getName(): string; + /** Returns the logical queue. */ + public function getQueue(): string; } diff --git a/src/SyncQueueProducer.php b/src/SyncQueueProducer.php index 53315f9a..475d8cc8 100644 --- a/src/SyncQueueProducer.php +++ b/src/SyncQueueProducer.php @@ -17,7 +17,7 @@ */ final class SyncQueueProducer implements QueueProducerInterface { - private string $name; + private string $queue; private PushMiddlewareDispatcher $dispatcher; /** @@ -27,10 +27,10 @@ public function __construct( private readonly LoggerInterface $logger, PushMiddlewareConfig $middlewareConfig, WorkerInterface $worker, - string|BackedEnum $name = DefaultQueue::NAME, + string|BackedEnum $queue = Defaults::QUEUE, array $middlewareDefinitions = [], ) { - $this->name = StringNormalizer::normalize($name); + $this->queue = StringNormalizer::normalize($queue); $this->dispatcher = new PushMiddlewareDispatcher( middlewareFactory: $middlewareConfig->middlewareFactory, middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions], @@ -38,9 +38,9 @@ public function __construct( ); } - public function getName(): string + public function getQueue(): string { - return $this->name; + return $this->queue; } public function push(MessageInterface $message): MessageInterface diff --git a/src/Worker/Worker.php b/src/Worker/Worker.php index 65f7c8b9..95094467 100644 --- a/src/Worker/Worker.php +++ b/src/Worker/Worker.php @@ -51,7 +51,7 @@ public function __construct( */ public function process( MessageInterface $message, - string $queueName, + string $queue, ?QueueProducerInterface $retryProducer = null, ): MessageInterface { $messageId = IdEnvelope::fromMessage($message)->getId(); @@ -72,12 +72,12 @@ public function process( throw new RuntimeException(sprintf('Queue handler for message type "%s" does not exist.', $messageType)); } - $request = new ConsumeRequest($message, $queueName); + $request = new ConsumeRequest($message, $queue); $closure = fn(MessageInterface $message): mixed => $this->injector->invoke($handler, [$message]); try { return $this->consumeMiddlewareDispatcher->dispatch($request, $this->createConsumeHandler($closure))->getMessage(); } catch (Throwable $exception) { - $request = new FailureHandlingRequest($request->getMessage(), $exception, $request->getQueueName(), $retryProducer); + $request = new FailureHandlingRequest($request->getMessage(), $exception, $request->getQueue(), $retryProducer); try { $result = $this->failureMiddlewareDispatcher->dispatch($request, $this->createFailureHandler()); diff --git a/src/Worker/WorkerInterface.php b/src/Worker/WorkerInterface.php index 08ca5849..eb71528e 100644 --- a/src/Worker/WorkerInterface.php +++ b/src/Worker/WorkerInterface.php @@ -9,10 +9,10 @@ interface WorkerInterface { - /** @param string $queueName Logical execution queue name. */ + /** @param string $queue Logical execution queue. */ public function process( MessageInterface $message, - string $queueName, + string $queue, ?QueueProducerInterface $retryProducer = null, ): MessageInterface; } diff --git a/stubs/StubQueueProducer.php b/stubs/StubQueueProducer.php index bac0547e..fab64363 100644 --- a/stubs/StubQueueProducer.php +++ b/stubs/StubQueueProducer.php @@ -10,7 +10,7 @@ final class StubQueueProducer implements QueueProducerInterface { - public function __construct(private string $name = 'default') {} + public function __construct(private string $queue = 'default') {} public function push(MessageInterface $message): MessageInterface { @@ -22,8 +22,8 @@ public function status(string|int $id): MessageStatus return MessageStatus::DONE; } - public function getName(): string + public function getQueue(): string { - return $this->name; + return $this->queue; } } diff --git a/stubs/StubWorker.php b/stubs/StubWorker.php index 9e8bec68..11bf658d 100644 --- a/stubs/StubWorker.php +++ b/stubs/StubWorker.php @@ -15,7 +15,7 @@ final class StubWorker implements WorkerInterface { public function process( MessageInterface $message, - string $queueName, + string $queue, ?QueueProducerInterface $retryProducer = null, ): MessageInterface { return $message; diff --git a/tests/Integration/MiddlewareTest.php b/tests/Integration/MiddlewareTest.php index 3ef03f6f..6dc2363d 100644 --- a/tests/Integration/MiddlewareTest.php +++ b/tests/Integration/MiddlewareTest.php @@ -131,7 +131,7 @@ public function testFullStackFailure(): void $callableFactory = new CallableFactory($container); $queue->expects(self::exactly(7))->method('push')->willReturnCallback($queueCallback); - $queue->method('getName')->willReturn('simple'); + $queue->method('getQueue')->willReturn('simple'); $middlewares = [ 'test-queue' => [ diff --git a/tests/Integration/QueueProviderTest.php b/tests/Integration/QueueProviderTest.php index c2af9af7..3d5e3fd2 100644 --- a/tests/Integration/QueueProviderTest.php +++ b/tests/Integration/QueueProviderTest.php @@ -33,7 +33,7 @@ public function testFactoryRoleMapsResolveThroughContainerAndKeepCapabilitiesSep 'both' => [ 'producer' => [ 'class' => StubQueueProducer::class, - '__construct()' => ['name' => Reference::to('producer-name')], + '__construct()' => ['queue' => Reference::to('producer-name')], ], 'consumer' => StubQueueConsumer::class, ], @@ -41,9 +41,9 @@ public function testFactoryRoleMapsResolveThroughContainerAndKeepCapabilitiesSep 'consumer-only' => ['consumer' => StubQueueConsumer::class], ], $container); - self::assertSame(['both', 'producer-only'], $provider->getProducerNames()); - self::assertSame(['both', 'consumer-only'], $provider->getConsumerNames()); - self::assertSame('factory-both', $provider->getProducer('both')->getName()); + self::assertSame(['both', 'producer-only'], $provider->getProducerQueues()); + self::assertSame(['both', 'consumer-only'], $provider->getConsumerQueues()); + self::assertSame('factory-both', $provider->getProducer('both')->getQueue()); self::assertInstanceOf(StubQueueConsumer::class, $provider->getConsumer('both')); self::assertInstanceOf(StubQueueProducer::class, $provider->getProducer('producer-only')); self::assertInstanceOf(StubQueueConsumer::class, $provider->getConsumer('consumer-only')); @@ -64,8 +64,8 @@ public function testPredefinedRoleMapsAndListenCommandUseConsumerOnlyService(): 'consumer-only' => ['consumer' => $consumer], ]); - self::assertSame(['both', 'producer-only'], $provider->getProducerNames()); - self::assertSame(['both', 'consumer-only'], $provider->getConsumerNames()); + self::assertSame(['both', 'producer-only'], $provider->getProducerQueues()); + self::assertSame(['both', 'consumer-only'], $provider->getConsumerQueues()); self::assertInstanceOf(QueueProducerInterface::class, $provider->getProducer('both')); self::assertInstanceOf(QueueConsumerInterface::class, $provider->getConsumer('both')); self::assertFalse($provider->hasConsumer('producer-only')); @@ -98,8 +98,8 @@ public function testDebugProxiesPreserveSeparatedProviderRoles(): void self::assertInstanceOf(QueueProducerDecorator::class, $producer); self::assertInstanceOf(QueueConsumerDecorator::class, $consumer); - self::assertSame(['mixed-name'], $producerProvider->getProducerNames()); - self::assertSame(['consumer-only'], $consumerProvider->getConsumerNames()); + self::assertSame(['mixed-name'], $producerProvider->getProducerQueues()); + self::assertSame(['consumer-only'], $consumerProvider->getConsumerQueues()); self::assertSame(1, $collector->getSummary()['countPushes']); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 8f597663..679a9b7d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -14,7 +14,7 @@ use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\Cli\LoopInterface; use Yiisoft\Queue\Cli\SimpleLoop; -use Yiisoft\Queue\DefaultQueue; +use Yiisoft\Queue\Defaults; use Yiisoft\Queue\Middleware\CallableFactory; use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareDispatcher; use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareFactory; @@ -93,20 +93,20 @@ protected function getContainer(): ContainerInterface protected function createQueue( ?AdapterInterface $adapter = null, - string|BackedEnum $name = DefaultQueue::NAME, + string|BackedEnum $queue = Defaults::QUEUE, ): QueueProducerInterface { return $adapter === null ? new SyncQueueProducer( new NullLogger(), $this->getPushMiddlewareConfig(), $this->getWorker(), - $name, + $queue, ) : new AsyncQueueProducer( new NullLogger(), $this->getPushMiddlewareConfig(), $adapter, - $name, + $queue, ); } diff --git a/tests/Unit/Command/RunCommandTest.php b/tests/Unit/Command/RunCommandTest.php index 133cdd83..f6c2d6e4 100644 --- a/tests/Unit/Command/RunCommandTest.php +++ b/tests/Unit/Command/RunCommandTest.php @@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\OutputInterface; use Yiisoft\Queue\Command\RunCommand; -use Yiisoft\Queue\DefaultQueue; +use Yiisoft\Queue\Defaults; use Yiisoft\Queue\Provider\PredefinedQueueProvider; use Yiisoft\Queue\QueueConsumerInterface; use Yiisoft\Queue\Stubs\StubQueueProducer; @@ -32,7 +32,7 @@ public function testDefaultRunSkipsProducerOnlyQueues(): void $consumer->expects($this->once())->method('run')->willReturn(0); $command = new RunCommand(new PredefinedQueueProvider([ 'producer' => ['producer' => new StubQueueProducer()], - DefaultQueue::NAME => ['consumer' => $consumer], + Defaults::QUEUE => ['consumer' => $consumer], ])); self::assertSame(0, $command->run(new StringInput(''), $this->createMock(OutputInterface::class))); } diff --git a/tests/Unit/Debug/QueueDecoratorTest.php b/tests/Unit/Debug/QueueDecoratorTest.php index c408726d..7a81e86b 100644 --- a/tests/Unit/Debug/QueueDecoratorTest.php +++ b/tests/Unit/Debug/QueueDecoratorTest.php @@ -19,7 +19,7 @@ public function testProducerDecoratorDelegatesAndCollects(): void { $message = new GenericMessage('test', null); $producer = $this->createMock(QueueProducerInterface::class); - $producer->method('getName')->willReturn('queue'); + $producer->method('getQueue')->willReturn('queue'); $producer->expects($this->once())->method('push')->with($message)->willReturn($message); $producer->expects($this->once())->method('status')->with('1')->willReturn(MessageStatus::WAITING); $collector = new QueueCollector(); diff --git a/tests/Unit/Debug/QueueProviderInterfaceProxyTest.php b/tests/Unit/Debug/QueueProviderInterfaceProxyTest.php index cf6325d3..7b1ee308 100644 --- a/tests/Unit/Debug/QueueProviderInterfaceProxyTest.php +++ b/tests/Unit/Debug/QueueProviderInterfaceProxyTest.php @@ -32,10 +32,10 @@ public function testConsumerProxyDelegatesOnlyConsumerRole(): void $provider = $this->createMock(QueueConsumerProviderInterface::class); $provider->method('getConsumer')->willReturn($consumer); $provider->method('hasConsumer')->with('queue')->willReturn(true); - $provider->method('getConsumerNames')->willReturn(['queue']); + $provider->method('getConsumerQueues')->willReturn(['queue']); $proxy = new QueueConsumerProviderProxy($provider, new QueueCollector()); self::assertInstanceOf(QueueConsumerDecorator::class, $proxy->getConsumer('queue')); self::assertTrue($proxy->hasConsumer('queue')); - self::assertSame(['queue'], $proxy->getConsumerNames()); + self::assertSame(['queue'], $proxy->getConsumerQueues()); } } diff --git a/tests/Unit/Middleware/Consume/ConsumeRequestTest.php b/tests/Unit/Middleware/Consume/ConsumeRequestTest.php index 9ee6aae8..33656901 100644 --- a/tests/Unit/Middleware/Consume/ConsumeRequestTest.php +++ b/tests/Unit/Middleware/Consume/ConsumeRequestTest.php @@ -18,6 +18,6 @@ public function testImmutable(): void $consumeRequest = new ConsumeRequest($message, 'test-queue'); $this->assertNotSame($consumeRequest, $consumeRequest->withMessage($message)); - $this->assertNotSame($consumeRequest, $consumeRequest->withQueueName('other-queue')); + $this->assertNotSame($consumeRequest, $consumeRequest->withQueue('other-queue')); } } diff --git a/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php b/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php index e1b0ab71..20e5e0a5 100644 --- a/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php +++ b/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php @@ -28,7 +28,7 @@ public function testCallableMiddlewareCalled(): void $dispatcher = $this->createDispatcher()->withMiddlewares( [ static function (ConsumeRequest $request): ConsumeRequest { - return $request->withMessage(new GenericMessage('test', 'New closure test data'))->withQueueName('other-queue'); + return $request->withMessage(new GenericMessage('test', 'New closure test data'))->withQueue('other-queue'); }, ], ); diff --git a/tests/Unit/Middleware/FailureHandling/FailureHandlingRequestTest.php b/tests/Unit/Middleware/FailureHandling/FailureHandlingRequestTest.php index 5d497272..b9baf6e7 100644 --- a/tests/Unit/Middleware/FailureHandling/FailureHandlingRequestTest.php +++ b/tests/Unit/Middleware/FailureHandling/FailureHandlingRequestTest.php @@ -21,7 +21,7 @@ public function testImmutable(): void 'test-queue', $queue, ); - $request2 = $request1->withQueueName('other-queue'); + $request2 = $request1->withQueue('other-queue'); $request3 = $request1->withException(new Exception('exception 2')); $request4 = $request1->withMessage(new GenericMessage('test2', null)); diff --git a/tests/Unit/Provider/CompositeQueueProviderTest.php b/tests/Unit/Provider/CompositeQueueProviderTest.php index d4526b95..728298b6 100644 --- a/tests/Unit/Provider/CompositeQueueProviderTest.php +++ b/tests/Unit/Provider/CompositeQueueProviderTest.php @@ -22,8 +22,8 @@ public function testCombinesRolesAndPreservesPrecedence(): void ); self::assertSame($firstProducer, $provider->getProducer('queue')); self::assertInstanceOf(StubQueueConsumer::class, $provider->getConsumer('queue')); - self::assertSame(['queue'], $provider->getProducerNames()); - self::assertSame(['queue'], $provider->getConsumerNames()); + self::assertSame(['queue'], $provider->getProducerQueues()); + self::assertSame(['queue'], $provider->getConsumerQueues()); } public function testMissingCapabilityThrows(): void diff --git a/tests/Unit/Provider/PredefinedQueueProviderTest.php b/tests/Unit/Provider/PredefinedQueueProviderTest.php index 982abc27..4fcb50cd 100644 --- a/tests/Unit/Provider/PredefinedQueueProviderTest.php +++ b/tests/Unit/Provider/PredefinedQueueProviderTest.php @@ -22,8 +22,8 @@ public function testProvidesIndependentRoles(): void self::assertSame($producer, $provider->getProducer('queue1')); self::assertSame($consumer, $provider->getConsumer('queue1')); - self::assertSame(['queue1'], $provider->getProducerNames()); - self::assertSame(['queue1'], $provider->getConsumerNames()); + self::assertSame(['queue1'], $provider->getProducerQueues()); + self::assertSame(['queue1'], $provider->getConsumerQueues()); } public function testCapabilityIsolationAndEnumNames(): void diff --git a/tests/Unit/Provider/QueueFactoryProviderTest.php b/tests/Unit/Provider/QueueFactoryProviderTest.php index 902c1053..a6f4b745 100644 --- a/tests/Unit/Provider/QueueFactoryProviderTest.php +++ b/tests/Unit/Provider/QueueFactoryProviderTest.php @@ -20,8 +20,8 @@ public function testLazilyCreatesRolesIndependently(): void self::assertInstanceOf(StubQueueProducer::class, $provider->getProducer('queue')); self::assertSame($provider->getProducer('queue'), $provider->getProducer('queue')); self::assertInstanceOf(StubQueueConsumer::class, $provider->getConsumer('queue')); - self::assertSame(['queue'], $provider->getProducerNames()); - self::assertSame(['queue'], $provider->getConsumerNames()); + self::assertSame(['queue'], $provider->getProducerQueues()); + self::assertSame(['queue'], $provider->getConsumerQueues()); } public function testCapabilityIsolation(): void diff --git a/tests/Unit/QueueTest.php b/tests/Unit/QueueTest.php index cc0a5502..5558dee5 100644 --- a/tests/Unit/QueueTest.php +++ b/tests/Unit/QueueTest.php @@ -69,7 +69,7 @@ public function testSynchronousConsumerIsNoOp(): void public function testProducerNameSupportsEnum(): void { - self::assertSame('high-priority', $this->createQueue(name: TestQueue::HIGH_PRIORITY)->getName()); + self::assertSame('high-priority', $this->createQueue(queue: TestQueue::HIGH_PRIORITY)->getQueue()); } public function testConsumerStopsAtLimit(): void From 2f3cd517159c2b8b62fdfbb9bfcd2e9e23ff45be Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 12 Aug 2026 15:22:32 +0300 Subject: [PATCH 2/2] queue-name --- README.md | 6 +- docs/guide/en/console-commands.md | 12 +-- docs/guide/en/queue-capabilities.md | 2 +- docs/guide/en/queue-names-advanced.md | 8 +- docs/guide/en/queue-names.md | 8 +- docs/guide/en/usage.md | 6 +- src/AsyncQueueProducer.php | 10 +-- src/Command/ListenAllCommand.php | 16 ++-- src/Command/ListenCommand.php | 10 +-- src/Command/RunCommand.php | 18 ++--- src/Debug/QueueCollector.php | 8 +- src/Debug/QueueConsumerProviderProxy.php | 12 +-- src/Debug/QueueProducerDecorator.php | 6 +- src/Debug/QueueProducerProviderProxy.php | 12 +-- src/Debug/QueueWorkerInterfaceProxy.php | 6 +- src/DefaultQueue.php | 13 ++++ src/Defaults.php | 13 ---- src/Middleware/Consume/ConsumeRequest.php | 12 +-- .../FailureHandlingRequest.php | 12 +-- .../FailureMiddlewareDispatcher.php | 14 ++-- .../ExponentialDelayMiddleware.php | 6 +- .../Implementation/SendAgainMiddleware.php | 6 +- .../Push/SynchronousPushHandler.php | 2 +- src/Provider/CompositeQueueProvider.php | 40 +++++----- src/Provider/PredefinedQueueProvider.php | 58 +++++++------- .../QueueConsumerProviderInterface.php | 12 +-- src/Provider/QueueFactoryProvider.php | 78 +++++++++---------- src/Provider/QueueNotFoundException.php | 4 +- .../QueueProducerProviderInterface.php | 12 +-- src/QueueConsumer.php | 8 +- src/QueueProducerInterface.php | 4 +- src/SyncQueueProducer.php | 10 +-- src/Worker/Worker.php | 6 +- src/Worker/WorkerInterface.php | 4 +- stubs/StubQueueProducer.php | 6 +- stubs/StubWorker.php | 2 +- tests/Integration/MiddlewareTest.php | 2 +- tests/Integration/QueueProviderTest.php | 16 ++-- tests/TestCase.php | 8 +- tests/Unit/Command/RunCommandTest.php | 4 +- tests/Unit/Debug/QueueDecoratorTest.php | 2 +- .../Debug/QueueProviderInterfaceProxyTest.php | 4 +- .../Middleware/Consume/ConsumeRequestTest.php | 2 +- .../Consume/MiddlewareDispatcherTest.php | 2 +- .../FailureHandlingRequestTest.php | 2 +- .../Provider/CompositeQueueProviderTest.php | 4 +- .../Provider/PredefinedQueueProviderTest.php | 4 +- .../Provider/QueueFactoryProviderTest.php | 4 +- tests/Unit/QueueTest.php | 2 +- tests/Unit/WorkerTest.php | 38 ++++----- 50 files changed, 278 insertions(+), 278 deletions(-) create mode 100644 src/DefaultQueue.php delete mode 100644 src/Defaults.php diff --git a/README.md b/README.md index 968f0293..836bc494 100644 --- a/README.md +++ b/README.md @@ -160,13 +160,13 @@ By default, Yii Framework uses [yiisoft/yii-console](https://github.com/yiisoft/ ```bash ./yii queue:run # Handle all existing messages in the queue -./yii queue:listen [queue] # Start a daemon listening for new messages permanently from the specified queue -./yii queue:listen-all [queue [queue2 [...]]] # Start a daemon listening for new messages permanently from all consumer-capable queues or specified list of queues (use with caution in production, recommended for dev only) +./yii queue:listen [queueName] # Start a daemon listening for new messages permanently from the specified queue +./yii queue:listen-all [queueName [queueName2 [...]]] # Start a daemon listening for new messages permanently from all consumer-capable queues or specified list of queues (use with caution in production, recommended for dev only) ``` See [Console commands](docs/guide/en/console-commands.md) for more details. -Producers use `Yiisoft\Queue\QueueProducerInterface` (`push()`, `status()`, `getQueue()`); consumers use `Yiisoft\Queue\QueueConsumerInterface` (`run()`, `listen()`). See [capability configuration](docs/guide/en/queue-capabilities.md) for the strict role map used when named queues are configured. +Producers use `Yiisoft\Queue\QueueProducerInterface` (`push()`, `status()`, `getQueueName()`); consumers use `Yiisoft\Queue\QueueConsumerInterface` (`run()`, `listen()`). See [capability configuration](docs/guide/en/queue-capabilities.md) for the strict role map used when named queues are configured. > In case you're running the queue in synchronous mode (no adapter), `queue:listen` logs an info message and exits. The messages are processed immediately when pushed. diff --git a/docs/guide/en/console-commands.md b/docs/guide/en/console-commands.md index 04e49419..9e214e9c 100644 --- a/docs/guide/en/console-commands.md +++ b/docs/guide/en/console-commands.md @@ -6,7 +6,7 @@ If you are using [yiisoft/config](https://github.com/yiisoft/config) and [yiisof If you are using [symfony/console](https://github.com/symfony/console) directly, you should register the commands manually. -> **Note:** `queue:run` and `queue:listen-all` use `QueueConsumerProviderInterface::getConsumerQueues()` when no queue names are passed. Explicitly passed names are resolved with `getConsumer()` and must have a consumer role. +> **Note:** `queue:run` and `queue:listen-all` use `QueueConsumerProviderInterface::getConsumerQueueNames()` when no queue names are passed. Explicitly passed names are resolved with `getConsumer()` and must have a consumer role. In [yiisoft/app](https://github.com/yiisoft/app) the `yii` console binary is provided out of the box. If you are using [yiisoft/yii-console](https://github.com/yiisoft/yii-console) or `symfony/console` without that template, invoke these commands the same way you invoke other console commands in your application. @@ -22,15 +22,15 @@ You can also narrow the scope of processed messages by specifying queue name(s) The full command signature is: ```sh -yii queue:run [queue1 [queue2 [...]]] --limit=100 +yii queue:run [queueName1 [queueName2 [...]]] --limit=100 ``` ## 2. Listen for queued messages and process them continuously -The following command launches a daemon, which infinitely consumes messages from a single queue. This command receives an optional `queue` argument to specify which queue to listen to, defaults to the queue name `yii-queue`. +The following command launches a daemon, which infinitely consumes messages from a single queue. This command receives an optional `queueName` argument to specify which queue to listen to, defaults to the queue name `yii-queue`. ```sh -yii queue:listen [queue] +yii queue:listen [queueName] ``` > **Note:** If the queue is not configured with an adapter (synchronous mode), the command logs an info message and exits gracefully. @@ -39,13 +39,13 @@ yii queue:listen [queue] The following command iterates through multiple queues and is meant to be used in development environment only, as it consumes a lot of CPU for iterating through queues. You can pass to it: -- `queue` argument(s). Specify one or more queue names to process. Messages from other queues will be ignored. Defaults to all registered consumer-capable queue names. +- `queueName` argument(s). Specify one or more queue names to process. Messages from other queues will be ignored. Defaults to all registered consumer-capable queue names. - `--limit` option to limit the number of messages processed before switching to another queue. E.g. you set `--limit` to 500 and right now you have 1000 messages in `queue1`. This command will consume only 500 of them, then it will switch to `queue2` to see if there are any messages there. Defaults to `0` (no limit). - `--pause` option to specify the number of seconds to pause between checking queues when no messages are found. Defaults to `1`. The full command signature is: ```sh -yii queue:listen-all [queue1 [queue2 [...]]] --pause=1 --limit=0 +yii queue:listen-all [queueName1 [queueName2 [...]]] --pause=1 --limit=0 ``` For long-running processes, graceful shutdown is controlled by `LoopInterface`. When `ext-pcntl` is available, diff --git a/docs/guide/en/queue-capabilities.md b/docs/guide/en/queue-capabilities.md index eb86d1b3..085e8b8c 100644 --- a/docs/guide/en/queue-capabilities.md +++ b/docs/guide/en/queue-capabilities.md @@ -2,7 +2,7 @@ A logical queue name can independently expose a producer, a consumer, or both. Inject `QueueProducerInterface` to push/status messages and `QueueConsumerInterface` to run/listen. Console commands use only `QueueConsumerProviderInterface`; retry middleware uses a direct `QueueProducerInterface` or `QueueProducerProviderInterface`. -Named providers use a strict nested role map. `getProducerQueues()` and `getConsumerQueues()` return only names with that role. Role definitions are created lazily and cached per name and role; failed lazy creation is cached and repeated lookups rethrow the same configuration error. +Named providers use a strict nested role map. `getProducerQueueNames()` and `getConsumerQueueNames()` return only names with that role. Role definitions are created lazily and cached per name and role; failed lazy creation is cached and repeated lookups rethrow the same configuration error. ```php use Yiisoft\Queue\QueueConsumer; diff --git a/docs/guide/en/queue-names-advanced.md b/docs/guide/en/queue-names-advanced.md index 10e155e3..a605815f 100644 --- a/docs/guide/en/queue-names-advanced.md +++ b/docs/guide/en/queue-names-advanced.md @@ -8,13 +8,13 @@ Most applications configure names through [`yiisoft/queue.queues`](queue-names.m Providers translate a queue name into the capability the caller needs: -- `QueueProducerProviderInterface::getProducer($name)` returns a `QueueProducerInterface` for pushing messages and obtaining their status. -- `QueueConsumerProviderInterface::getConsumer($name)` returns a `QueueConsumerInterface` for running or listening for messages. -- `hasProducer()` / `hasConsumer()` check whether a name exposes a role. `getProducerQueues()` / `getConsumerQueues()` list names for only that role. +- `QueueProducerProviderInterface::getProducer($queueName)` returns a `QueueProducerInterface` for pushing messages and obtaining their status. +- `QueueConsumerProviderInterface::getConsumer($queueName)` returns a `QueueConsumerInterface` for running or listening for messages. +- `hasProducer()` / `hasConsumer()` check whether a name exposes a role. `getProducerQueueNames()` / `getConsumerQueueNames()` list names for only that role. Both lookup methods accept a string or `BackedEnum`. They throw `QueueNotFoundException` when the name is unknown or does not have the requested role. This separation prevents a producer-only queue from accidentally being used by a worker, and vice versa. -The default name is `Defaults::QUEUE`, whose value is `yii-queue`. +The default name is `DefaultQueue::NAME`, whose value is `yii-queue`. ## Role-map configuration diff --git a/docs/guide/en/queue-names.md b/docs/guide/en/queue-names.md index 3cede7a2..bee1d1bc 100644 --- a/docs/guide/en/queue-names.md +++ b/docs/guide/en/queue-names.md @@ -6,7 +6,7 @@ A *queue name* is a logical identifier for independently configured producer and - Use `QueueProducerProviderInterface` to obtain a named producer with `getProducer()`. - Use `QueueConsumerProviderInterface` to obtain a named consumer with `getConsumer()`; console commands use this provider. -The default name is `Defaults::QUEUE`, whose value is `yii-queue`. +The default name is `DefaultQueue::NAME`, whose value is `yii-queue`. ## When to use named queues @@ -18,7 +18,7 @@ Named queues use a strict role map under `yiisoft/queue.queues`. Each name must ```php use Yiisoft\Queue\Adapter\AdapterInterface; -use Yiisoft\Queue\Defaults; +use Yiisoft\Queue\DefaultQueue; use Yiisoft\Queue\QueueConsumer; use Yiisoft\Queue\AsyncQueueProducer; @@ -26,7 +26,7 @@ return [ 'yiisoft/queue' => [ 'queues' => [ // A queue with both capabilities. - Defaults::QUEUE => [ + DefaultQueue::NAME => [ 'producer' => ['class' => AsyncQueueProducer::class, '__construct()' => ['adapter' => AdapterInterface::class]], 'consumer' => ['class' => QueueConsumer::class, '__construct()' => ['adapter' => AdapterInterface::class]], ], @@ -78,7 +78,7 @@ final readonly class SendTransactionalEmail } ``` -Both typed providers accept strings and `BackedEnum` values. Use `getProducerQueues()` or `getConsumerQueues()` when enumerating only that role. +Both typed providers accept strings and `BackedEnum` values. Use `getProducerQueueNames()` or `getConsumerQueueNames()` when enumerating only that role. ## Running workers diff --git a/docs/guide/en/usage.md b/docs/guide/en/usage.md index 2d64fe6f..ba4de48c 100644 --- a/docs/guide/en/usage.md +++ b/docs/guide/en/usage.md @@ -73,9 +73,9 @@ Most adapters can be consumed using [console commands](./console-commands.md) re If you configured multiple [queue names](./queue-names.md), you can choose which queue to consume with console commands: ```sh -yii queue:listen [queue] -yii queue:run [queue1 [queue2 [...]]] -yii queue:listen-all [queue1 [queue2 [...]]] +yii queue:listen [queueName] +yii queue:run [queueName1 [queueName2 [...]]] +yii queue:listen-all [queueName1 [queueName2 [...]]] ``` diff --git a/src/AsyncQueueProducer.php b/src/AsyncQueueProducer.php index 7158d1eb..7d63c389 100644 --- a/src/AsyncQueueProducer.php +++ b/src/AsyncQueueProducer.php @@ -18,7 +18,7 @@ */ final class AsyncQueueProducer implements QueueProducerInterface { - private string $queue; + private string $queueName; private PushMiddlewareDispatcher $dispatcher; /** @@ -28,10 +28,10 @@ public function __construct( private readonly LoggerInterface $logger, PushMiddlewareConfig $middlewareConfig, private readonly AdapterInterface $adapter, - string|BackedEnum $queue = Defaults::QUEUE, + string|BackedEnum $queueName = DefaultQueue::NAME, array $middlewareDefinitions = [], ) { - $this->queue = StringNormalizer::normalize($queue); + $this->queueName = StringNormalizer::normalize($queueName); $this->dispatcher = new PushMiddlewareDispatcher( middlewareFactory: $middlewareConfig->middlewareFactory, middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions], @@ -39,9 +39,9 @@ public function __construct( ); } - public function getQueue(): string + public function getQueueName(): string { - return $this->queue; + return $this->queueName; } public function push(MessageInterface $message): MessageInterface diff --git a/src/Command/ListenAllCommand.php b/src/Command/ListenAllCommand.php index c1290e19..5ef5d75f 100644 --- a/src/Command/ListenAllCommand.php +++ b/src/Command/ListenAllCommand.php @@ -37,7 +37,7 @@ public function configure(): void $this->addArgument( 'queue', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, - 'Queue list to connect to', + 'Queue name list to connect to', [], ) ->addOption( @@ -61,16 +61,16 @@ public function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - /** @var string[] $queues */ - $queues = $input->getArgument('queue'); - if ($queues === []) { - $queues = $this->queueProvider->getConsumerQueues(); + /** @var string[] $queueNames */ + $queueNames = $input->getArgument('queue'); + if ($queueNames === []) { + $queueNames = $this->queueProvider->getConsumerQueueNames(); } $consumers = []; - /** @var string $queue */ - foreach ($queues as $queue) { - $consumers[] = $this->queueProvider->getConsumer($queue); + /** @var string $queueName */ + foreach ($queueNames as $queueName) { + $consumers[] = $this->queueProvider->getConsumer($queueName); } if ($consumers === []) { diff --git a/src/Command/ListenCommand.php b/src/Command/ListenCommand.php index 7046b906..14b9e04c 100644 --- a/src/Command/ListenCommand.php +++ b/src/Command/ListenCommand.php @@ -9,7 +9,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Yiisoft\Queue\Defaults; +use Yiisoft\Queue\DefaultQueue; use Yiisoft\Queue\Provider\QueueConsumerProviderInterface; #[AsCommand( @@ -29,16 +29,16 @@ public function configure(): void $this->addArgument( 'queue', InputArgument::OPTIONAL, - 'Queue to connect to', - Defaults::QUEUE, + 'Queue name to connect to', + DefaultQueue::NAME, ); } protected function execute(InputInterface $input, OutputInterface $output): int { - $queue = (string) $input->getArgument('queue'); + $queueName = (string) $input->getArgument('queue'); - $this->queueProvider->getConsumer($queue)->listen(); + $this->queueProvider->getConsumer($queueName)->listen(); return Command::SUCCESS; } diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index 70a8e081..c6f9a422 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -29,7 +29,7 @@ public function configure(): void $this->addArgument( 'queue', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, - 'Queue list to connect to.', + 'Queue name list to connect to.', [], ) ->addOption( @@ -44,17 +44,17 @@ public function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - /** @var string[] $queues */ - $queues = $input->getArgument('queue'); - if ($queues === []) { - $queues = $this->queueProvider->getConsumerQueues(); + /** @var string[] $queueNames */ + $queueNames = $input->getArgument('queue'); + if ($queueNames === []) { + $queueNames = $this->queueProvider->getConsumerQueueNames(); } - /** @var string $queue */ - foreach ($queues as $queue) { - $queueConsumer = $this->queueProvider->getConsumer($queue); + /** @var string $queueName */ + foreach ($queueNames as $queueName) { + $queueConsumer = $this->queueProvider->getConsumer($queueName); - $output->write("Processing queue $queue... "); + $output->write("Processing queue $queueName... "); $count = $queueConsumer->run((int) $input->getOption('limit')); $output->writeln("Messages processed: $count."); diff --git a/src/Debug/QueueCollector.php b/src/Debug/QueueCollector.php index 47458a04..92ddba5c 100644 --- a/src/Debug/QueueCollector.php +++ b/src/Debug/QueueCollector.php @@ -52,24 +52,24 @@ public function collectStatus(string $id, MessageStatus $status, string $line): ]; } - public function collectPush(string $queue, MessageInterface $message, string $line): void + public function collectPush(string $queueName, MessageInterface $message, string $line): void { if (!$this->isActive()) { return; } - $this->pushes[$queue][] = [ + $this->pushes[$queueName][] = [ 'message' => $message, 'line' => $line, ]; } - public function collectWorkerProcessing(MessageInterface $message, string $queue): void + public function collectWorkerProcessing(MessageInterface $message, string $queueName): void { if (!$this->isActive()) { return; } - $this->processingMessages[$queue][] = $message; + $this->processingMessages[$queueName][] = $message; } public function getSummary(): array diff --git a/src/Debug/QueueConsumerProviderProxy.php b/src/Debug/QueueConsumerProviderProxy.php index fd970063..ab6a6e28 100644 --- a/src/Debug/QueueConsumerProviderProxy.php +++ b/src/Debug/QueueConsumerProviderProxy.php @@ -12,18 +12,18 @@ final class QueueConsumerProviderProxy implements QueueConsumerProviderInterface { public function __construct(private readonly QueueConsumerProviderInterface $provider, private readonly QueueCollector $collector) {} - public function getConsumer(string|BackedEnum $queue): QueueConsumerInterface + public function getConsumer(string|BackedEnum $queueName): QueueConsumerInterface { - return new QueueConsumerDecorator($this->provider->getConsumer($queue), $this->collector); + return new QueueConsumerDecorator($this->provider->getConsumer($queueName), $this->collector); } - public function hasConsumer(string|BackedEnum $queue): bool + public function hasConsumer(string|BackedEnum $queueName): bool { - return $this->provider->hasConsumer($queue); + return $this->provider->hasConsumer($queueName); } - public function getConsumerQueues(): array + public function getConsumerQueueNames(): array { - return $this->provider->getConsumerQueues(); + return $this->provider->getConsumerQueueNames(); } } diff --git a/src/Debug/QueueProducerDecorator.php b/src/Debug/QueueProducerDecorator.php index e9c19f35..589ba1c1 100644 --- a/src/Debug/QueueProducerDecorator.php +++ b/src/Debug/QueueProducerDecorator.php @@ -22,12 +22,12 @@ public function status(string|int $id): MessageStatus public function push(MessageInterface $message): MessageInterface { /** @psalm-var array{file: string, line: int} $stack */ $stack = debug_backtrace()[0]; $message = $this->queue->push($message); - $this->collector->collectPush($this->queue->getQueue(), $message, $stack['file'] . ':' . $stack['line']); + $this->collector->collectPush($this->queue->getQueueName(), $message, $stack['file'] . ':' . $stack['line']); return $message; } - public function getQueue(): string + public function getQueueName(): string { - return $this->queue->getQueue(); + return $this->queue->getQueueName(); } } diff --git a/src/Debug/QueueProducerProviderProxy.php b/src/Debug/QueueProducerProviderProxy.php index 297e9e32..a71f846a 100644 --- a/src/Debug/QueueProducerProviderProxy.php +++ b/src/Debug/QueueProducerProviderProxy.php @@ -12,18 +12,18 @@ final class QueueProducerProviderProxy implements QueueProducerProviderInterface { public function __construct(private readonly QueueProducerProviderInterface $provider, private readonly QueueCollector $collector) {} - public function getProducer(string|BackedEnum $queue): QueueProducerInterface + public function getProducer(string|BackedEnum $queueName): QueueProducerInterface { - return new QueueProducerDecorator($this->provider->getProducer($queue), $this->collector); + return new QueueProducerDecorator($this->provider->getProducer($queueName), $this->collector); } - public function hasProducer(string|BackedEnum $queue): bool + public function hasProducer(string|BackedEnum $queueName): bool { - return $this->provider->hasProducer($queue); + return $this->provider->hasProducer($queueName); } - public function getProducerQueues(): array + public function getProducerQueueNames(): array { - return $this->provider->getProducerQueues(); + return $this->provider->getProducerQueueNames(); } } diff --git a/src/Debug/QueueWorkerInterfaceProxy.php b/src/Debug/QueueWorkerInterfaceProxy.php index f40dc873..b26c5cd5 100644 --- a/src/Debug/QueueWorkerInterfaceProxy.php +++ b/src/Debug/QueueWorkerInterfaceProxy.php @@ -17,10 +17,10 @@ public function __construct( public function process( MessageInterface $message, - string $queue, + string $queueName, ?QueueProducerInterface $retryProducer = null, ): MessageInterface { - $this->collector->collectWorkerProcessing($message, $queue); - return $this->worker->process($message, $queue, $retryProducer); + $this->collector->collectWorkerProcessing($message, $queueName); + return $this->worker->process($message, $queueName, $retryProducer); } } diff --git a/src/DefaultQueue.php b/src/DefaultQueue.php new file mode 100644 index 00000000..07eb52a1 --- /dev/null +++ b/src/DefaultQueue.php @@ -0,0 +1,13 @@ +message; } - /** Logical queue currently executing this message. */ - public function getQueue(): string + /** Logical name of the queue currently executing this message. */ + public function getQueueName(): string { - return $this->queue; + return $this->queueName; } public function withMessage(MessageInterface $message): self @@ -28,10 +28,10 @@ public function withMessage(MessageInterface $message): self return $instance; } - public function withQueue(string $queue): self + public function withQueueName(string $queueName): self { $instance = clone $this; - $instance->queue = $queue; + $instance->queueName = $queueName; return $instance; } } diff --git a/src/Middleware/FailureHandling/FailureHandlingRequest.php b/src/Middleware/FailureHandling/FailureHandlingRequest.php index 50a5c4c7..03dc9888 100644 --- a/src/Middleware/FailureHandling/FailureHandlingRequest.php +++ b/src/Middleware/FailureHandling/FailureHandlingRequest.php @@ -13,7 +13,7 @@ final class FailureHandlingRequest public function __construct( private MessageInterface $message, private Throwable $exception, - private string $queue, + private string $queueName, private ?QueueProducerInterface $retryProducer = null, ) {} @@ -27,10 +27,10 @@ public function getException(): Throwable return $this->exception; } - /** Logical queue which executed the message. */ - public function getQueue(): string + /** Logical name of the queue which executed the message. */ + public function getQueueName(): string { - return $this->queue; + return $this->queueName; } /** Direct retry target used by synchronous producer execution, if any. */ @@ -53,10 +53,10 @@ public function withException(Throwable $exception): self return $instance; } - public function withQueue(string $queue): self + public function withQueueName(string $queueName): self { $instance = clone $this; - $instance->queue = $queue; + $instance->queueName = $queueName; return $instance; } } diff --git a/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php b/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php index 76225b4b..3647e6ad 100644 --- a/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php +++ b/src/Middleware/FailureHandling/FailureMiddlewareDispatcher.php @@ -37,17 +37,17 @@ public function dispatch( FailureHandlingRequest $request, FailureHandlerInterface $finishHandler, ): FailureHandlingRequest { - $queue = $request->getQueue(); - if (!isset($this->middlewareDefinitions[$queue]) || $this->middlewareDefinitions[$queue] === []) { - $queue = self::DEFAULT_PIPELINE; + $queueName = $request->getQueueName(); + if (!isset($this->middlewareDefinitions[$queueName]) || $this->middlewareDefinitions[$queueName] === []) { + $queueName = self::DEFAULT_PIPELINE; } - $definitions = array_reverse($this->middlewareDefinitions[$queue]); + $definitions = array_reverse($this->middlewareDefinitions[$queueName]); - if (!isset($this->stack[$queue])) { - $this->stack[$queue] = new FailureMiddlewareStack($this->buildMiddlewares(...$definitions), $finishHandler); + if (!isset($this->stack[$queueName])) { + $this->stack[$queueName] = new FailureMiddlewareStack($this->buildMiddlewares(...$definitions), $finishHandler); } - return $this->stack[$queue]->handleFailure($request); + return $this->stack[$queueName]->handleFailure($request); } /** diff --git a/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php b/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php index 40b3bcf0..524461c6 100644 --- a/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php +++ b/src/Middleware/FailureHandling/Implementation/ExponentialDelayMiddleware.php @@ -67,12 +67,12 @@ private function producer(FailureHandlingRequest $request): QueueProducerInterfa return $request->getRetryProducer(); } if ($this->producerProvider === null) { - throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": configure a producer target or QueueProducerProviderInterface.', $request->getQueue())); + throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": configure a producer target or QueueProducerProviderInterface.', $request->getQueueName())); } try { - return $this->producerProvider->getProducer($request->getQueue()); + return $this->producerProvider->getProducer($request->getQueueName()); } catch (Throwable $exception) { - throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": no producer capability is available.', $request->getQueue()), previous: $exception); + throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": no producer capability is available.', $request->getQueueName()), previous: $exception); } } diff --git a/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php b/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php index 0870be80..1de2074d 100644 --- a/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php +++ b/src/Middleware/FailureHandling/Implementation/SendAgainMiddleware.php @@ -48,12 +48,12 @@ public function processFailure(FailureHandlingRequest $request, FailureHandlerIn private function sourceProducer(FailureHandlingRequest $request): QueueProducerInterface { if ($this->producerProvider === null) { - throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": configure a producer target or QueueProducerProviderInterface.', $request->getQueue())); + throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": configure a producer target or QueueProducerProviderInterface.', $request->getQueueName())); } try { - return $this->producerProvider->getProducer($request->getQueue()); + return $this->producerProvider->getProducer($request->getQueueName()); } catch (Throwable $exception) { - throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": no producer capability is available.', $request->getQueue()), previous: $exception); + throw new InvalidQueueConfigException(sprintf('Cannot retry queue "%s": no producer capability is available.', $request->getQueueName()), previous: $exception); } } diff --git a/src/Middleware/Push/SynchronousPushHandler.php b/src/Middleware/Push/SynchronousPushHandler.php index 2b017d41..db7b9cfc 100644 --- a/src/Middleware/Push/SynchronousPushHandler.php +++ b/src/Middleware/Push/SynchronousPushHandler.php @@ -20,7 +20,7 @@ public function __construct( public function handlePush(MessageInterface $message): MessageInterface { - $this->worker->process($message, $this->queue->getQueue(), $this->queue); + $this->worker->process($message, $this->queue->getQueueName(), $this->queue); return $message; } diff --git a/src/Provider/CompositeQueueProvider.php b/src/Provider/CompositeQueueProvider.php index 4f548909..7a7abbe8 100644 --- a/src/Provider/CompositeQueueProvider.php +++ b/src/Provider/CompositeQueueProvider.php @@ -29,65 +29,65 @@ public function __construct(QueueProducerProviderInterface|QueueConsumerProvider } } - public function getProducer(string|BackedEnum $queue): QueueProducerInterface + public function getProducer(string|BackedEnum $queueName): QueueProducerInterface { foreach ($this->producerProviders as $provider) { - if ($provider->hasProducer($queue)) { - return $provider->getProducer($queue); + if ($provider->hasProducer($queueName)) { + return $provider->getProducer($queueName); } } - throw new QueueNotFoundException(StringNormalizer::normalize($queue)); + throw new QueueNotFoundException(StringNormalizer::normalize($queueName)); } - public function hasProducer(string|BackedEnum $queue): bool + public function hasProducer(string|BackedEnum $queueName): bool { foreach ($this->producerProviders as $p) { - if ($p->hasProducer($queue)) { + if ($p->hasProducer($queueName)) { return true; } } return false; } /** @return list */ - public function getProducerQueues(): array + public function getProducerQueueNames(): array { $result = []; foreach ($this->producerProviders as $provider) { - foreach ($provider->getProducerQueues() as $queue) { - if (!in_array($queue, $result, true)) { - $result[] = $queue; + foreach ($provider->getProducerQueueNames() as $queueName) { + if (!in_array($queueName, $result, true)) { + $result[] = $queueName; } } } return $result; } - public function getConsumer(string|BackedEnum $queue): QueueConsumerInterface + public function getConsumer(string|BackedEnum $queueName): QueueConsumerInterface { foreach ($this->consumerProviders as $provider) { - if ($provider->hasConsumer($queue)) { - return $provider->getConsumer($queue); + if ($provider->hasConsumer($queueName)) { + return $provider->getConsumer($queueName); } } - throw new QueueNotFoundException(StringNormalizer::normalize($queue)); + throw new QueueNotFoundException(StringNormalizer::normalize($queueName)); } - public function hasConsumer(string|BackedEnum $queue): bool + public function hasConsumer(string|BackedEnum $queueName): bool { foreach ($this->consumerProviders as $p) { - if ($p->hasConsumer($queue)) { + if ($p->hasConsumer($queueName)) { return true; } } return false; } /** @return list */ - public function getConsumerQueues(): array + public function getConsumerQueueNames(): array { $result = []; foreach ($this->consumerProviders as $provider) { - foreach ($provider->getConsumerQueues() as $queue) { - if (!in_array($queue, $result, true)) { - $result[] = $queue; + foreach ($provider->getConsumerQueueNames() as $queueName) { + if (!in_array($queueName, $result, true)) { + $result[] = $queueName; } } } return $result; diff --git a/src/Provider/PredefinedQueueProvider.php b/src/Provider/PredefinedQueueProvider.php index 0e8bf667..7b3d6df2 100644 --- a/src/Provider/PredefinedQueueProvider.php +++ b/src/Provider/PredefinedQueueProvider.php @@ -24,20 +24,20 @@ final class PredefinedQueueProvider implements QueueProducerProviderInterface, Q /** @var array> */ private array $queues = []; /** @var list */ - private array $producerQueues = []; + private array $producerQueueNames = []; /** @var list */ - private array $consumerQueues = []; + private array $consumerQueueNames = []; /** @param array $queues */ public function __construct(array $queues) { - foreach ($queues as $queue => $roles) { + foreach ($queues as $queueName => $roles) { if (!is_array($roles) || $roles === []) { - throw new InvalidQueueConfigException(sprintf('Queue "%s" must be a non-empty role map containing ready "producer" and/or "consumer" instances.', $queue)); + throw new InvalidQueueConfigException(sprintf('Queue "%s" must be a non-empty role map containing ready "producer" and/or "consumer" instances.', $queueName)); } $unknown = array_diff(array_keys($roles), ['producer', 'consumer']); if ($unknown !== []) { - throw new InvalidQueueConfigException(sprintf('Queue "%s" has unknown role key(s) "%s". Only "producer" and "consumer" are allowed.', $queue, implode('", "', $unknown))); + throw new InvalidQueueConfigException(sprintf('Queue "%s" has unknown role key(s) "%s". Only "producer" and "consumer" are allowed.', $queueName, implode('", "', $unknown))); } foreach ($roles as $role => $instance) { $expected = $role === 'producer' ? QueueProducerInterface::class : QueueConsumerInterface::class; @@ -45,70 +45,70 @@ public function __construct(array $queues) $hint = is_array($instance) || is_string($instance) ? ' Use QueueFactoryProvider for factory definitions.' : ''; throw new InvalidQueueConfigException(sprintf( 'Queue "%s" role "%s" must be a ready instance of "%s"; got "%s" (configuration path queues.%s.%s).%s', - $queue, + $queueName, $role, $expected, get_debug_type($instance), - $queue, + $queueName, $role, $hint, )); } } /** @var array $roles */ - $this->queues[$queue] = $roles; + $this->queues[$queueName] = $roles; if (array_key_exists('producer', $roles)) { - $this->producerQueues[] = $queue; + $this->producerQueueNames[] = $queueName; } if (array_key_exists('consumer', $roles)) { - $this->consumerQueues[] = $queue; + $this->consumerQueueNames[] = $queueName; } } } - public function getProducer(string|BackedEnum $queue): QueueProducerInterface + public function getProducer(string|BackedEnum $queueName): QueueProducerInterface { - $instance = $this->get($queue, 'producer'); + $instance = $this->get($queueName, 'producer'); assert($instance instanceof QueueProducerInterface); return $instance; } - public function hasProducer(string|BackedEnum $queue): bool + public function hasProducer(string|BackedEnum $queueName): bool { - return array_key_exists('producer', $this->queues[StringNormalizer::normalize($queue)] ?? []); + return array_key_exists('producer', $this->queues[StringNormalizer::normalize($queueName)] ?? []); } - public function getProducerQueues(): array + public function getProducerQueueNames(): array { - return $this->producerQueues; + return $this->producerQueueNames; } - public function getConsumer(string|BackedEnum $queue): QueueConsumerInterface + public function getConsumer(string|BackedEnum $queueName): QueueConsumerInterface { - $instance = $this->get($queue, 'consumer'); + $instance = $this->get($queueName, 'consumer'); assert($instance instanceof QueueConsumerInterface); return $instance; } - public function hasConsumer(string|BackedEnum $queue): bool + public function hasConsumer(string|BackedEnum $queueName): bool { - return array_key_exists('consumer', $this->queues[StringNormalizer::normalize($queue)] ?? []); + return array_key_exists('consumer', $this->queues[StringNormalizer::normalize($queueName)] ?? []); } - public function getConsumerQueues(): array + public function getConsumerQueueNames(): array { - return $this->consumerQueues; + return $this->consumerQueueNames; } - private function get(string|BackedEnum $queue, string $role): QueueProducerInterface|QueueConsumerInterface + private function get(string|BackedEnum $queueName, string $role): QueueProducerInterface|QueueConsumerInterface { - $queue = StringNormalizer::normalize($queue); - if (!array_key_exists($queue, $this->queues)) { - throw new QueueNotFoundException($queue); + $queueName = StringNormalizer::normalize($queueName); + if (!array_key_exists($queueName, $this->queues)) { + throw new QueueNotFoundException($queueName); } - if (!array_key_exists($role, $this->queues[$queue])) { - throw new QueueNotFoundException(sprintf('Queue "%s" does not have the "%s" capability.', $queue, $role)); + if (!array_key_exists($role, $this->queues[$queueName])) { + throw new QueueNotFoundException(sprintf('Queue "%s" does not have the "%s" capability.', $queueName, $role)); } - return $this->queues[$queue][$role]; + return $this->queues[$queueName][$role]; } } diff --git a/src/Provider/QueueConsumerProviderInterface.php b/src/Provider/QueueConsumerProviderInterface.php index 1f537fa0..e114f68d 100644 --- a/src/Provider/QueueConsumerProviderInterface.php +++ b/src/Provider/QueueConsumerProviderInterface.php @@ -7,15 +7,15 @@ use BackedEnum; use Yiisoft\Queue\QueueConsumerInterface; -/** Finds consumer capabilities by logical queue. */ +/** Finds consumer capabilities by logical queue name. */ interface QueueConsumerProviderInterface { /** @throws InvalidQueueConfigException|QueueNotFoundException|QueueProviderException */ - public function getConsumer(string|BackedEnum $queue): QueueConsumerInterface; + public function getConsumer(string|BackedEnum $queueName): QueueConsumerInterface; - /** Whether this queue has a configured consumer role. */ - public function hasConsumer(string|BackedEnum $queue): bool; + /** Whether this queue name has a configured consumer role. */ + public function hasConsumer(string|BackedEnum $queueName): bool; - /** @return list Queues which have a configured consumer role. */ - public function getConsumerQueues(): array; + /** @return list Queue names which have a configured consumer role. */ + public function getConsumerQueueNames(): array; } diff --git a/src/Provider/QueueFactoryProvider.php b/src/Provider/QueueFactoryProvider.php index 1e8a4184..5957815a 100644 --- a/src/Provider/QueueFactoryProvider.php +++ b/src/Provider/QueueFactoryProvider.php @@ -29,9 +29,9 @@ final class QueueFactoryProvider implements QueueProducerProviderInterface, Queu /** @var array> */ private array $resolved = []; /** @var list */ - private array $producerQueues = []; + private array $producerQueueNames = []; /** @var list */ - private array $consumerQueues = []; + private array $consumerQueueNames = []; /** @param array $definitions */ public function __construct( @@ -42,98 +42,98 @@ public function __construct( /** @var array> $validatedDefinitions */ $validatedDefinitions = $this->validateRoleMaps($definitions); $this->definitions = $validatedDefinitions; - foreach ($this->definitions as $queue => $roles) { + foreach ($this->definitions as $queueName => $roles) { if (array_key_exists('producer', $roles)) { - $this->producerQueues[] = $queue; + $this->producerQueueNames[] = $queueName; } if (array_key_exists('consumer', $roles)) { - $this->consumerQueues[] = $queue; + $this->consumerQueueNames[] = $queueName; } } } - public function getProducer(string|BackedEnum $queue): QueueProducerInterface + public function getProducer(string|BackedEnum $queueName): QueueProducerInterface { - $producer = $this->get($queue, 'producer', QueueProducerInterface::class); + $producer = $this->get($queueName, 'producer', QueueProducerInterface::class); assert($producer instanceof QueueProducerInterface); return $producer; } - public function hasProducer(string|BackedEnum $queue): bool + public function hasProducer(string|BackedEnum $queueName): bool { - return array_key_exists('producer', $this->definitions[StringNormalizer::normalize($queue)] ?? []); + return array_key_exists('producer', $this->definitions[StringNormalizer::normalize($queueName)] ?? []); } - public function getProducerQueues(): array + public function getProducerQueueNames(): array { - return $this->producerQueues; + return $this->producerQueueNames; } - public function getConsumer(string|BackedEnum $queue): QueueConsumerInterface + public function getConsumer(string|BackedEnum $queueName): QueueConsumerInterface { - $consumer = $this->get($queue, 'consumer', QueueConsumerInterface::class); + $consumer = $this->get($queueName, 'consumer', QueueConsumerInterface::class); assert($consumer instanceof QueueConsumerInterface); return $consumer; } - public function hasConsumer(string|BackedEnum $queue): bool + public function hasConsumer(string|BackedEnum $queueName): bool { - return array_key_exists('consumer', $this->definitions[StringNormalizer::normalize($queue)] ?? []); + return array_key_exists('consumer', $this->definitions[StringNormalizer::normalize($queueName)] ?? []); } - public function getConsumerQueues(): array + public function getConsumerQueueNames(): array { - return $this->consumerQueues; + return $this->consumerQueueNames; } /** @template T of QueueProducerInterface|QueueConsumerInterface @param class-string $expected @return T */ - private function get(string|BackedEnum $queue, string $role, string $expected): QueueProducerInterface|QueueConsumerInterface + private function get(string|BackedEnum $queueName, string $role, string $expected): QueueProducerInterface|QueueConsumerInterface { - $queue = StringNormalizer::normalize($queue); - if (!array_key_exists($queue, $this->definitions)) { - throw new QueueNotFoundException($queue); + $queueName = StringNormalizer::normalize($queueName); + if (!array_key_exists($queueName, $this->definitions)) { + throw new QueueNotFoundException($queueName); } - if (!array_key_exists($role, $this->definitions[$queue])) { - throw new QueueNotFoundException(sprintf('Queue "%s" does not have the "%s" capability.', $queue, $role)); + if (!array_key_exists($role, $this->definitions[$queueName])) { + throw new QueueNotFoundException(sprintf('Queue "%s" does not have the "%s" capability.', $queueName, $role)); } - if (isset($this->resolved[$queue][$role])) { - $result = $this->resolved[$queue][$role]; + if (isset($this->resolved[$queueName][$role])) { + $result = $this->resolved[$queueName][$role]; if ($result instanceof Throwable) { throw $result; } return $result; } try { - $key = $queue . ':' . $role; - $factory = new StrictFactory([$key => $this->definitions[$queue][$role]], $this->container, $this->validate); + $key = $queueName . ':' . $role; + $factory = new StrictFactory([$key => $this->definitions[$queueName][$role]], $this->container, $this->validate); $result = $factory->create($key); if (!$result instanceof $expected) { throw new InvalidQueueConfigException(sprintf( 'Queue "%s" role "%s" must implement "%s"; got "%s" (configuration path queues.%s.%s).', - $queue, + $queueName, $role, $expected, get_debug_type($result), - $queue, + $queueName, $role, )); } assert($result instanceof QueueProducerInterface || $result instanceof QueueConsumerInterface); - $this->resolved[$queue][$role] = $result; + $this->resolved[$queueName][$role] = $result; return $result; } catch (InvalidQueueConfigException $exception) { - $this->resolved[$queue][$role] = $exception; + $this->resolved[$queueName][$role] = $exception; throw $exception; } catch (InvalidConfigException $exception) { $wrapped = new InvalidQueueConfigException(sprintf( 'Invalid queue "%s" role "%s" definition (configuration path queues.%s.%s): %s', - $queue, + $queueName, $role, - $queue, + $queueName, $role, $exception->getMessage(), ), previous: $exception); - $this->resolved[$queue][$role] = $wrapped; + $this->resolved[$queueName][$role] = $wrapped; throw $wrapped; } } @@ -143,20 +143,20 @@ private function validateRoleMaps(array $definitions): array { /** @var array> $result */ $result = []; - foreach ($definitions as $queue => $roles) { + foreach ($definitions as $queueName => $roles) { if (!is_array($roles)) { - throw new InvalidQueueConfigException(sprintf('Queue "%s" must be a role map containing "producer" and/or "consumer"; got "%s".', $queue, get_debug_type($roles))); + throw new InvalidQueueConfigException(sprintf('Queue "%s" must be a role map containing "producer" and/or "consumer"; got "%s".', $queueName, get_debug_type($roles))); } $keys = array_keys($roles); $unknown = array_diff($keys, ['producer', 'consumer']); if ($unknown !== []) { - throw new InvalidQueueConfigException(sprintf('Queue "%s" has unknown role key(s) "%s". Only "producer" and "consumer" are allowed.', $queue, implode('", "', $unknown))); + throw new InvalidQueueConfigException(sprintf('Queue "%s" has unknown role key(s) "%s". Only "producer" and "consumer" are allowed.', $queueName, implode('", "', $unknown))); } if ($roles === []) { - throw new InvalidQueueConfigException(sprintf('Queue "%s" role map must contain "producer" and/or "consumer".', $queue)); + throw new InvalidQueueConfigException(sprintf('Queue "%s" role map must contain "producer" and/or "consumer".', $queueName)); } /** @var array $roles */ - $result[$queue] = $roles; + $result[$queueName] = $roles; } return $result; } diff --git a/src/Provider/QueueNotFoundException.php b/src/Provider/QueueNotFoundException.php index 836481e8..5f36327c 100644 --- a/src/Provider/QueueNotFoundException.php +++ b/src/Provider/QueueNotFoundException.php @@ -16,10 +16,10 @@ */ final class QueueNotFoundException extends LogicException implements QueueProviderException { - public function __construct(string|BackedEnum $queue, int $code = 0, ?Throwable $previous = null) + public function __construct(string|BackedEnum $queueName, int $code = 0, ?Throwable $previous = null) { parent::__construct( - sprintf('Queue "%s" not found.', StringNormalizer::normalize($queue)), + sprintf('Queue "%s" not found.', StringNormalizer::normalize($queueName)), $code, $previous, ); diff --git a/src/Provider/QueueProducerProviderInterface.php b/src/Provider/QueueProducerProviderInterface.php index 069e6735..8d8073ea 100644 --- a/src/Provider/QueueProducerProviderInterface.php +++ b/src/Provider/QueueProducerProviderInterface.php @@ -7,15 +7,15 @@ use BackedEnum; use Yiisoft\Queue\QueueProducerInterface; -/** Finds producer capabilities by logical queue. */ +/** Finds producer capabilities by logical queue name. */ interface QueueProducerProviderInterface { /** @throws InvalidQueueConfigException|QueueNotFoundException|QueueProviderException */ - public function getProducer(string|BackedEnum $queue): QueueProducerInterface; + public function getProducer(string|BackedEnum $queueName): QueueProducerInterface; - /** Whether this queue has a configured producer role. */ - public function hasProducer(string|BackedEnum $queue): bool; + /** Whether this queue name has a configured producer role. */ + public function hasProducer(string|BackedEnum $queueName): bool; - /** @return list Queues which have a configured producer role. */ - public function getProducerQueues(): array; + /** @return list Queue names which have a configured producer role. */ + public function getProducerQueueNames(): array; } diff --git a/src/QueueConsumer.php b/src/QueueConsumer.php index 43bd82c6..ffcfbe7b 100644 --- a/src/QueueConsumer.php +++ b/src/QueueConsumer.php @@ -14,16 +14,16 @@ /** Consumes messages for one logical queue. */ final class QueueConsumer implements QueueConsumerInterface { - private string $queue; + private string $queueName; public function __construct( private readonly WorkerInterface $worker, private readonly LoopInterface $loop, private readonly LoggerInterface $logger, private readonly ?AdapterInterface $adapter = null, - string|BackedEnum $queue = Defaults::QUEUE, + string|BackedEnum $queueName = DefaultQueue::NAME, ) { - $this->queue = StringNormalizer::normalize($queue); + $this->queueName = StringNormalizer::normalize($queueName); } public function run(int $max = 0): int @@ -58,7 +58,7 @@ public function listen(): void private function handle(MessageInterface $message): bool { - $this->worker->process($message, $this->queue); + $this->worker->process($message, $this->queueName); return $this->loop->canContinue(); } } diff --git a/src/QueueProducerInterface.php b/src/QueueProducerInterface.php index 578b11ba..5613b195 100644 --- a/src/QueueProducerInterface.php +++ b/src/QueueProducerInterface.php @@ -15,6 +15,6 @@ public function push(MessageInterface $message): MessageInterface; /** Returns the status of a message ID. */ public function status(string|int $id): MessageStatus; - /** Returns the logical queue. */ - public function getQueue(): string; + /** Returns the logical queue name. */ + public function getQueueName(): string; } diff --git a/src/SyncQueueProducer.php b/src/SyncQueueProducer.php index 475d8cc8..555c21fd 100644 --- a/src/SyncQueueProducer.php +++ b/src/SyncQueueProducer.php @@ -17,7 +17,7 @@ */ final class SyncQueueProducer implements QueueProducerInterface { - private string $queue; + private string $queueName; private PushMiddlewareDispatcher $dispatcher; /** @@ -27,10 +27,10 @@ public function __construct( private readonly LoggerInterface $logger, PushMiddlewareConfig $middlewareConfig, WorkerInterface $worker, - string|BackedEnum $queue = Defaults::QUEUE, + string|BackedEnum $queueName = DefaultQueue::NAME, array $middlewareDefinitions = [], ) { - $this->queue = StringNormalizer::normalize($queue); + $this->queueName = StringNormalizer::normalize($queueName); $this->dispatcher = new PushMiddlewareDispatcher( middlewareFactory: $middlewareConfig->middlewareFactory, middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions], @@ -38,9 +38,9 @@ public function __construct( ); } - public function getQueue(): string + public function getQueueName(): string { - return $this->queue; + return $this->queueName; } public function push(MessageInterface $message): MessageInterface diff --git a/src/Worker/Worker.php b/src/Worker/Worker.php index 95094467..65f7c8b9 100644 --- a/src/Worker/Worker.php +++ b/src/Worker/Worker.php @@ -51,7 +51,7 @@ public function __construct( */ public function process( MessageInterface $message, - string $queue, + string $queueName, ?QueueProducerInterface $retryProducer = null, ): MessageInterface { $messageId = IdEnvelope::fromMessage($message)->getId(); @@ -72,12 +72,12 @@ public function process( throw new RuntimeException(sprintf('Queue handler for message type "%s" does not exist.', $messageType)); } - $request = new ConsumeRequest($message, $queue); + $request = new ConsumeRequest($message, $queueName); $closure = fn(MessageInterface $message): mixed => $this->injector->invoke($handler, [$message]); try { return $this->consumeMiddlewareDispatcher->dispatch($request, $this->createConsumeHandler($closure))->getMessage(); } catch (Throwable $exception) { - $request = new FailureHandlingRequest($request->getMessage(), $exception, $request->getQueue(), $retryProducer); + $request = new FailureHandlingRequest($request->getMessage(), $exception, $request->getQueueName(), $retryProducer); try { $result = $this->failureMiddlewareDispatcher->dispatch($request, $this->createFailureHandler()); diff --git a/src/Worker/WorkerInterface.php b/src/Worker/WorkerInterface.php index eb71528e..08ca5849 100644 --- a/src/Worker/WorkerInterface.php +++ b/src/Worker/WorkerInterface.php @@ -9,10 +9,10 @@ interface WorkerInterface { - /** @param string $queue Logical execution queue. */ + /** @param string $queueName Logical execution queue name. */ public function process( MessageInterface $message, - string $queue, + string $queueName, ?QueueProducerInterface $retryProducer = null, ): MessageInterface; } diff --git a/stubs/StubQueueProducer.php b/stubs/StubQueueProducer.php index fab64363..4525747b 100644 --- a/stubs/StubQueueProducer.php +++ b/stubs/StubQueueProducer.php @@ -10,7 +10,7 @@ final class StubQueueProducer implements QueueProducerInterface { - public function __construct(private string $queue = 'default') {} + public function __construct(private string $queueName = 'default') {} public function push(MessageInterface $message): MessageInterface { @@ -22,8 +22,8 @@ public function status(string|int $id): MessageStatus return MessageStatus::DONE; } - public function getQueue(): string + public function getQueueName(): string { - return $this->queue; + return $this->queueName; } } diff --git a/stubs/StubWorker.php b/stubs/StubWorker.php index 11bf658d..9e8bec68 100644 --- a/stubs/StubWorker.php +++ b/stubs/StubWorker.php @@ -15,7 +15,7 @@ final class StubWorker implements WorkerInterface { public function process( MessageInterface $message, - string $queue, + string $queueName, ?QueueProducerInterface $retryProducer = null, ): MessageInterface { return $message; diff --git a/tests/Integration/MiddlewareTest.php b/tests/Integration/MiddlewareTest.php index 6dc2363d..9118d0e5 100644 --- a/tests/Integration/MiddlewareTest.php +++ b/tests/Integration/MiddlewareTest.php @@ -131,7 +131,7 @@ public function testFullStackFailure(): void $callableFactory = new CallableFactory($container); $queue->expects(self::exactly(7))->method('push')->willReturnCallback($queueCallback); - $queue->method('getQueue')->willReturn('simple'); + $queue->method('getQueueName')->willReturn('simple'); $middlewares = [ 'test-queue' => [ diff --git a/tests/Integration/QueueProviderTest.php b/tests/Integration/QueueProviderTest.php index 3d5e3fd2..cd9e5e31 100644 --- a/tests/Integration/QueueProviderTest.php +++ b/tests/Integration/QueueProviderTest.php @@ -33,7 +33,7 @@ public function testFactoryRoleMapsResolveThroughContainerAndKeepCapabilitiesSep 'both' => [ 'producer' => [ 'class' => StubQueueProducer::class, - '__construct()' => ['queue' => Reference::to('producer-name')], + '__construct()' => ['queueName' => Reference::to('producer-name')], ], 'consumer' => StubQueueConsumer::class, ], @@ -41,9 +41,9 @@ public function testFactoryRoleMapsResolveThroughContainerAndKeepCapabilitiesSep 'consumer-only' => ['consumer' => StubQueueConsumer::class], ], $container); - self::assertSame(['both', 'producer-only'], $provider->getProducerQueues()); - self::assertSame(['both', 'consumer-only'], $provider->getConsumerQueues()); - self::assertSame('factory-both', $provider->getProducer('both')->getQueue()); + self::assertSame(['both', 'producer-only'], $provider->getProducerQueueNames()); + self::assertSame(['both', 'consumer-only'], $provider->getConsumerQueueNames()); + self::assertSame('factory-both', $provider->getProducer('both')->getQueueName()); self::assertInstanceOf(StubQueueConsumer::class, $provider->getConsumer('both')); self::assertInstanceOf(StubQueueProducer::class, $provider->getProducer('producer-only')); self::assertInstanceOf(StubQueueConsumer::class, $provider->getConsumer('consumer-only')); @@ -64,8 +64,8 @@ public function testPredefinedRoleMapsAndListenCommandUseConsumerOnlyService(): 'consumer-only' => ['consumer' => $consumer], ]); - self::assertSame(['both', 'producer-only'], $provider->getProducerQueues()); - self::assertSame(['both', 'consumer-only'], $provider->getConsumerQueues()); + self::assertSame(['both', 'producer-only'], $provider->getProducerQueueNames()); + self::assertSame(['both', 'consumer-only'], $provider->getConsumerQueueNames()); self::assertInstanceOf(QueueProducerInterface::class, $provider->getProducer('both')); self::assertInstanceOf(QueueConsumerInterface::class, $provider->getConsumer('both')); self::assertFalse($provider->hasConsumer('producer-only')); @@ -98,8 +98,8 @@ public function testDebugProxiesPreserveSeparatedProviderRoles(): void self::assertInstanceOf(QueueProducerDecorator::class, $producer); self::assertInstanceOf(QueueConsumerDecorator::class, $consumer); - self::assertSame(['mixed-name'], $producerProvider->getProducerQueues()); - self::assertSame(['consumer-only'], $consumerProvider->getConsumerQueues()); + self::assertSame(['mixed-name'], $producerProvider->getProducerQueueNames()); + self::assertSame(['consumer-only'], $consumerProvider->getConsumerQueueNames()); self::assertSame(1, $collector->getSummary()['countPushes']); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 679a9b7d..5ed6f752 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -14,7 +14,7 @@ use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\Cli\LoopInterface; use Yiisoft\Queue\Cli\SimpleLoop; -use Yiisoft\Queue\Defaults; +use Yiisoft\Queue\DefaultQueue; use Yiisoft\Queue\Middleware\CallableFactory; use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareDispatcher; use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareFactory; @@ -93,20 +93,20 @@ protected function getContainer(): ContainerInterface protected function createQueue( ?AdapterInterface $adapter = null, - string|BackedEnum $queue = Defaults::QUEUE, + string|BackedEnum $queueName = DefaultQueue::NAME, ): QueueProducerInterface { return $adapter === null ? new SyncQueueProducer( new NullLogger(), $this->getPushMiddlewareConfig(), $this->getWorker(), - $queue, + $queueName, ) : new AsyncQueueProducer( new NullLogger(), $this->getPushMiddlewareConfig(), $adapter, - $queue, + $queueName, ); } diff --git a/tests/Unit/Command/RunCommandTest.php b/tests/Unit/Command/RunCommandTest.php index f6c2d6e4..133cdd83 100644 --- a/tests/Unit/Command/RunCommandTest.php +++ b/tests/Unit/Command/RunCommandTest.php @@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\OutputInterface; use Yiisoft\Queue\Command\RunCommand; -use Yiisoft\Queue\Defaults; +use Yiisoft\Queue\DefaultQueue; use Yiisoft\Queue\Provider\PredefinedQueueProvider; use Yiisoft\Queue\QueueConsumerInterface; use Yiisoft\Queue\Stubs\StubQueueProducer; @@ -32,7 +32,7 @@ public function testDefaultRunSkipsProducerOnlyQueues(): void $consumer->expects($this->once())->method('run')->willReturn(0); $command = new RunCommand(new PredefinedQueueProvider([ 'producer' => ['producer' => new StubQueueProducer()], - Defaults::QUEUE => ['consumer' => $consumer], + DefaultQueue::NAME => ['consumer' => $consumer], ])); self::assertSame(0, $command->run(new StringInput(''), $this->createMock(OutputInterface::class))); } diff --git a/tests/Unit/Debug/QueueDecoratorTest.php b/tests/Unit/Debug/QueueDecoratorTest.php index 7a81e86b..48913476 100644 --- a/tests/Unit/Debug/QueueDecoratorTest.php +++ b/tests/Unit/Debug/QueueDecoratorTest.php @@ -19,7 +19,7 @@ public function testProducerDecoratorDelegatesAndCollects(): void { $message = new GenericMessage('test', null); $producer = $this->createMock(QueueProducerInterface::class); - $producer->method('getQueue')->willReturn('queue'); + $producer->method('getQueueName')->willReturn('queue'); $producer->expects($this->once())->method('push')->with($message)->willReturn($message); $producer->expects($this->once())->method('status')->with('1')->willReturn(MessageStatus::WAITING); $collector = new QueueCollector(); diff --git a/tests/Unit/Debug/QueueProviderInterfaceProxyTest.php b/tests/Unit/Debug/QueueProviderInterfaceProxyTest.php index 7b1ee308..f9e5fc48 100644 --- a/tests/Unit/Debug/QueueProviderInterfaceProxyTest.php +++ b/tests/Unit/Debug/QueueProviderInterfaceProxyTest.php @@ -32,10 +32,10 @@ public function testConsumerProxyDelegatesOnlyConsumerRole(): void $provider = $this->createMock(QueueConsumerProviderInterface::class); $provider->method('getConsumer')->willReturn($consumer); $provider->method('hasConsumer')->with('queue')->willReturn(true); - $provider->method('getConsumerQueues')->willReturn(['queue']); + $provider->method('getConsumerQueueNames')->willReturn(['queue']); $proxy = new QueueConsumerProviderProxy($provider, new QueueCollector()); self::assertInstanceOf(QueueConsumerDecorator::class, $proxy->getConsumer('queue')); self::assertTrue($proxy->hasConsumer('queue')); - self::assertSame(['queue'], $proxy->getConsumerQueues()); + self::assertSame(['queue'], $proxy->getConsumerQueueNames()); } } diff --git a/tests/Unit/Middleware/Consume/ConsumeRequestTest.php b/tests/Unit/Middleware/Consume/ConsumeRequestTest.php index 33656901..9ee6aae8 100644 --- a/tests/Unit/Middleware/Consume/ConsumeRequestTest.php +++ b/tests/Unit/Middleware/Consume/ConsumeRequestTest.php @@ -18,6 +18,6 @@ public function testImmutable(): void $consumeRequest = new ConsumeRequest($message, 'test-queue'); $this->assertNotSame($consumeRequest, $consumeRequest->withMessage($message)); - $this->assertNotSame($consumeRequest, $consumeRequest->withQueue('other-queue')); + $this->assertNotSame($consumeRequest, $consumeRequest->withQueueName('other-queue')); } } diff --git a/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php b/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php index 20e5e0a5..e1b0ab71 100644 --- a/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php +++ b/tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php @@ -28,7 +28,7 @@ public function testCallableMiddlewareCalled(): void $dispatcher = $this->createDispatcher()->withMiddlewares( [ static function (ConsumeRequest $request): ConsumeRequest { - return $request->withMessage(new GenericMessage('test', 'New closure test data'))->withQueue('other-queue'); + return $request->withMessage(new GenericMessage('test', 'New closure test data'))->withQueueName('other-queue'); }, ], ); diff --git a/tests/Unit/Middleware/FailureHandling/FailureHandlingRequestTest.php b/tests/Unit/Middleware/FailureHandling/FailureHandlingRequestTest.php index b9baf6e7..5d497272 100644 --- a/tests/Unit/Middleware/FailureHandling/FailureHandlingRequestTest.php +++ b/tests/Unit/Middleware/FailureHandling/FailureHandlingRequestTest.php @@ -21,7 +21,7 @@ public function testImmutable(): void 'test-queue', $queue, ); - $request2 = $request1->withQueue('other-queue'); + $request2 = $request1->withQueueName('other-queue'); $request3 = $request1->withException(new Exception('exception 2')); $request4 = $request1->withMessage(new GenericMessage('test2', null)); diff --git a/tests/Unit/Provider/CompositeQueueProviderTest.php b/tests/Unit/Provider/CompositeQueueProviderTest.php index 728298b6..2a1a2db1 100644 --- a/tests/Unit/Provider/CompositeQueueProviderTest.php +++ b/tests/Unit/Provider/CompositeQueueProviderTest.php @@ -22,8 +22,8 @@ public function testCombinesRolesAndPreservesPrecedence(): void ); self::assertSame($firstProducer, $provider->getProducer('queue')); self::assertInstanceOf(StubQueueConsumer::class, $provider->getConsumer('queue')); - self::assertSame(['queue'], $provider->getProducerQueues()); - self::assertSame(['queue'], $provider->getConsumerQueues()); + self::assertSame(['queue'], $provider->getProducerQueueNames()); + self::assertSame(['queue'], $provider->getConsumerQueueNames()); } public function testMissingCapabilityThrows(): void diff --git a/tests/Unit/Provider/PredefinedQueueProviderTest.php b/tests/Unit/Provider/PredefinedQueueProviderTest.php index 4fcb50cd..bf751209 100644 --- a/tests/Unit/Provider/PredefinedQueueProviderTest.php +++ b/tests/Unit/Provider/PredefinedQueueProviderTest.php @@ -22,8 +22,8 @@ public function testProvidesIndependentRoles(): void self::assertSame($producer, $provider->getProducer('queue1')); self::assertSame($consumer, $provider->getConsumer('queue1')); - self::assertSame(['queue1'], $provider->getProducerQueues()); - self::assertSame(['queue1'], $provider->getConsumerQueues()); + self::assertSame(['queue1'], $provider->getProducerQueueNames()); + self::assertSame(['queue1'], $provider->getConsumerQueueNames()); } public function testCapabilityIsolationAndEnumNames(): void diff --git a/tests/Unit/Provider/QueueFactoryProviderTest.php b/tests/Unit/Provider/QueueFactoryProviderTest.php index a6f4b745..51f2a826 100644 --- a/tests/Unit/Provider/QueueFactoryProviderTest.php +++ b/tests/Unit/Provider/QueueFactoryProviderTest.php @@ -20,8 +20,8 @@ public function testLazilyCreatesRolesIndependently(): void self::assertInstanceOf(StubQueueProducer::class, $provider->getProducer('queue')); self::assertSame($provider->getProducer('queue'), $provider->getProducer('queue')); self::assertInstanceOf(StubQueueConsumer::class, $provider->getConsumer('queue')); - self::assertSame(['queue'], $provider->getProducerQueues()); - self::assertSame(['queue'], $provider->getConsumerQueues()); + self::assertSame(['queue'], $provider->getProducerQueueNames()); + self::assertSame(['queue'], $provider->getConsumerQueueNames()); } public function testCapabilityIsolation(): void diff --git a/tests/Unit/QueueTest.php b/tests/Unit/QueueTest.php index 5558dee5..4923edca 100644 --- a/tests/Unit/QueueTest.php +++ b/tests/Unit/QueueTest.php @@ -69,7 +69,7 @@ public function testSynchronousConsumerIsNoOp(): void public function testProducerNameSupportsEnum(): void { - self::assertSame('high-priority', $this->createQueue(queue: TestQueue::HIGH_PRIORITY)->getQueue()); + self::assertSame('high-priority', $this->createQueue(queueName: TestQueue::HIGH_PRIORITY)->getQueueName()); } public function testConsumerStopsAtLimit(): void diff --git a/tests/Unit/WorkerTest.php b/tests/Unit/WorkerTest.php index 786f7577..6840f828 100644 --- a/tests/Unit/WorkerTest.php +++ b/tests/Unit/WorkerTest.php @@ -39,10 +39,10 @@ public function testMessageHandled(mixed $handler, array $containerServices): vo $container = new SimpleContainer($containerServices); $handlers = ['simple' => $handler]; - $queue = 'test-queue'; + $queueName = 'test-queue'; $worker = $this->createWorkerByParams($handlers, $container, $logger); - $worker->process($message, $queue); + $worker->process($message, $queueName); $processedMessages = FakeHandler::$processedMessages; FakeHandler::$processedMessages = []; @@ -93,10 +93,10 @@ public function testMessageFailWithDefinitionUndefinedMethodHandler(): void $container = new SimpleContainer([FakeHandler::class => $handler]); $handlers = ['simple' => [FakeHandler::class, 'undefinedMethod']]; - $queue = 'test-queue'; + $queueName = 'test-queue'; $worker = $this->createWorkerByParams($handlers, $container); - $worker->process($message, $queue); + $worker->process($message, $queueName); } public function testMessageFailWithDefinitionUndefinedClassHandler(): void @@ -109,10 +109,10 @@ public function testMessageFailWithDefinitionUndefinedClassHandler(): void $container = new SimpleContainer([FakeHandler::class => $handler]); $handlers = ['simple' => ['UndefinedClass', 'handle']]; - $queue = 'test-queue'; + $queueName = 'test-queue'; $worker = $this->createWorkerByParams($handlers, $container, $logger); - $worker->process($message, $queue); + $worker->process($message, $queueName); } public function testMessageFailWithDefinitionClassNotFoundInContainerHandler(): void @@ -122,10 +122,10 @@ public function testMessageFailWithDefinitionClassNotFoundInContainerHandler(): $container = new SimpleContainer(); $handlers = ['simple' => [FakeHandler::class, 'handle']]; - $queue = 'test-queue'; + $queueName = 'test-queue'; $worker = $this->createWorkerByParams($handlers, $container); - $worker->process($message, $queue); + $worker->process($message, $queueName); } public function testMessageFailWithDefinitionHandlerException(): void @@ -136,11 +136,11 @@ public function testMessageFailWithDefinitionHandlerException(): void $container = new SimpleContainer([FakeHandler::class => $handler]); $handlers = ['simple' => [FakeHandler::class, 'handleWithException']]; - $queue = 'test-queue'; + $queueName = 'test-queue'; $worker = $this->createWorkerByParams($handlers, $container, $logger); try { - $worker->process($message, $queue); + $worker->process($message, $queueName); } catch (MessageFailureException $exception) { self::assertSame($exception::class, MessageFailureException::class); self::assertSame($exception->getMessage(), "Processing of message without ID is stopped because of an exception:\nTest exception."); @@ -161,12 +161,12 @@ public function testHandlerNotFoundInContainer(): void $container = new SimpleContainer(); $handlers = []; - $queue = 'test-queue'; + $queueName = 'test-queue'; $worker = $this->createWorkerByParams($handlers, $container); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Queue handler for message type "nonexistent" does not exist'); - $worker->process($message, $queue); + $worker->process($message, $queueName); } public function testHandlerInContainerNotImplementingInterface(): void @@ -179,18 +179,18 @@ public function handle(): void {} ]); $handlers = []; - $queue = 'test-queue'; + $queueName = 'test-queue'; $worker = $this->createWorkerByParams($handlers, $container); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Queue handler for message type "invalid" does not exist'); - $worker->process($message, $queue); + $worker->process($message, $queueName); } public function testMessageFailureIsHandledSuccessfully(): void { $message = new GenericMessage('simple', null); - $queue = 'test-queue'; + $queueName = 'test-queue'; $originalException = new RuntimeException('Consume failed'); /** @var ConsumeMiddlewareInterface&MockObject $consumeMiddleware */ @@ -205,7 +205,7 @@ public function testMessageFailureIsHandledSuccessfully(): void $finalMessage = new GenericMessage('final', null); /** @var FailureMiddlewareInterface&MockObject $failureMiddleware */ $failureMiddleware = $this->createMock(FailureMiddlewareInterface::class); - $failureMiddleware->method('processFailure')->willReturn(new FailureHandlingRequest($finalMessage, $originalException, $queue)); + $failureMiddleware->method('processFailure')->willReturn(new FailureHandlingRequest($finalMessage, $originalException, $queueName)); /** @var FailureMiddlewareFactoryInterface&MockObject $failureMiddlewareFactory */ $failureMiddlewareFactory = $this->createMock(FailureMiddlewareFactoryInterface::class); @@ -223,7 +223,7 @@ public function testMessageFailureIsHandledSuccessfully(): void new CallableFactory($container), ); - $result = $worker->process($message, $queue); + $result = $worker->process($message, $queueName); self::assertSame($finalMessage, $result); } @@ -236,11 +236,11 @@ public function testStaticMethodHandler(): void 'static-handler' => StaticMessageHandler::handle(...), ]; - $queue = 'test-queue'; + $queueName = 'test-queue'; $worker = $this->createWorkerByParams($handlers, $container); StaticMessageHandler::$wasHandled = false; - $worker->process($message, $queue); + $worker->process($message, $queueName); $this->assertTrue(StaticMessageHandler::$wasHandled); }