<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
palpalani / laravel-sqs-queue-json-reader example snippets
/**
* List of plain SQS queues and their corresponding handling classes
*/
return [
// Separate queue handler with corresponding queue name as key.
'handlers' => [
'stripe-webhooks' => [
'class' => App\Jobs\StripeHandler::class,
'count' => 10,
],
'mailgun-webhooks' => [
'class' => App\Jobs\MailgunHandler::class,
'count' => 10,
]
],
// If no handlers specified then default handler will be executed.
'default-handler' => [
// Name of the handler class
'class' => App\Jobs\SqsHandler::class,
// Number of messages need to read from SQS.
'count' => 1,
]
];
use palPalani\SqsQueueReader\Jobs\DispatcherJob;
class ExampleController extends Controller
{
public function index()
{
// Dispatch job with some data.
$job = new DispatcherJob([
'music' => 'Ponni nathi from PS-1',
'singer' => 'AR. Rahman',
'time' => time()
]);
// Dispatch the job as you normally would
// By default, your data will be encapsulated in 'data' and 'job' field will be added
$this->dispatch($job);
// If you wish to submit a true plain JSON, add setPlain()
$this->dispatch($job->setPlain());
}
}
use Illuminate\Contracts\Queue\Job as LaravelJob;
class SqsHandlerJob extends Job
{
/**
* @var null|array $data
*/
protected $data;
/**
* @param LaravelJob $job
* @param null|array $data
*/
public function handle(LaravelJob $job, ?array $data): void
{
// This is incoming JSON payload, already decoded to an array
var_dump($data);
// Raw JSON payload from SQS, if necessary
var_dump($job->getRawBody());
}
}