Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
secrets:
codecovToken: ${{ secrets.CODECOV_TOKEN }}
with:
ini-values: pcov.directory=$GITHUB_WORKSPACE, pcov.exclude=#^(?!($GITHUB_WORKSPACE/config/|$GITHUB_WORKSPACE/src/)).*#
ini-values: pcov.directory=%GITHUB_WORKSPACE%, pcov.exclude=#^(?!(%GITHUB_WORKSPACE%/config/|%GITHUB_WORKSPACE%/src/)).*#
os: >-
['ubuntu-latest']
php: >-
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/en/queue-names-advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Providers translate a queue name into the capability the caller needs:

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 `QueueProducerProviderInterface::DEFAULT_QUEUE` (also available from `QueueConsumerProviderInterface`), whose value is `yii-queue`.
The default name is `DefaultQueue::NAME`, whose value is `yii-queue`.

## Role-map configuration

Expand Down
6 changes: 3 additions & 3 deletions docs/guide/en/queue-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `QueueProducerProviderInterface::DEFAULT_QUEUE` (also available from `QueueConsumerProviderInterface`) and is `yii-queue`.
The default name is `DefaultQueue::NAME`, whose value is `yii-queue`.

## When to use named queues

Expand All @@ -18,15 +18,15 @@ Named queues use a strict role map under `yiisoft/queue.queues`. Each name must

