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
@@ -4,80 +4,158 @@ A *queue channel* is a named queue configuration.
4
4
5
5
In practice, a channel is a string (for example, `yii-queue`, `emails`, `critical`) that selects which queue backend (adapter) messages are pushed to and which worker consumes them.
6
6
7
+
At a high level:
8
+
9
+
- You configure one or more channels.
10
+
- When producing messages, you either:
11
+
- use `QueueInterface` directly (single/default channel), or
12
+
- use `QueueProviderInterface` to get a queue for a specific channel.
13
+
- When consuming messages, you run a worker command for a channel (or a set of channels).
14
+
7
15
Having multiple channels is useful when you want to separate workloads, for example:
> `SynchronousAdapter` is for learning/testing only. For production, install a real adapter, see adapter list: [adapter-list](adapter-list.md).
46
+
47
+
#### 1.2. Configure a default channel
48
+
49
+
When you are using `yiisoft/config` and the default configs from this package are loaded, the default channel is already present in params (so you don't need to add anything). The snippet below shows what is shipped by default in [config/params.php](../../../config/params.php):
`QueueProviderInterface` accepts both strings and `BackedEnum` values (they are normalized to a string channel name).
61
123
124
+
## Running workers (CLI)
125
+
126
+
To consume messages you run console commands such as `queue:run`, `queue:listen`, and `queue:listen-all`.
127
+
See [Console commands](console-commands.md) for details.
128
+
129
+
## Advanced
130
+
131
+
### How channels are used in the code
132
+
133
+
- A channel name is passed to `Yiisoft\Queue\Provider\QueueProviderInterface::get($channel)`.
134
+
- The provider returns a `Yiisoft\Queue\QueueInterface` instance that uses an adapter configured for that channel.
135
+
- Internally, the provider creates an adapter instance and calls `AdapterInterface::withChannel($channel)`.
136
+
137
+
In other words, a channel is the key that lets the application select a particular adapter instance/configuration.
138
+
139
+
`QueueInterface::getChannel()` is available for introspection and higher-level logic (for example, selecting middleware pipelines per channel). The channel itself is stored in the adapter and `Queue` proxies it.
The exact adapter definitions depend on which queue adapter package you use (Redis, AMQP, etc.).
177
-
178
-
When using the default DI config from this package, the configured channel names are also used as the default channel list for `queue:run` and `queue:listen-all`.
179
-
180
-
## Manual configuration (without yiisoft/config)
206
+
### Manual configuration (without yiisoft/config)
181
207
182
208
For multiple channels without `yiisoft/config`, you can create a provider manually.
183
209
184
210
`AdapterFactoryQueueProvider` accepts adapter definitions indexed by channel names and returns a `QueueInterface` for a channel on demand:
185
211
212
+
> In this example, `$worker`, `$queue` and `$container` are assumed to be created already.
213
+
> See [Manual configuration](configuration-manual.md) for a full runnable setup.
214
+
186
215
```php
187
216
use Yiisoft\Queue\Provider\AdapterFactoryQueueProvider;
188
217
use Yiisoft\Queue\Adapter\SynchronousAdapter;
189
218
190
219
$definitions = [
191
-
'channel1' => new SynchronousAdapter($worker, $queue),
0 commit comments