PHP code example of perspct / laravel-plain-sqs

1. Go to this page and download the library: Download perspct/laravel-plain-sqs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

perspct / laravel-plain-sqs example snippets


// Add in your config/app.php

'providers' => [
    '...',
    'Dusterio\PlainSqs\Integrations\LaravelServiceProvider',
];

// Add in your bootstrap/app.php
$app->loadComponent('queue', 'Dusterio\PlainSqs\Integrations\LumenServiceProvider');

// Generate standard config file (Laravel only)
php artisan vendor:publish

// In Lumen, create it manually (see example below) and load it in bootstrap/app.php
$app->configure('sqs-plain');

return [
    'handlers' => [
        'base-integrations-updates' => App\Jobs\HandlerJob::class,
    ],

    'default-handler' => App\Jobs\HandlerJob::class
];

        ...
        'sqs-plain' => [
            'driver' => 'sqs-plain',
            'key'    => env('AWS_KEY', ''),
            'secret' => env('AWS_SECRET', ''),
            'prefix' => 'https://sqs.ap-southeast-2.amazonaws.com/123123/',
            'queue'  => 'important-music-updates',
            'region' => 'ap-southeast-2',
        ],
        ...

use Dusterio\PlainSqs\Jobs\DispatcherJob;

class ExampleController extends Controller
{
    public function index()
    {
        // Create a PHP object
        $object = [
            'music' => 'M.I.A. - Bad girls',
            'time' => time()
        ];

        // Pass it to dispatcher job
        $job = new DispatcherJob($object);

        // 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 HandlerJob extends Job
{
    protected $data;

    /**
     * @param LaravelJob $job
     * @param array $data
     */
    public function handle(LaravelJob $job, array $data)
    {
        // This is incoming JSON payload, already decoded to an array
        var_dump($data);

        // Raw JSON payload from SQS, if necessary
        var_dump($job->getRawBody());
    }
}


QUEUE_DRIVER=sqs-plain