|
2 | 2 |
|
3 | 3 | > [Message Queue](https://github.com/antidot-framework/message-queue)
|
4 | 4 |
|
| 5 | +## Install |
| 6 | + |
5 | 7 | ```bash
|
6 | 8 | composer require antidot-fw/message-queue
|
7 | 9 | ```
|
8 | 10 |
|
9 | 11 | Install a transport for the queues:
|
10 | 12 |
|
11 |
| -* Null Queue |
12 |
| -* Filesystem Queue |
13 |
| -* DBAL Queue |
14 |
| -* Redis Queue |
15 |
| -* Beanstalk |
16 |
| -* Amazon SQS |
17 |
| - |
| 13 | +* [Null Queue](https://queue.antidotfw.io/#/#null-qeue) |
| 14 | +* [Filesystem Queue](https://queue.antidotfw.io/#/#filesystem-qeue) |
| 15 | +* [DBAL Queue](https://queue.antidotfw.io/#/#dbal-qeue) |
| 16 | +* [Redis Queue](https://queue.antidotfw.io/#/#redis-qeue) |
| 17 | +* [Beanstalk](https://queue.antidotfw.io/#/#beanstalk-qeue) |
| 18 | +* [Amazon SQS](https://queue.antidotfw.io/#/#amazon-sqs-qeue) |
18 | 19 |
|
19 | 20 | Allow using a job queues out of the box with different queue systems.
|
20 | 21 |
|
21 | 22 | [See full documentation](https://queue.antidotfw.io) for transport specific configs.
|
| 23 | + |
| 24 | +## Quick start |
| 25 | + |
| 26 | +Once you have installed and configured some transport type following specific config section. You can inject the `Antidot\Queue\Producer` class |
| 27 | +inside your classes, for example in a Request Handler. |
| 28 | + |
| 29 | +```php |
| 30 | +<?php |
| 31 | + |
| 32 | +declare(strict_types=1); |
| 33 | + |
| 34 | +namespace App\Application\Http\Handler; |
| 35 | + |
| 36 | +use Antidot\Queue\Job; |
| 37 | +use Antidot\Queue\Producer; |
| 38 | +use Psr\Http\Message\ResponseInterface; |
| 39 | +use Psr\Http\Message\ServerRequestInterface; |
| 40 | +use Psr\Http\Server\RequestHandlerInterface; |
| 41 | +use Laminas\Diactoros\Response\JsonResponse; |
| 42 | + |
| 43 | +class HomePage implements RequestHandlerInterface |
| 44 | +{ |
| 45 | + private Producer $producer; |
| 46 | + |
| 47 | + public function __construct(Producer $producer) |
| 48 | + { |
| 49 | + $this->producer = $producer; |
| 50 | + } |
| 51 | + |
| 52 | + public function handle(ServerRequestInterface $request): ResponseInterface |
| 53 | + { |
| 54 | + // Send String Job of type "some_message_type" to "default" queue. |
| 55 | + $job1 = Job::create('default', 'some_message_type', 'Hello world!!'); |
| 56 | + $this->producer->enqueue($job1); |
| 57 | + |
| 58 | + // Send Array Job of type "other_message_type" to "other_queue" queue. |
| 59 | + $job2 = Job::create('other_queue', 'other_message_type', ['greet' => 'Hello world!!']); |
| 60 | + $this->producer->enqueue($job2); |
| 61 | + |
| 62 | + |
| 63 | + return new JsonResponse([ |
| 64 | + 'docs' => 'https://queue.antidotfw.io', |
| 65 | + 'Message' => 'Welcome to Antidot Framework Starter' |
| 66 | + ]); |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +then start listening a queue: |
| 72 | + |
| 73 | +```bash |
| 74 | +bin/console queue:start queue_name |
| 75 | +``` |
0 commit comments