Azure Storage Queue for Laravel based on triggered Azure Functions.
digitalclaim/azure-queue-laravel is a Laravel package for azure storage queue for laravel based on triggered azure functions..
It currently has 3 GitHub stars and 314 downloads on Packagist (latest version v1.0.0-beta2).
Install it with composer require digitalclaim/azure-queue-laravel.
Discover more Laravel packages by digitalclaim
or browse all Laravel packages to compare alternatives.
Last updated
Azure Storage Queue for Laravel. This works fundamentally different than the normal Laravel queue worker. We will push items to the storage queue as usual, but instead of constant pulling with something like queue:liste we use Azure Storage Queue trigger to call a Azure Function. The Azure Function will then call our Laravel app with the job payload to process it. There is no need to run a queue:work/listen command.
This package is inspired by stackkit/laravel-google-cloud-tasks-queue and based on squigg/azure-queue-laravel.
Warning: Currently we do not save failed jobs in any way. However, it's possible to use Laravel queue callbacks to do so.
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)
});
}
You can install the package via composer:
composer require digitalclaim/azure-queue-laravel
You can publish the config file with:
php artisan vendor:publish --tag="azure-queue-laravel-config"
With the config it is possible to set a custom repository for the payload. This is usefull when one has to work with messages > 64kb (Azure Limit). This is the contents of the published config file:
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),
],
];
Some example for a custom payload repository:
'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,
]);
}
},
],
config/queue.php'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
],
QUEUE_CONNECTION=azure
AZURE_QUEUE_STORAGE_NAME=YOUR_QUEUE_STORAGE_NAME
AZURE_QUEUE_KEY=YOUR_QUEUE_KEY
AZURE_QUEUE_NAME=YOUR_QUEUE_NAME
#AZURE_QUEUE_ENDPOINTSUFFIX=core.windows.net
#AZURE_QUEUE_ENDPOINT=https
const axios = require("axios");
module.exports = async function (context, myQueueItem, more) {
await instance.post(process.env["QUEUE_CALLBACK_URL"], {
id: context.triggerMetadata.id,
message: queueItem,
meta: {
dequeueCount: context.triggerMetadata.dequeueCount,
expirationTime: context.triggerMetadata.expirationTime,
insertionTime: context.triggerMetadata.insertionTime,
nextVisibleTime: context.triggerMetadata.nextVisibleTime,
popReceipt: context.triggerMetadata.popReceipt,
},
});
};
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.