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
-201Lines changed: 0 additions & 201 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,207 +128,6 @@ By default, Yii Framework uses [yiisoft/yii-console](https://github.com/yiisoft/
128
128
129
129
> In case you're using the `SynchronosAdapter` for development purposes, you should not use these commands, as you have no asynchronous processing available. The messages are processed immediately when pushed.
130
130
131
-
132
-
133
-
## Custom handler names
134
-
135
-
By default, when you push a message to the queue, the message handler name is the fully qualified class name of the handler.
136
-
This can be useful for most cases, but sometimes you may want to use a shorter name or arbitrary string as the handler name.
137
-
This can be useful when you want to reduce the amount of data being passed or when you communicate with external systems.
138
-
139
-
To use a custom handler name before message push, you can pass it as the first argument `Message` when creating it:
140
-
141
-
```php
142
-
new Message('handler-name', $data);
143
-
```
144
-
145
-
To use a custom handler name on message consumption, you should configure handler mapping for the `Worker` class:
146
-
147
-
```php
148
-
$params['yiisoft/queue']['handlers'] = [
149
-
'handler-name' => FooHandler::class,
150
-
];
151
-
```
152
-
153
-
## Different queue channels
154
-
155
-
Often we need to push to different queue channels with an only application. There is the `QueueProviderInterface`
156
-
interface that provides different `Queue` objects creation for different channels. With implementation of this interface
157
-
channel-specific `Queue` creation is as simple as
158
-
159
-
```php
160
-
$queue = $provider->get('channel-name');
161
-
```
162
-
163
-
You can also check if a channel exists before trying to get it:
164
-
165
-
```php
166
-
if ($provider->has('channel-name')) {
167
-
$queue = $provider->get('channel-name');
168
-
}
169
-
```
170
-
171
-
`QueueProviderInterface::get()` may throw `ChannelNotFoundException`, `InvalidQueueConfigException` or `QueueProviderException`.
172
-
173
-
Out of the box, there are three implementations of the `QueueProviderInterface`:
174
-
175
-
-`AdapterFactoryQueueProvider`
176
-
-`PrototypeQueueProvider`
177
-
-`CompositeQueueProvider`
178
-
179
-
### `AdapterFactoryQueueProvider`
180
-
181
-
Provider based on the definition of channel-specific adapters. Definitions are passed in
182
-
the `$definitions` constructor parameter of the factory, where keys are channel names and values are definitions
183
-
for the [`Yiisoft\Factory\Factory`](https://github.com/yiisoft/factory). Below are some examples:
For more information about the definition formats available, see the [factory](https://github.com/yiisoft/factory) documentation.
199
-
200
-
### `PrototypeQueueProvider`
201
-
202
-
Queue provider that only changes the channel name of the base queue. It can be useful when your queues used the same
203
-
adapter.
204
-
205
-
> Warning: This strategy is not recommended as it does not give you any protection against typos and mistakes
206
-
> in channel names.
207
-
208
-
### `CompositeQueueProvider`
209
-
210
-
This provider allows you to combine multiple providers into one. It will try to get a queue from each provider in the
211
-
order they are passed to the constructor. The first queue found will be returned.
212
-
213
-
## Console execution
214
-
215
-
This package provides queue abstractions and includes a `SynchronousAdapter` for development and test environments.
216
-
To run a real queue backend, install one of the adapter packages listed in the [guide](docs/guide/en/adapter-list.md).
217
-
218
-
The exact way of task execution depends on the adapter used. Most adapters can be run using console commands.
219
-
If you are using [yiisoft/config](https://github.com/yiisoft/config) with [yiisoft/yii-console](https://github.com/yiisoft/yii-console), the component automatically registers the commands.
220
-
221
-
The following command obtains and executes tasks in a loop until the queue is empty:
With push middlewares you can define an adapter object at the runtime, not in the `Queue` constructor.
298
-
There is a restriction: by the time all middlewares are executed in the forward order, the adapter must be specified
299
-
in the `PushRequest` object. You will get a `AdapterNotConfiguredException`, if it isn't.
300
-
301
-
You have three places to define push middlewares:
302
-
303
-
1. `PushMiddlewareDispatcher`. You can pass it either to the constructor, or to the `withMiddlewares()` method, which
304
-
creates a completely new dispatcher object with only those middlewares, which are passed as arguments.
305
-
If you use [yiisoft/config](https://github.com/yiisoft/config), you can add middleware to the `middlewares-push` key of the
306
-
[`yiisoft/queue`](https://github.com/yiisoft/queue) array in the `params`.
307
-
2. Pass middlewares to either `Queue::withMiddlewares()` or `Queue::withMiddlewaresAdded()` methods. The difference is
308
-
that the former will completely replace an existing middleware stack, while the latter will add passed middlewares to
309
-
the end of the existing stack. These middlewares will be executed after the common ones, passed directly to the
310
-
`PushMiddlewareDispatcher`. It's useful when defining a queue channel. Both methods return a new instance of the `Queue`
311
-
class.
312
-
3. Put middlewares into the `Queue::push()` method like this: `$queue->push($message, ...$middlewares)`. These
313
-
middlewares have the lowest priority and will be executed after those which are in the `PushMiddlewareDispatcher` and
314
-
the ones passed to the `Queue::withMiddlewares()` and `Queue::withMiddlewaresAdded()` and only for the message passed
315
-
along with them.
316
-
317
-
### Consume pipeline
318
-
319
-
You can set a middleware pipeline fora message when it will be consumed from a queue server. This is useful to collect metrics, modify message data, etc. In a pair with a Push middleware you can deduplicate messagesin the queue, calculate time from push to consume, handle errors (push to a queue again, redirect failed message to another queue, send a notification, etc.). Except push pipeline, you have only one place to define the middleware stack: in the `ConsumeMiddlewareDispatcher`, either in the constructor, or in the `withMiddlewares()` method. If you use [yiisoft/config](https://github.com/yiisoft/config), you can add middleware to the `middlewares-consume` key of the [`yiisoft/queue`](https://github.com/yiisoft/queue) array in the `params`.
320
-
321
-
### Error handling pipeline
322
-
323
-
Often when some job is failing, we want to retry its execution a couple more times or redirect it to another queue channel. This can be donein [yiisoft/queue](https://github.com/yiisoft/queue) with a Failure middleware pipeline. They are triggered each time message processing via the Consume middleware pipeline is interrupted with any `Throwable`. The key differences from the previous two pipelines:
324
-
325
-
- You should set up the middleware pipeline separately for each queue channel. That means, the format should be `['channel-name'=> [FooMiddleware::class]]` instead of `[FooMiddleware::class]`, like for the other two pipelines. There is also a default key, which will be used for those channels without their own one: `FailureMiddlewareDispatcher::DEFAULT_PIPELINE`.
326
-
- The last middleware will throw the exception, which will come with the `FailureHandlingRequest` object. If you don't want the exception to be thrown, your middlewares should `return` a request without calling `$handler->handleFailure()`.
327
-
328
-
You can declare error handling a middleware pipeline in the `FailureMiddlewareDispatcher`, either in the constructor, or in the `withMiddlewares()` method. If you use [yiisoft/config](https://github.com/yiisoft/config), you can add middleware to the `middlewares-fail` key of the [`yiisoft/queue`](https://github.com/yiisoft/queue) array in the `params`.
329
-
330
-
See [error handling docs](docs/guide/error-handling.md) for details.
0 commit comments