digitalclaim / azure-queue-laravel
基于触发式Azure Functions的Laravel Azure存储队列。
v1.0.0-alpha4
2024-05-07 18:01 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^10.0
- nesbot/carbon: ^2.72
- spatie/laravel-package-tools: ^1.14.0
- squigg/azure-queue-laravel: ^11.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.5
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is auto-updated.
Last update: 2024-09-08 19:53:33 UTC
README
Azure Storage Queue for Laravel。这与常规的Laravel队列工作方式根本不同。我们像往常一样将项目推送到存储队列,但不是使用类似queue:liste
的持续拉取,而是使用Azure Storage Queue触发器调用Azure Function。然后,Azure Function将调用我们的Laravel应用,以工作负载的形式处理任务。无需运行queue:work/listen
命令。
此包受到stackkit/laravel-google-cloud-tasks-queue的启发,并基于squigg/azure-queue-laravel。
警告:目前我们没有以任何方式保存失败的任务。但是,可以使用Laravel队列回调来实现这一点。
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) }); }
安装
您可以通过composer安装此包
composer require digitalclaim/azure-queue-laravel
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="azure-queue-laravel-config"
这是已发布配置文件的内容
return [ 'worker' => [ 'backoff' => env('DIGITALCLAIM_AZURE_QUEUE_LARAVEL_BACKOFF', 60 * 5), // backoff time in seconds 'maxTries' => env('DIGITALCLAIM_AZURE_QUEUE_LARAVEL_MAXTRIES', 3), // max number of retries ], ];
使用方法
- 您已经设置了Azure App Service和存储账户
- 在
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 'timeout' => 60, // Seconds before a job is released back to the queue '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 https:///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
- 为新队列项目触发Azure Function App(nodejs)(请参阅https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-trigger)
const axios = require("axios"); module.exports = async function (context, myQueueItem, more) { try { const response = await axios.post( "https://YOURSITE.azurewebsites.net/handle-queue", { id: context.bindingData.id, message: myQueueItem, meta: { dequeueCount: context.bindingData.dequeueCount, expirationTime: context.bindingData.expirationTime, insertionTime: context.bindingData.insertionTime, nextVisibleTime: context.bindingData.nextVisibleTime, popReceipt: context.bindingData.popReceipt, }, } ); context.log(response.data); } catch (error) { // If the promise rejects, an error will be thrown and caught here context.log(error); } context.done(); };
测试
composer test
变更日志
请参阅CHANGELOG以获取有关最近更改的更多信息。
贡献
请参阅CONTRIBUTING以获取详细信息。
安全漏洞
请查看我们的安全策略,了解如何报告安全漏洞:我们的安全策略
鸣谢
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。