Skip to content

Commit 108efce

Browse files
committed
Docs enhancements
1 parent bb9bea8 commit 108efce

13 files changed

+383
-290
lines changed

docs/guide/en/README.md

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,36 @@
1-
# Yii Queue
1+
# Yii Queue documentation map
22

3-
An extension for running tasks asynchronously via queues.
4-
5-
## Getting started
3+
## Install and configure
64

75
- [Prerequisites and installation](prerequisites-and-installation.md)
86
- [Configuration with yiisoft/config](configuration-with-config.md)
9-
- [Manual configuration](configuration-manual.md)
10-
11-
- [Usage basics](usage.md)
12-
- [Workers](worker.md)
13-
- [Console commands](console-commands.md)
14-
15-
## Adapters
16-
177
- [Adapter list](adapter-list.md)
188
- [Synchronous adapter](adapter-sync.md)
19-
20-
## Core concepts
21-
229
- [Queue names](queue-names.md)
23-
- [Message handler](message-handler.md)
24-
- [Envelopes](envelopes.md)
25-
- [Middleware pipelines](middleware-pipelines.md)
26-
- [Loops](loops.md)
2710

28-
## Interoperability
11+
## Build and run jobs
2912

30-
- [Producing messages from external systems](consuming-messages-from-external-systems.md)
13+
- [Usage basics](usage.md)
14+
- [Messages and handlers: concepts](messages-and-handlers.md)
15+
- [Message handler](message-handler-simple.md)
16+
- [Console commands](console-commands.md)
17+
- [Job status](job-status.md)
3118

3219
## Reliability and visibility
3320

3421
- [Errors and retryable jobs](error-handling.md)
35-
- [Job status](job-status.md)
22+
- [Envelopes](envelopes.md)
3623
- [Yii Debug integration](debug-integration.md)
3724

38-
## Production and optimization
25+
## Production readiness
3926

4027
- [Best practices](best-practices.md)
4128
- [Running workers in production (systemd and Supervisor)](process-managers.md)
42-
- [Performance tuning](performance-tuning.md)
4329

44-
## Migration from Yii2
30+
## Migration
4531

4632
- [Migrating from `yii2-queue`](migrating-from-yii2-queue.md)
33+
34+
## Advanced topics
35+
36+
Open the [advanced documentation map](advanced-map.md) if you build custom middleware, adapters, queue providers, or tooling.