```php
use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\Provider\QueueProducerProviderInterface;
use Yiisoft\Queue\DefaultQueue;
use Yiisoft\Queue\QueueConsumer;
use Yiisoft\Queue\AsyncQueueProducer;

return [
'yiisoft/queue' => [
'queues' => [
// A queue with both capabilities.
QueueProducerProviderInterface::DEFAULT_QUEUE => [
DefaultQueue::NAME => [
'producer' => ['class' => AsyncQueueProducer::class, '__construct()' => ['adapter' => AdapterInterface::class]],
'consumer' => ['class' => QueueConsumer::class, '__construct()' => ['adapter' => AdapterInterface::class]],
],
Expand Down
3 changes: 1 addition & 2 deletions src/AsyncQueueProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Yiisoft\Queue\Middleware\Push\AdapterPushHandler;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareConfig;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareDispatcher;
use Yiisoft\Queue\Provider\QueueProducerProviderInterface;

/**
* Produces messages for one logical queue, pushing them to an adapter-backed broker.
Expand All @@ -29,13 +28,13 @@
private readonly LoggerInterface $logger,
PushMiddlewareConfig $middlewareConfig,
private readonly AdapterInterface $adapter,
string|BackedEnum $name = QueueProducerProviderInterface::DEFAULT_QUEUE,
string|BackedEnum $name = DefaultQueue::NAME,
array $middlewareDefinitions = [],
) {
$this->name = StringNormalizer::normalize($name);
$this->dispatcher = new PushMiddlewareDispatcher(
middlewareFactory: $middlewareConfig->middlewareFactory,
middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions],

Check warning on line 37 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ $this->name = StringNormalizer::normalize($name); $this->dispatcher = new PushMiddlewareDispatcher( middlewareFactory: $middlewareConfig->middlewareFactory, - middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions], + middlewareDefinitions: [...$middlewareDefinitions], finishHandler: new AdapterPushHandler($adapter), ); }
finishHandler: new AdapterPushHandler($adapter),
);
}
Expand All @@ -47,17 +46,17 @@

public function push(MessageInterface $message): MessageInterface
{
$this->logger->debug(

Check warning on line 49 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ public function push(MessageInterface $message): MessageInterface { - $this->logger->debug( - 'Preparing to push message with message type "{messageType}".', - ['messageType' => $message->getType()], - ); + $message = $this->dispatcher->dispatch($message); $id = IdEnvelope::fromMessage($message)->getId(); $this->logger->info(
'Preparing to push message with message type "{messageType}".',
['messageType' => $message->getType()],

Check warning on line 51 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ { $this->logger->debug( 'Preparing to push message with message type "{messageType}".', - ['messageType' => $message->getType()], + [], ); $message = $this->dispatcher->dispatch($message); $id = IdEnvelope::fromMessage($message)->getId();

Check warning on line 51 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItem": @@ @@ { $this->logger->debug( 'Preparing to push message with message type "{messageType}".', - ['messageType' => $message->getType()], + ['messageType' > $message->getType()], ); $message = $this->dispatcher->dispatch($message); $id = IdEnvelope::fromMessage($message)->getId();
);
$message = $this->dispatcher->dispatch($message);
$id = IdEnvelope::fromMessage($message)->getId();
$this->logger->info(

Check warning on line 55 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ ); $message = $this->dispatcher->dispatch($message); $id = IdEnvelope::fromMessage($message)->getId(); - $this->logger->info( - $id === null - ? 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.' - : 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.', - ['messageType' => $message->getType(), 'id' => $id], - ); + return $message; }
$id === null

Check warning on line 56 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Ternary": @@ @@ $message = $this->dispatcher->dispatch($message); $id = IdEnvelope::fromMessage($message)->getId(); $this->logger->info( - $id === null - ? 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.' - : 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.', + $id === null ? 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.' : 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.', ['messageType' => $message->getType(), 'id' => $id], ); return $message;
? 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.'
: 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.',
['messageType' => $message->getType(), 'id' => $id],

Check warning on line 59 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ $id === null ? 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.' : 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.', - ['messageType' => $message->getType(), 'id' => $id], + ['id' => $id], ); return $message; }

Check warning on line 59 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItem": @@ @@ $id === null ? 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.' : 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.', - ['messageType' => $message->getType(), 'id' => $id], + ['messageType' > $message->getType(), 'id' => $id], ); return $message; }
);
return $message;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Command/ListenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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\Provider\QueueConsumerProviderInterface;

#[AsCommand(
Expand All @@ -29,7 +30,7 @@ public function configure(): void
'queue',
InputArgument::OPTIONAL,
'Queue name to connect to',
QueueConsumerProviderInterface::DEFAULT_QUEUE,
DefaultQueue::NAME,
);
}

Expand Down
13 changes: 13 additions & 0 deletions src/DefaultQueue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Queue;

/**
* Holds the default logical queue name.
*/
final class DefaultQueue
{
public const NAME = 'yii-queue';
}
2 changes: 1 addition & 1 deletion src/Provider/QueueConsumerProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Yiisoft\Queue\QueueConsumerInterface;

/** Finds consumer capabilities by logical queue name. */
interface QueueConsumerProviderInterface extends QueueProviderDefaults
interface QueueConsumerProviderInterface
{
/** @throws InvalidQueueConfigException|QueueNotFoundException|QueueProviderException */
public function getConsumer(string|BackedEnum $name): QueueConsumerInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/QueueProducerProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Yiisoft\Queue\QueueProducerInterface;

/** Finds producer capabilities by logical queue name. */
interface QueueProducerProviderInterface extends QueueProviderDefaults
interface QueueProducerProviderInterface
{
/** @throws InvalidQueueConfigException|QueueNotFoundException|QueueProviderException */
public function getProducer(string|BackedEnum $name): QueueProducerInterface;
Expand Down
11 changes: 0 additions & 11 deletions src/Provider/QueueProviderDefaults.php

This file was deleted.

3 changes: 1 addition & 2 deletions src/QueueConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\Cli\LoopInterface;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Provider\QueueConsumerProviderInterface;
use Yiisoft\Queue\Worker\WorkerInterface;

/** Consumes messages for one logical queue. */
Expand All @@ -22,7 +21,7 @@ public function __construct(
private readonly LoopInterface $loop,
private readonly LoggerInterface $logger,
private readonly ?AdapterInterface $adapter = null,
string|BackedEnum $name = QueueConsumerProviderInterface::DEFAULT_QUEUE,
string|BackedEnum $name = DefaultQueue::NAME,
) {
$this->name = StringNormalizer::normalize($name);
}
Expand Down
3 changes: 1 addition & 2 deletions src/SyncQueueProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Yiisoft\Queue\Middleware\Push\PushMiddlewareConfig;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareDispatcher;
use Yiisoft\Queue\Middleware\Push\SynchronousPushHandler;
use Yiisoft\Queue\Provider\QueueProducerProviderInterface;
use Yiisoft\Queue\Worker\WorkerInterface;

/**
Expand All @@ -28,7 +27,7 @@ public function __construct(
private readonly LoggerInterface $logger,
PushMiddlewareConfig $middlewareConfig,
WorkerInterface $worker,
string|BackedEnum $name = QueueProducerProviderInterface::DEFAULT_QUEUE,
string|BackedEnum $name = DefaultQueue::NAME,
array $middlewareDefinitions = [],
) {
$this->name = StringNormalizer::normalize($name);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use Psr\Log\NullLogger;
use RuntimeException;
use Yiisoft\Injector\Injector;
use Yiisoft\Queue\Provider\QueueProducerProviderInterface;
use Yiisoft\Test\Support\Container\SimpleContainer;
use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\Cli\LoopInterface;
use Yiisoft\Queue\Cli\SimpleLoop;
use Yiisoft\Queue\DefaultQueue;
use Yiisoft\Queue\Middleware\CallableFactory;
use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareDispatcher;
use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareFactory;
Expand Down Expand Up @@ -93,7 +93,7 @@ protected function getContainer(): ContainerInterface

protected function createQueue(
?AdapterInterface $adapter = null,
string|BackedEnum $name = QueueProducerProviderInterface::DEFAULT_QUEUE,
string|BackedEnum $name = DefaultQueue::NAME,
): QueueProducerInterface {
return $adapter === null
? new SyncQueueProducer(
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Command/RunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\OutputInterface;
use Yiisoft\Queue\Command\RunCommand;
use Yiisoft\Queue\DefaultQueue;
use Yiisoft\Queue\Provider\PredefinedQueueProvider;
use Yiisoft\Queue\Provider\QueueConsumerProviderInterface;
use Yiisoft\Queue\QueueConsumerInterface;
use Yiisoft\Queue\Stubs\StubQueueProducer;

Expand All @@ -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()],
QueueConsumerProviderInterface::DEFAULT_QUEUE => ['consumer' => $consumer],
DefaultQueue::NAME => ['consumer' => $consumer],
]));
self::assertSame(0, $command->run(new StringInput(''), $this->createMock(OutputInterface::class)));
}
Expand Down
Loading