55[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/palpalani/laravel-sqs-queue-json-reader.svg?style=flat-square )] ( https://packagist.org/packages/palpalani/laravel-sqs-queue-json-reader )
66
77
8- Custom SQS queue reader for Laravel that supports plain JSON payloads.
8+ Custom SQS queue reader for Laravel projects that supports raw JSON payloads.
99Laravel expects SQS messages to be generated in a
1010specific format that includes job handler class and a serialized job.
1111
12+ Note: Implemented tm read multiple messages from queue.
13+
1214But in certain cases you may want to parse messages from 3rd party
1315applications, custom JSON messages and so on.
1416
@@ -28,18 +30,32 @@ php artisan vendor:publish --provider="palPalani\SqsQueueReader\SqsQueueReaderSe
2830This is the contents of the published config file:
2931
3032``` php
33+ /**
34+ * List of plain SQS queues and their corresponding handling classes
35+ */
3136return [
3237
33- /**
34- * Separate queue handle with corresponding queue name as key.
35- */
38+ // Separate queue handler with corresponding queue name as key.
3639 'handlers' => [
37- //'stripe-webhooks' => App\Jobs\StripeHandler::class,
38- //'mailgun-webhooks' => App\Jobs\MailgunHandler::class,
39- //'shopify-webhooks' => App\Jobs\ShopifyHandler::class,
40+ 'stripe-webhooks' => [
41+ 'class' => App\Jobs\StripeHandler::class,
42+ 'count' => 10,
43+ ],
44+ 'mailgun-webhooks' => [
45+ 'class' => App\Jobs\MailgunHandler::class,
46+ 'count' => 100,
47+ ]
4048 ],
4149
42- 'default-handler' => App\Jobs\SqsHandler::class
50+ // If no handlers specified then default handler will be executed.
51+ 'default-handler' => [
52+
53+ // Name of the handler class
54+ 'class' => App\Jobs\SqsHandler::class,
55+
56+ // Number of messages need to read from SQS.
57+ 'count' => 1,
58+ ]
4359];
4460```
4561
@@ -78,14 +94,12 @@ class ExampleController extends Controller
7894{
7995 public function index()
8096 {
81- // Create a PHP object
82- $object = [
97+ // Dispatch job with some data.
98+ $job = new DispatcherJob( [
8399 'music' => 'Sample SQS message',
100+ 'singer' => 'AR. Rahman',
84101 'time' => time()
85- ];
86-
87- // Pass it to dispatcher job
88- $job = new DispatcherJob($object);
102+ ]);
89103
90104 // Dispatch the job as you normally would
91105 // By default, your data will be encapsulated in 'data' and 'job' field will be added
@@ -99,7 +113,7 @@ class ExampleController extends Controller
99113Above code will push the following JSON object to SQS queue:
100114
101115``` json
102- {"job" :" App\\ Jobs\\ SqsHandler@handle" ,"data" :{"music" :" Sample SQS message" ,"time" :1464511672 }}
116+ {"job" :" App\\ Jobs\\ SqsHandler@handle" ,"data" :{"music" :" Sample SQS message" ,"singer" : " AR. Rahman " , " time" :1464511672 }}
103117```
104118
105119'job' field is not used, actually. It's just kept for compatibility with Laravel
0 commit comments