Skip to content

Commit c598caf

Browse files
committed
Guide improvements and bugfixes
1 parent f2e7eff commit c598caf

6 files changed

Lines changed: 45 additions & 11 deletions

File tree

docs/guide/en/channels.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,18 @@ $queue = $provider->get('emails');
126126
```
127127

128128
## Configuration with yiisoft/config
129+
130+
When using [yiisoft/config](https://github.com/yiisoft/config), channel configuration is stored in params under `yiisoft/queue.channels`.
129131

130-
When using [yiisoft/config](https://github.com/yiisoft/config), channel configuration is stored in params under `yiisoft/queue.channels`.
132+
By default, `QueueProviderInterface` is bound to `AdapterFactoryQueueProvider`.
133+
That makes `yiisoft/queue.channels` a strict channel registry:
131134

132-
It is a map:
135+
- `QueueProviderInterface::has($channel)` checks whether the channel exists in definitions.
136+
- `QueueProviderInterface::get($channel)` throws `ChannelNotFoundException` for unknown channels.
137+
138+
The same channel list is used by `queue:run` and `queue:listen-all` as the default set of channels to process.
139+
140+
It is a map:
133141

134142
- key: channel name
135143
- value: adapter definition that should be resolved for that channel

docs/guide/en/configuration-with-config.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,27 @@ If your project structure differs, put configuration into any params config file
99

1010
## What you need to configure
1111

12-
- Optionally: define default `\Yiisoft\Queue\Adapter\AdapterInterface` implementation.
13-
- And/or define channel-specific `AdapterInterface` implementations in the `channels` params key. See more about channels [here](./channels.md).
14-
- Define [message handlers](./message-handlers.md) in the `handlers` params key to be used with the `QueueWorker`.
12+
- Define queue channel adapter definitions in the `channels` params key. See more about channels [here](./channels.md).
13+
- Optionally: define [message handlers](./message-handler.md) in the `handlers` params key to be used with the `QueueWorker`.
1514
- Resolve other `\Yiisoft\Queue\Queue` dependencies (psr-compliant event dispatcher).
1615

16+
By default, when using the DI config provided by this package, `QueueProviderInterface` is bound to `AdapterFactoryQueueProvider` and uses `yiisoft/queue.channels` as a strict channel registry.
17+
That means unknown channels are not accepted silently and `QueueProviderInterface::get()` will throw `ChannelNotFoundException`.
18+
The configured channel names are also used as the default channel list for `queue:run` and `queue:listen-all`.
19+
20+
For development and testing you can start with the synchronous adapter.
21+
For production you must use a real backend adapter (AMQP, Kafka, SQS, etc.). If you do not have any preference, start with [yiisoft/queue-amqp](https://github.com/yiisoft/queue-amqp) and [RabbitMQ](https://www.rabbitmq.com/).
22+
23+
The examples below use the synchronous adapter for brevity. In production, override `yiisoft/queue.channels` with an adapter definition from the backend adapter package you selected.
24+
1725
## Minimal configuration example
1826

27+
If you use the handler class FQCN as the message handler name, no additional configuration is required.
28+
29+
See [Message handler](./message-handler.md) for details and trade-offs.
30+
31+
## Minimal configuration example (named handlers)
32+
1933
```php
2034
return [
2135
'yiisoft/queue' => [
@@ -35,11 +49,12 @@ return [
3549
'handler-name' => [FooHandler::class, 'handle'],
3650
],
3751
'channels' => [
38-
\Yiisoft\Queue\QueueInterface::DEFAULT_CHANNEL => \Yiisoft\Queue\Adapter\AdapterInterface::class,
52+
\Yiisoft\Queue\QueueInterface::DEFAULT_CHANNEL => \Yiisoft\Queue\Adapter\SynchronousAdapter::class,
3953
],
40-
'middlewares-push' => [],
41-
'middlewares-consume' => [],
42-
'middlewares-fail' => [],
54+
'middlewares-push' => [], // push middleware pipeline definition
55+
'middlewares-consume' => [], // consume middleware pipeline definition
56+
'middlewares-fail' => [], // consume failure handling middleware pipeline definition
4357
],
4458
];
4559
```
60+
Middleware pipelines are discussed in detail [here](./middleware-pipelines.md).

docs/guide/en/console-commands.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ If you are using [yiisoft/config](https://github.com/yiisoft/config) and [yiisof
66

77
If you are using [symfony/console](https://github.com/symfony/console) directly, you should register the commands manually.
88

9+
In [yiisoft/app](https://github.com/yiisoft/app) the `yii` console binary is provided out of the box.
10+
If you are using [yiisoft/console](https://github.com/yiisoft/console) or `symfony/console` without that template, invoke these commands the same way you invoke other console commands in your application.
11+
912
## 1. Run queued messages and exit
1013

1114
The command `queue:run` obtains and executes tasks until the queue is empty, then exits.

docs/guide/en/message-handler.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ This way external producers never need to know your internal PHP class names.
107107

108108
## Common pitfalls and unsupported formats
109109

110-
- A string definition is treated as a DI container ID first. If the container doesn't have such entry, it is resolved as a callable only when it is a valid PHP callable.
111110
- A class-string that is not resolvable via `$container->has()` will not be auto-instantiated.
112111
- [yiisoft/definitions](https://github.com/yiisoft/definitions) array format (like `['class' => ..., '__construct()' => ...]`) is **not** supported for handlers.
113112

docs/guide/en/prerequisites-and-installation.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
- PHP 8.1 or higher.
66
- PCNTL extension for signal handling (optional, recommended for production use).
77

8+
If `ext-pcntl` is not installed, workers cannot handle OS signals (such as `SIGTERM`/`SIGINT`) gracefully.
9+
In practice it means a process manager may terminate a worker at any time, which can interrupt a job in the middle of execution.
10+
See [Loops](loops.md) for details.
11+
812
## Installation
913

1014
Install the package with [Composer](https://getcomposer.org):

docs/guide/en/usage.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ $queue->push($message);
4848

4949
To push a job into the queue that should run after 5 minutes:
5050

51+
Delayed execution is implemented via a push middleware.
52+
The middleware must implement `\Yiisoft\Queue\Middleware\Push\Implementation\DelayMiddlewareInterface` and be provided by the adapter package you use.
53+
For example, the official AMQP adapter supports delays: <https://github.com/yiisoft/queue-amqp>
54+
5155
```php
52-
// TODO
56+
$delayMiddleware = $container->get(\Yiisoft\Queue\Middleware\Push\Implementation\DelayMiddlewareInterface::class);
57+
$queue->push($message, $delayMiddleware->withDelay(5 * 60));
5358
```
5459

5560
**Important:** Not every adapter (such as synchronous adapter) supports delayed execution.

0 commit comments

Comments
 (0)