Skip to content

Commit f2e7eff

Browse files
committed
Remove redundant info from the main readme
1 parent ae5867a commit f2e7eff

1 file changed

Lines changed: 0 additions & 201 deletions

File tree

README.md

Lines changed: 0 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -128,207 +128,6 @@ By default, Yii Framework uses [yiisoft/yii-console](https://github.com/yiisoft/
128128

129129
> 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.
130130
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:
184-
185-
```php
186-
use Yiisoft\Queue\Adapter\SynchronousAdapter;
187-
188-
[
189-
'channel1' => new SynchronousAdapter(),
190-
'channel2' => static fn(SynchronousAdapter $adapter) => $adapter->withChannel('channel2'),
191-
'channel3' => [
192-
'class' => SynchronousAdapter::class,
193-
'__constructor' => ['channel' => 'channel3'],
194-
],
195-
]
196-
```
197-
198-
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:
222-
223-
```sh
224-
yii queue:run [channel1 [channel2 [...]]] --maximum=100
225-
```
226-
227-
The following command launches a daemon which infinitely queries the queue:
228-
229-
```sh
230-
yii queue:listen [channel]
231-
```
232-
233-
The following command iterates through multiple channels and is meant to be used in development environment only:
234-
235-
```sh
236-
yii queue:listen-all [channel1 [channel2 [...]]] --pause=1 --maximum=0
237-
```
238-
239-
For long-running processes, graceful shutdown is controlled by `LoopInterface`. When `ext-pcntl` is available,
240-
the default `SignalLoop` handles signals such as `SIGTERM`/`SIGINT`.
241-
242-
See the documentation for more details about adapter specific console commands and their options.
243-
244-
The component can also track the status of a job which was pushed into queue.
245-
For more details, see [Job status](docs/guide/en/job-status.md).
246-
247-
## Debugging
248-
249-
If you use [yiisoft/yii-debug](https://github.com/yiisoft/yii-debug), the package provides a `QueueCollector` that can
250-
collect message pushes, `status()` calls and message processing by the worker. The defaults are already present in
251-
[`config/params.php`](config/params.php).
252-
253-
## Middleware pipelines
254-
255-
Any message pushed to a queue or consumed from it passes through two different middleware pipelines: one pipeline
256-
on message push and another - on a message consume. The process is the same as for the HTTP request, but it is executed
257-
twice for a queue message. That means you can add extra functionality on message pushing and consuming with configuration
258-
of the two classes: `PushMiddlewareDispatcher` and `ConsumeMiddlewareDispatcher` respectively.
259-
260-
You can use any of these formats to define a middleware:
261-
262-
- A ready-to-use middleware object: `new FooMiddleware()`. It must implement `MiddlewarePushInterface`,
263-
`MiddlewareConsumeInterface` or `MiddlewareFailureInterface` depending on the place you use it.
264-
- An array in the format of [yiisoft/definitions](https://github.com/yiisoft/definitions).
265-
- A `callable`: `fn() => // do stuff`, `$object->foo(...)`, etc. It will be executed through the
266-
[yiisoft/injector](https://github.com/yiisoft/injector), so all the dependencies of your callable will be resolved.
267-
- A string for your DI container to resolve the middleware, e.g. `FooMiddleware::class`
268-
269-
Middleware will be executed forwards in the same order they are defined. If you define it like the following:
270-
`[$middleware1, $midleware2]`, the execution will look like this:
271-
272-
```mermaid
273-
graph LR
274-
StartPush((Start)) --> PushMiddleware1[$middleware1] --> PushMiddleware2[$middleware2] --> Push(Push to a queue)
275-
-.-> PushMiddleware2[$middleware2] -.-> PushMiddleware1[$middleware1]
276-
PushMiddleware1[$middleware1] -.-> EndPush((End))
277-
278-
279-
StartConsume((Start)) --> ConsumeMiddleware1[$middleware1] --> ConsumeMiddleware2[$middleware2] --> Consume(Consume / handle)
280-
-.-> ConsumeMiddleware2[$middleware2] -.-> ConsumeMiddleware1[$middleware1]
281-
ConsumeMiddleware1[$middleware1] -.-> EndConsume((End))
282-
```
283-
284-
### Push a pipeline
285-
286-
When you push a message, you can use middlewares to modify both message and queue adapter.
287-
With message modification you can add extra data, obfuscate data, collect metrics, etc.
288-
With queue adapter modification you can redirect the message to another queue, delay message consuming, and so on.
289-
290-
To use this feature, you have to create a middleware class, which implements `MiddlewarePushInterface`, and
291-
return a modified `PushRequest` object from the `processPush` method:
292-
293-
```php
294-
return $pushRequest->withMessage($newMessage)->withAdapter($newAdapter);
295-
```
296-
297-
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 for a 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 messages in 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 done in [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.
331-
332131
## Documentation
333132

334133
- [Guide](docs/guide/en/README.md)

0 commit comments

Comments
 (0)