Skip to content

Commit 89d8d95

Browse files
committed
upd laravel docs
1 parent 6b07486 commit 89d8d95

File tree

3 files changed

+111
-12
lines changed

3 files changed

+111
-12
lines changed

docs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- [Quick tour](async_event_dispatcher/quick_tour.md)
4141
* Laravel
4242
- [Quick tour](laravel/quick_tour.md)
43+
- [Queues](laravel/queues.md)
4344
* Magento
4445
- [Quick tour](magento/quick_tour.md)
4546
- [Cli commands](magento/cli_commands.md)

docs/laravel/queues.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Laravel Queue. Quick tour.
2+
3+
The [LaravelQueue](https://github.com/php-enqueue/laravel-queue) package allows to use [queue-interop](https://github.com/queue-interop/queue-interop) compatible transports [the Laravel way](https://laravel.com/docs/5.4/queues).
4+
I suppose you already [installed and configured](quick_tour.md) the package so let's look what you have to do to make queue work.
5+
6+
## Configure
7+
8+
You have to add a connector to `config/queues.php` file. The driver must be `interop`.
9+
10+
```php
11+
<?php
12+
13+
// config/queue.php
14+
15+
return [
16+
// uncomment to set it as default
17+
// 'default' => env('QUEUE_DRIVER', 'interop'),
18+
19+
'connections' => [
20+
'interop' => [
21+
'driver' => 'interop',
22+
'connection_factory_class' => \Enqueue\Fs\FsConnectionFactory::class,
23+
24+
// the factory specific options
25+
'dsn' => 'file://'.realpath(__DIR__.'/../storage').'/enqueue',
26+
],
27+
],
28+
];
29+
```
30+
31+
## Usage
32+
33+
Same as standard [Laravel Queues](https://laravel.com/docs/5.4/queues)
34+
35+
Send message example:
36+
37+
```php
38+
<?php
39+
40+
$job = (new \App\Jobs\EnqueueTest())->onConnection('interop');
41+
42+
dispatch($job);
43+
```
44+
45+
Consume messages:
46+
47+
```bash
48+
$ php artisan queue:work interop
49+
```
50+
51+
[back to index](../index.md)

docs/laravel/quick_tour.md

+59-12
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,77 @@ return [
2424
];
2525
```
2626

27-
## Configure
27+
## Laravel queues
2828

29-
First, you have to configure a transport layer and set one to be default.
29+
At this stage you are already able to use [laravel queues](queues.md).
30+
31+
## Enqueue Simple client
32+
33+
If you want to use [enqueue/simple-client](https://github.com/php-enqueue/simple-client) in your Laravel application you have perform additional steps .
34+
You have to install the client library, in addition to what you've already installed:
35+
36+
```bash
37+
$ composer require enqueue/simple-client
38+
```
39+
40+
Create `config/enqueue.php` file and put a client configuration there:
41+
Here's an example of what it might look like:
3042

3143
```php
3244
<?php
3345

34-
// config/queue.php
46+
// config/enqueue.php
3547

3648
return [
37-
'connections' => [
38-
'interop' => [
39-
'driver' => 'interop',
40-
'connection_factory_class' => \Enqueue\Fs\FsConnectionFactory::class,
41-
42-
// the factory specific options
43-
'dsn' => 'file://'.realpath(__DIR__.'/../storage').'/enqueue',
49+
'client' => [
50+
'transport' => [
51+
'default' => 'file://'.realpath(__DIR__.'/../storage/enqueue')
52+
],
53+
'client' => [
54+
'router_topic' => 'default',
55+
'router_queue' => 'default',
56+
'default_processor_queue' => 'default',
4457
],
4558
],
4659
];
4760
```
4861

49-
## Usage
62+
Register processor:
63+
64+
```php
65+
<?php
66+
use Enqueue\SimpleClient\SimpleClient;
67+
use Interop\Queue\PsrMessage;
68+
use Interop\Queue\PsrProcessor;
69+
70+
$app->resolving(SimpleClient::class, function (SimpleClient $client, $app) {
71+
$client->bind('enqueue_test', 'a_processor', function(PsrMessage $message) {
72+
// do stuff here
73+
74+
return PsrProcessor::ACK;
75+
});
76+
77+
return $client;
78+
});
79+
80+
```
81+
82+
Send message:
83+
84+
```php
85+
<?php
86+
use Enqueue\SimpleClient\SimpleClient;
87+
88+
/** @var SimpleClient $client */
89+
$client = \App::make(SimpleClient::class);
90+
91+
$client->sendEvent('enqueue_test', 'The message');
92+
```
93+
94+
Consume messages:
5095

51-
Same as standard [Laravel Queues](https://laravel.com/docs/5.4/queues)
96+
```bash
97+
$ php artisan enqueue:consume -vvv --setup-broker
98+
```
5299

53100
[back to index](../index.md)

0 commit comments

Comments
 (0)