PHP code example of renatomaldonado / laravel-sqs-consume

1. Go to this page and download the library: Download renatomaldonado/laravel-sqs-consume 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/ */

    

renatomaldonado / laravel-sqs-consume example snippets


// Add in your config/app.php

'providers' => [
    '...',
    'Renatomaldonado\LaravelSqsConsume\Provider\LaravelSQSQueueServiceProvider',
];

// Add in your bootstrap/app.php
$app->register(Renatomaldonado\LaravelSqsConsume\Provider\LumenSQSQueueServiceProvider::class);

// Generate standard config file (Laravel only)
php artisan vendor:publish --provider="Renatomaldonado\LaravelSqsConsume\Provider\LaravelSQSQueueServiceProvider" 

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

return [

    /**
     * Queues array for execute in each job
     */
    'queues' => ['queue-sqs-name-example', 'queue-sqs-name-example-two'],

    'handlers' => [
        'queue-sqs-name-example' => 'your-job',
        'queue-sqs-name-example-two' => 'your-job-two',
    ],

    'default-handler' => 'job-default'
];

        ...
        'sqs-consumer' => [
            'driver' => 'sqs-consumer',
            'key'    => env('AWS_KEY', ''),
            'secret' => env('AWS_SECRET', ''),
            'prefix' => 'https://sqs.ea-northheast-1.amazonaws.com/123456/',
            'queue'  => 'queue-sqs-name-example',
            'region' => 'ea-northheast-1',
        ],
        ...

use Illuminate\Contracts\Queue\Job as LaravelJob;

class ExempleJob extends Job
{
    protected $data;

    /**
     * @param LaravelJob $job
     * @param $data
     */
    public function handle(LaravelJob $job, $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());
    }
}