Skip to content

Commit f33a3bb

Browse files
committed
update plain mode doc
1 parent 57f1c68 commit f33a3bb

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,30 @@ Configure `config/queue.php`
136136
php artisan queue:work {connection-name} --queue={queue-name}
137137
```
138138

139-
#### Plain Mode (Experimental)
139+
#### Plain Mode
140+
141+
Configure `.env`
140142

141143
```
142144
CMQ_PLAIN_ENABLE=true
143145
CMQ_PLAIN_JOB=App\Jobs\CMQPlainJobHandler@handle
144146
```
145147

148+
Create a job implements `PlainPayload` interface.
149+
150+
The method `getPayload` must return a sting value.
151+
146152
```php
147153
<?php
148154

149155
namespace App\Jobs;
150-
156+
151157
use Illuminate\Bus\Queueable;
152158
use Illuminate\Queue\InteractsWithQueue;
153159
use Illuminate\Contracts\Queue\ShouldQueue;
154-
use Illuminate\Queue\Jobs\Job;
160+
use Freyo\LaravelQueueCMQ\Queue\Contracts\PlainPayload;
155161

156-
class CMQPlainJob implements ShouldQueue
162+
class CMQPlainJob implements ShouldQueue, PlainPayload
157163
{
158164
use InteractsWithQueue, Queueable;
159165

@@ -181,6 +187,8 @@ class CMQPlainJob implements ShouldQueue
181187
}
182188
```
183189

190+
Create a plain job handler
191+
184192
```php
185193
<?php
186194

@@ -192,16 +200,21 @@ class CMQPlainJobHandler
192200
{
193201
/**
194202
* Execute the job.
195-
*
203+
*
204+
* @param \Illuminate\Queue\Jobs\Job $job
205+
* @param string $payload
206+
*
196207
* @return void
197208
*/
198209
public function handle(Job $job, $payload)
199210
{
211+
// processing your payload...
212+
var_dump($payload);
213+
214+
// delete message when processed.
200215
if (! $job->isDeletedOrReleased()) {
201216
$job->delete();
202-
}
203-
204-
var_dump($payload);
217+
}
205218
}
206219
}
207220
```

src/Queue/Contracts/PlainPayload.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Freyo\LaravelQueueCMQ\Queue\Contracts;
4+
5+
interface PlainPayload
6+
{
7+
/**
8+
* Get the plain payload of the job.
9+
*
10+
* @return string
11+
*/
12+
public function getPayload();
13+
}

0 commit comments

Comments
 (0)