PHP code example of coinvestor / laravel-batchsqs

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

    

coinvestor / laravel-batchsqs example snippets


'connections' => [
        'batch-sqs' => [
            'driver'      => 'batch-sqs',
            'key'         => env('AWS_KEY', null),
            'secret'      => env('AWS_SECRET', null),
            'prefix'      => env('AWS_PREFIX', null),
            'queue'       => env('AWS_QUEUE', null),
            'region'      => env('AWS_REGION', null),
            'batch_size'  => 7,
        ],
// [...]


use \CoInvestor\BatchSQS\Queues\Events\BatchMessageReleasingEvent;
class BatchMessageReleasingEventListener
{
    public function handle(BatchMessageReleasingEvent $event)
    {
        $return = [];

        // If the message is 'foo' it should be changed to 'foobar'
        if ($event->message['MessageBody'] == 'foo') {
            $return['MessageBody'] = 'foobar';
        }
        // If the queue name ends in .norbert, the message should have a message group id consisting of 128 '1's
        if (preg_match('/.*\.norbert/', $event->queue)) {
            $return['MessageGroupId'] = str_repeat("1", 128);
        }

        return $return;
    }
}

use Illuminate\Support\Facades\Queue;

// Send all message batches to their respective queues
Queue::flush();

// Discard all message batches
Queue::flush(true);