PHP code example of digitalclaim / azure-queue-laravel

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

    

digitalclaim / azure-queue-laravel example snippets


public function boot(): void
{
    Queue::before(function (JobProcessing $event) {
        // before processing
    });

    Queue::after(function (JobProcessed $event) {
        // after processing
    });

    Queue::exceptionOccurred(function (JobExceptionOccurred $event) {
        // on error (for each retry)
    });

    Queue::failing(function (JobFailed $event) {
        // on fail (after all retries)
    });
}

use DigitalClaim\AzureQueue\PayloadRepository;

return [
    'job' => [
        'payloadRepository' => PayloadRepository::class,
    ],
    'worker' => [
        'backoff' => env('DIGITALCLAIM_AZURE_QUEUE_LARAVEL_BACKOFF', 60 * 5),
        'maxTries' => env('DIGITALCLAIM_AZURE_QUEUE_LARAVEL_MAXTRIES', 3),
    ],
];


'job' => [
    'payloadRepository' => new class extends \DigitalClaim\AzureQueue\PayloadRepository
    {
        /**
         * get entry to load long message text
         */
        public function get(QueueMessage $message): string
        {
            $payload = json_decode($message->getMessageText(), true);

            $entry = ...; // load entry from you db

            return json_encode($entry['payload']);
        }

        /**
         * create entry to store long message text and returns the short message text (max 64kb) for the Azure Queue
         */
        public function create(string $payload): string
        {
            $payload = json_decode($payload, true);

            $id = ...; // save payload to db entry

            return json_encode([
                'id' => $id,
            ]);
        }
    },
],

'azure'      => [
    'driver' => 'azurepush', // Leave this as-is
    'protocol' => 'https', // https or http
    'accountname' => env('AZURE_QUEUE_STORAGE_NAME'), // Azure storage account name
    'key' => env('AZURE_QUEUE_KEY'), // Access key for storage account
    'queue' => env('AZURE_QUEUE_NAME'), // Queue container name
    'endpoint' => env('AZURE_QUEUE_ENDPOINTSUFFIX'), // Optional endpoint suffix if different from core.windows.net
    'queue_endpoint' => env('AZURE_QUEUE_ENDPOINT'), // Optional endpoint for custom addresses like http://localhost/my_storage_name
],
bash
php artisan vendor:publish --tag="azure-queue-laravel-config"