docs/guide/en/advanced-map.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Advanced documentation map
2+
3+
Use this index when you need to customize internals: custom middleware, adapters, queue providers, tooling, or diagnostics.
4+
5+
## Configuration and infrastructure
6+
7+
- [Manual configuration without yiisoft/config](configuration-manual.md) — wiring queues, workers, and middleware factories without `yiisoft/config`.
8+
- [Queue provider registry](#queue-provider-registry) — selecting and extending adapter factories.
9+
- [Loops and worker processes](loops.md) — implementing custom runners, heartbeat hooks, and graceful shutdown (requires `pcntl`).
10+
- [Worker internals](worker.md) — dependency resolution and middleware stacks within `WorkerInterface`.
11+
- [Performance tuning](performance-tuning.md) — profiling handlers, envelopes, and adapters.
12+
13+
## Middleware, envelopes, and handlers
14+
15+
- [Middleware pipelines deep dive](middleware-pipelines.md) — dispatcher lifecycle, request mutations, and per-pipeline contracts.
16+
- [Callable definitions and middleware factories](callable-definitions-extended.md) — container-aware definitions for middleware factories.
17+
- [Error handling](error-handling.md#failure-pipeline-overview) — end-to-end flow of the failure pipeline.
18+
- [Custom failure middleware](error-handling.md#how-to-create-a-custom-failure-middleware) — implementing `MiddlewareFailureInterface`.
19+
- [Envelope metadata and stack reconstruction](envelopes.md#metadata-and-envelope-stacking) — stack resolution and metadata merging.
20+
- [FailureEnvelope usage](error-handling.md#failureenvelope) — retry metadata semantics.
21+
- [Handler resolver pipeline](message-handler.md#resolver-pipeline) — alternative handler lookup strategies.
22+
23+
## Queue adapters and interoperability
24+
25+
- [Custom queue provider implementations](queue-names-advanced.md#extending-the-registry) — bespoke selection logic, tenant registries, and fallback strategies.
26+
- [Consuming messages from external systems](consuming-messages-from-external-systems.md) — contract for third-party producers.
27+
- [Adapter internals](adapter-list.md#available-adapters) — extend or swap backend adapters.
28+
29+
## Tooling, diagnostics, and storage
30+
31+
- [Yii Debug collector internals](debug-integration-advanced.md) — collector internals, proxies, and manual wiring.
32+
- [Job status storage extensions](job-status.md#extend-storage) — persisting custom metadata or drivers.
33+
- [Extending queue processes and supervisors](process-managers.md#custom-supervisors) — custom supervisor hooks and graceful shutdown integration.
34+
35+
## Internals and contribution
36+
37+
- [Internals guide](../../internals.md) — local QA tooling (PHPUnit, Infection, Psalm, Rector, ComposerRequireChecker).
38+
39+
## Queue provider registry
40+
41+
When multiple queue names share infrastructure, rely on `QueueProviderInterface`:
42+
43+
- A queue name is passed to `QueueProviderInterface::get($queueName)` and resolved into a configured `QueueInterface` instance.
44+
- Providers typically construct adapters lazily via [`yiisoft/factory`](https://github.com/yiisoft/factory) and call `AdapterInterface::withChannel($channel)` to switch broker-specific channels.
45+
- Default implementation (`AdapterFactoryQueueProvider`) enforces a strict registry defined in `yiisoft/queue.channels`. Unknown names throw `ChannelNotFoundException`.
46+
- Alternative providers include:
47+
- `PrototypeQueueProvider` — clones a base queue/adapter, switching only the channel name (useful when all queues share infrastructure but risks typos).
48+
- `CompositeQueueProvider` — aggregates multiple providers and selects the first that knows the queue name.
49+
- Implement `QueueProviderInterface` to introduce custom registries or fallback strategies, then register the implementation in DI.

docs/guide/en/best-practices.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ $queue->push(new Message(
263263

264264
#### More info
265265

266-
See [Message handler](message-handler.md) for details.
266+
See [Message handler](message-handler-simple.md) for details.
267267

268268
## Monitoring and observability
269269

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

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,13 @@ If you are using [yiisoft/config](https://github.com/yiisoft/config) (i.e. insta
77
In [yiisoft/app](https://github.com/yiisoft/app) / [yiisoft/app-api](https://github.com/yiisoft/app-api) templates you typically add or adjust configuration in `config/params.php`.
88
If your project structure differs, put configuration into any params config file that is loaded by [yiisoft/config](https://github.com/yiisoft/config).
99

10-
## What you need to configure
10+
When your message uses a handler class that implements `Yiisoft\Queue\Message\MessageHandlerInterface` and the handler name equals its FQCN, nothing else has to be configured: the DI container resolves the class automatically. See [Message handler: simple setup](message-handler-simple.md) for details and trade-offs.
1111

12-
- Define queue name adapter definitions in the `channels` params key. See more about queue names [here](./queue-names.md).
13-
- Optionally: define [message handlers](./message-handler.md) in the `handlers` params key to be used with the `QueueWorker`.
12+
Advanced applications eventually need the following tweaks:
1413

15-
By default, when using the DI config provided by this package, `QueueProviderInterface` is bound to `AdapterFactoryQueueProvider` and uses `yiisoft/queue.channels` as a strict queue name registry.
16-
That means unknown queue names are not accepted silently and `QueueProviderInterface::get()` will throw `ChannelNotFoundException`.
17-
The configured queue names are also used as the default queue name list for `queue:run` and `queue:listen-all`.
14+
- **Channels** — configure queue/back-end per logical queue name via [`yiisoft/queue.channels` config](queue-names.md) when you need to parallelize message handling or send some of them to a different application.
15+
- **Named handlers or callable definitions** — map a short handler name to a callable in [`yiisoft/queue.handlers` config](message-handler.md) when another application is the message producer and you cannot use FQCN as the handler name.
16+
- **Middleware pipelines** — adjust push/consume/failure behavior: collect metrics, modify messages, and so on. See [Middleware pipelines](middleware-pipelines.md) for details.
1817

1918
For development and testing you can start with the synchronous adapter.
20-
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/).
21-
22-
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.
23-
24-
## Minimal configuration example
25-
26-
If you use the handler class FQCN as the message handler name, no additional configuration is required.
27-
28-
See [Message handler](./message-handler.md) for details and trade-offs.
29-
30-
## Minimal configuration example (named handlers)
31-
32-
```php
33-
return [
34-
'yiisoft/queue' => [
35-
'handlers' => [
36-
'handler-name' => [FooHandler::class, 'handle'],
37-
],
38-
],
39-
];
40-
```
41-
42-
## Full configuration example
43-
44-
```php
45-
return [
46-
'yiisoft/queue' => [
47-
'handlers' => [
48-
'handler-name' => [FooHandler::class, 'handle'],
49-
],
50-
'channels' => [
51-
\Yiisoft\Queue\QueueInterface::DEFAULT_CHANNEL => \Yiisoft\Queue\Adapter\SynchronousAdapter::class,
52-
],
53-
'middlewares-push' => [], // push middleware pipeline definition
54-
'middlewares-consume' => [], // consume middleware pipeline definition
55-
'middlewares-fail' => [], // consume failure handling middleware pipeline definition
56-
],
57-
];
58-
```
59-
Middleware pipelines are discussed in detail [here](./middleware-pipelines.md).
19+
For production you have to use a [real backend adapter](adapter-list.md) (AMQP, Kafka, SQS, etc.). If you do not have any preference, it's simpler to start with [yiisoft/queue-amqp](https://github.com/yiisoft/queue-amqp) and [RabbitMQ](https://www.rabbitmq.com/).

docs/guide/en/consuming-messages-from-external-systems.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Producing messages from external systems
1+
# Consuming messages from external systems
22

33
This guide explains how to publish messages to a queue backend (RabbitMQ, Kafka, SQS, etc.) from *external producers* (including non-PHP services) so that `yiisoft/queue` consumers can correctly deserialize and process these messages.
44

@@ -16,7 +16,7 @@ So, external systems should produce the **same payload format** that your consum
1616

1717
`yiisoft/queue` resolves a handler by message handler name (`MessageInterface::getHandlerName()`).
1818

19-
For external producers, you should not rely on PHP FQCN handler names. Prefer a stable short name and map it in the consumer application configuration (see [Message handler](message-handler.md)).
19+
For external producers, you should not rely on PHP FQCN handler names. Prefer a stable short name and map that name to a handler callable in the consumer application configuration (see [Message handler](message-handler.md)).
2020

2121
Example mapping:
2222

@@ -70,7 +70,7 @@ Full example:
7070

7171
### Notes about `meta`
7272

73-
The `meta` key is a general-purpose metadata container (for example, tracing, correlation, tenant information). External systems may populate it, and the consumer-side application or middleware may also read, add, or override keys as needed. However, it's not recommended, as it highly depends on the consumer-side application code.
73+
The `meta` key is a general-purpose metadata container (for example, tracing, correlation, tenant information). The consumer-side application or middleware may read, add, or override keys as needed. Populating `meta` from external producers is possible but not recommended: the accepted keys and their semantics are entirely defined by the consumer application, so any contract must be maintained manually.
7474

7575
## 3. Data encoding rules
7676

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Advanced Yii Debug integration
2+
3+
Use this guide when you need to understand which events are tracked by the queue collector, how proxy services operate, and how to wire the collector manually.
4+
5+
## What is collected
6+
7+
The integration is based on `Yiisoft\Queue\Debug\QueueCollector` and captures:
8+
9+
- Pushed messages grouped by queue name (including middleware definitions passed to `push()`).
10+
- Job status checks performed via `QueueInterface::status()`.
11+
- Messages processed by a worker grouped by queue name.
12+
13+
## How it works
14+
15+
The collector is enabled by registering it in Yii Debug and wrapping tracked services with proxy implementations.
16+
17+
Out of the box (see this package's `config/params.php`), the following services are intercepted:
18+
19+
- `Yiisoft\Queue\Provider\QueueProviderInterface` is wrapped with `Yiisoft\Queue\Debug\QueueProviderInterfaceProxy`. The proxy decorates returned queues with `Yiisoft\Queue\Debug\QueueDecorator` so that `push()` and `status()` calls are reported to the collector.
20+
- `Yiisoft\Queue\Worker\WorkerInterface` is wrapped with `Yiisoft\Queue\Debug\QueueWorkerInterfaceProxy` to record message processing events.
21+
22+
To see data in the debug panel you must obtain `QueueProviderInterface` and `WorkerInterface` from the DI container so that the proxies remain in effect.
23+
24+
## Manual configuration
25+
26+
If you do not rely on the defaults supplied via [yiisoft/config](https://github.com/yiisoft/config), configure the collector and proxies explicitly:
27+
28+
```php
29+
use Yiisoft\Queue\Debug\QueueCollector;
30+
use Yiisoft\Queue\Debug\QueueProviderInterfaceProxy;
31+
use Yiisoft\Queue\Debug\QueueWorkerInterfaceProxy;
32+
use Yiisoft\Queue\Provider\QueueProviderInterface;
33+
use Yiisoft\Queue\Worker\WorkerInterface;
34+
35+
return [
36+
'yiisoft/yii-debug' => [
37+
'collectors' => [
38+
QueueCollector::class,
39+
],
40+
'trackedServices' => [
41+
QueueProviderInterface::class => [QueueProviderInterfaceProxy::class, QueueCollector::class],
42+
WorkerInterface::class => [QueueWorkerInterfaceProxy::class, QueueCollector::class],
43+
],
44+
],
45+
];
46+
```

docs/guide/en/debug-integration.md

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,6 @@
22

33
This package provides an integration with [yiisoft/yii-debug](https://github.com/yiisoft/yii-debug).
44

5-
When debug is enabled, it collects queue-related information and shows it in the Yii Debug panel.
5+
When Yii Debug is enabled, the queue collector adds a panel that shows pushed messages, job status checks, and worker activity.
66

7-
## What is collected
8-
9-
The integration is based on `Yiisoft\Queue\Debug\QueueCollector`.
10-
11-
It collects:
12-
13-
- Pushed messages grouped by queue name (including middleware definitions passed to `push()`).
14-
- Job status checks performed via `QueueInterface::status()`.
15-
- Messages processed by a worker grouped by queue name.
16-
17-
## How it works
18-
19-
The details below are optional. You can skip them if you only need to enable the panel and see collected data.
20-
21-
The integration is enabled by registering the collector and wrapping tracked services with proxy implementations.
22-
23-
In this package defaults (see `config/params.php`), the following services are tracked:
24-
25-
- `Yiisoft\Queue\Provider\QueueProviderInterface` is wrapped with `Yiisoft\Queue\Debug\QueueProviderInterfaceProxy`.
26-
The proxy decorates returned queues with `Yiisoft\Queue\Debug\QueueDecorator` to collect `push()` and `status()` calls.
27-
- `Yiisoft\Queue\Worker\WorkerInterface` is wrapped with `Yiisoft\Queue\Debug\QueueWorkerInterfaceProxy` to collect message processing.
28-
29-
Because of that, to see data in debug you should obtain `QueueProviderInterface` / `WorkerInterface` from the DI container.
30-
31-
## Configuration
32-
33-
If you use [yiisoft/config](https://github.com/yiisoft/config) and the configuration plugin, these defaults are loaded automatically from this package.
34-
35-
Otherwise, you can configure it manually in your params configuration:
36-
37-
```php
38-
use Yiisoft\Queue\Debug\QueueCollector;
39-
use Yiisoft\Queue\Debug\QueueProviderInterfaceProxy;
40-
use Yiisoft\Queue\Debug\QueueWorkerInterfaceProxy;
41-
use Yiisoft\Queue\Provider\QueueProviderInterface;
42-
use Yiisoft\Queue\Worker\WorkerInterface;
43-
44-
return [
45-
'yiisoft/yii-debug' => [
46-
'collectors' => [
47-
QueueCollector::class,
48-
],
49-
'trackedServices' => [
50-
QueueProviderInterface::class => [QueueProviderInterfaceProxy::class, QueueCollector::class],
51-
WorkerInterface::class => [QueueWorkerInterfaceProxy::class, QueueCollector::class],
52-
],
53-
],
54-
];
55-
```
7+
If you use [yiisoft/config](https://github.com/yiisoft/config) together with this package, the debug collector is registered automatically. For manual configuration snippets and proxy wiring details, see [Advanced Yii Debug integration](debug-integration-advanced.md).
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Message handler
2+
3+
> If you are new to the concept of messages and handlers, read [Messages and handlers: concepts](messages-and-handlers.md) first.
4+
5+
The simplest setup requires no configuration at all: create a dedicated class implementing `Yiisoft\Queue\Message\MessageHandlerInterface` and use its FQCN as the handler name when pushing a message.
6+
7+
## HandlerInterface implementation (without name mapping)
8+
9+
If your handler implements `Yiisoft\Queue\Message\MessageHandlerInterface`, you can use the class FQCN as the message handler name. The DI container resolves the handler automatically.
10+
11+
> By default the [yiisoft/di](https://github.com/yiisoft/di) container resolves all FQCNs into corresponding class objects.
12+
13+
**Message**:
14+
15+
```php
16+
new \Yiisoft\Queue\Message\Message(\App\Queue\RemoteFileHandler::class, ['url' => '...']);
17+
```
18+
19+
**Handler**:
20+
21+
```php
22+
final class RemoteFileHandler implements \Yiisoft\Queue\Message\MessageHandlerInterface
23+
{
24+
public function handle(\Yiisoft\Queue\Message\MessageInterface $message): void
25+
{
26+
// Handle the message
27+
}
28+
}
29+
```
30+
31+
**Config**: Not needed.
32+
33+
**Pros**:
34+
35+
- Minimal configuration.
36+
- Rename-safe within the same application (rename class and producer together).
37+
- Easy to unit-test the handler as a normal class.
38+
39+
**Cons**:
40+
41+
- Couples message names to PHP class names.
42+
- Requires producer and consumer to share the same naming contract (typically the same app).
43+
44+
**Use when**:
45+
46+
- Producer and consumer are the same application.
47+
- You control message creation and can safely use FQCN as the handler name.
48+
49+
## When FQCN is not enough
50+
51+
When the producer is an external application or a different service, FQCN-based names create a hard dependency on PHP class names. In that case, use short stable handler names mapped to callables in config.
52+
53+
See [Message handler: named handlers and advanced formats](message-handler.md) for all supported definition formats, pitfalls, and recommendations.

0 commit comments

Comments
 (0)