You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,9 +36,11 @@ composer require yiisoft/queue
36
36
For production use, you should install an adapter package that matches your message broker ([AMQP](https://github.com/yiisoft/queue-amqp), [Kafka](https://github.com/g41797/queue-kafka), [NATS](https://github.com/g41797/queue-nats), and [others](docs/guide/en/adapter-list.md)).
37
37
See the [adapter list](docs/guide/en/adapter-list.md) and follow the adapter-specific documentation for installation and configuration details.
38
38
39
-
> For development and testing, you can start without an external broker using the built-in [`SynchronousAdapter`](docs/guide/en/adapter-sync.md).
40
-
> This adapter processes messages immediately in the same process, so it won't provide true async execution,
41
-
> but it's useful for getting started and writing tests.
39
+
> If you don't have an external broker — whether for development, testing, or because you want to
40
+
> design around `QueueInterface` from day one and add a real broker later — you can run the queue
41
+
> in [synchronous mode](docs/guide/en/synchronous-mode.md) (the adapter argument is optional).
42
+
> In this mode messages are processed immediately in the same process, so it won't provide true
43
+
> async execution, but the code stays the same when you switch to a real adapter.
42
44
43
45
### 2. Configure the queue
44
46
@@ -127,7 +129,7 @@ By default, Yii Framework uses [yiisoft/yii-console](https://github.com/yiisoft/
127
129
128
130
See [Console commands](docs/guide/en/console-commands.md) for more details.
129
131
130
-
> In case you're using the `SynchronousAdapter` for development purposes, you should not use these commands, as you have no asynchronous processing available. The messages are processed immediately when pushed.
132
+
> 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.
Copy file name to clipboardExpand all lines: docs/guide/en/configuration-manual.md
+3-30Lines changed: 3 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,6 @@ To use the queue, you need to create instances of the following classes:
16
16
use Psr\Container\ContainerInterface;
17
17
use Psr\Log\NullLogger;
18
18
use Yiisoft\Injector\Injector;
19
-
use Yiisoft\Queue\Adapter\SynchronousAdapter;
20
19
use Yiisoft\Queue\Cli\SimpleLoop;
21
20
use Yiisoft\Queue\Middleware\CallableFactory;
22
21
use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareDispatcher;
@@ -70,49 +69,23 @@ $worker = new Worker(
70
69
// Create loop (SignalLoop requires ext-pcntl; SimpleLoop works without it)
71
70
$loop = new SimpleLoop();
72
71
73
-
// Create queue (adapter is wired in a second step due to mutual dependency)
72
+
// Create queue. Without an adapter the queue runs in synchronous mode (messages are processed
73
+
// immediately on push). Pass an adapter (e.g., AMQP, Redis) for asynchronous processing.
74
74
$queue = new Queue(
75
75
$worker,
76
76
$loop,
77
77
$logger,
78
78
$pushMiddlewareDispatcher,
79
79
);
80
80
81
-
// SynchronousAdapter needs a queue reference — create it after the queue
82
-
$adapter = new SynchronousAdapter($worker, $queue);
83
-
84
-
// Attach the adapter to the queue (returns a new Queue instance)
85
-
$queue = $queue->withAdapter($adapter);
86
-
87
81
// Now you can push messages
88
82
$message = new \Yiisoft\Queue\Message\Message('file-download', ['url' => 'https://example.com/file.pdf']);
89
83
$queue->push($message);
90
84
```
91
85
92
86
## Using Queue Provider
93
87
94
-
For multiple queue names, use `AdapterFactoryQueueProvider` (maps queue names to adapter definitions) or `PredefinedQueueProvider` (maps queue names to pre-built queue instances):
95
-
96
-
```php
97
-
use Yiisoft\Queue\Provider\AdapterFactoryQueueProvider;
98
-
use Yiisoft\Queue\Adapter\SynchronousAdapter;
99
-
100
-
// AdapterFactoryQueueProvider: each queue name maps to an adapter definition.
101
-
// The provider wraps each adapter in a Queue with the given name.
102
-
$definitions = [
103
-
'queue1' => new SynchronousAdapter($worker, $queue),
104
-
'queue2' => SynchronousAdapter::class,
105
-
];
106
-
107
-
$provider = new AdapterFactoryQueueProvider(
108
-
$queue,
109
-
$definitions,
110
-
$container,
111
-
);
112
-
113
-
$queueForQueue1 = $provider->get('queue1');
114
-
$queueForQueue2 = $provider->get('queue2');
115
-
```
88
+
For multiple queue names, use `PredefinedQueueProvider` (maps queue names to pre-built queue instances):
116
89
117
90
```php
118
91
use Yiisoft\Queue\Provider\PredefinedQueueProvider;
Copy file name to clipboardExpand all lines: docs/guide/en/configuration-with-config.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,5 +15,6 @@ Advanced applications eventually need the following tweaks:
15
15
-**Named handlers or callable definitions** — map a short message type to a callable in [`yiisoft/queue.handlers` config](message-handler-advanced.md) when another application is the message producer and you cannot use FQCN as message type.
16
16
-**Middleware pipelines** — adjust push/consume/failure behavior: collect metrics, modify messages, and so on. See [Middleware pipelines](middleware-pipelines.md) for details.
17
17
18
-
For development and testing you can start with the synchronous adapter.
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/).
18
+
If you don't have a broker yet (for development, testing, or as a stepping stone before introducing
19
+
async processing), you can run the queue in [synchronous mode](synchronous-mode.md).
20
+
For real asynchronous processing pick a [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/).
Copy file name to clipboardExpand all lines: docs/guide/en/console-commands.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,8 @@ The following command launches a daemon, which infinitely consumes messages from
33
33
yii queue:listen [queueName]
34
34
```
35
35
36
+
>**Note:** If the queue is not configured with an adapter (synchronous mode), the command logs an info message and exits gracefully.
37
+
36
38
## 3. Listen to multiple queues
37
39
38
40
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:
Status tracking support depends on the adapter. If an adapter doesn't keep status history, calling `status()` with that ID will throw `InvalidArgumentException`.
10
+
Status tracking support depends on the adapter. If an adapter doesn't support status tracking or can't find the message by ID, it returns `MessageStatus::NOT_FOUND`.
11
11
12
12
## Getting a message ID
13
13
@@ -30,6 +30,9 @@ The ID type (`string` or `int`) and how long it stays queryable are adapter-spec
30
30
31
31
Statuses are represented by the `Yiisoft\Queue\MessageStatus` enum:
32
32
33
+
-`MessageStatus::NOT_FOUND`
34
+
The message is not known to the queue, or the adapter doesn't support status tracking.
35
+
33
36
-`MessageStatus::WAITING`
34
37
The message is in the queue and has not been picked up yet.
35
38
@@ -42,7 +45,7 @@ Statuses are represented by the `Yiisoft\Queue\MessageStatus` enum:
42
45
In addition to enum cases, `MessageStatus` provides a string key via `MessageStatus::key()`:
43
46
44
47
```php
45
-
$statusKey = $status->key(); // "waiting", "reserved" or "done"
48
+
$statusKey = $status->key(); // "not-found", "waiting", "reserved" or "done"
46
49
```
47
50
48
51
## Querying a status
@@ -73,10 +76,10 @@ if ($status === MessageStatus::DONE) {
73
76
}
74
77
```
75
78
76
-
## Errors and edge cases
79
+
## Edge cases
77
80
78
-
-**Unknown ID**
79
-
If an adapter can't find the message by ID, it must throw `InvalidArgumentException`.
81
+
-**Unknown ID or unsupported tracking**
82
+
If an adapter doesn't support status tracking or can't find the message by ID, it returns `MessageStatus::NOT_FOUND`.
80
83
81
84
-**Timing**
82
85
`RESERVED` can be short-lived and difficult to observe: depending on the adapter, a message may move from `WAITING` to `RESERVED` and then to `DONE` quickly.
0 commit comments