tdonselaar/googlecloud-pubsub-laravel-queue-driver

为 Laravel/Lumen 队列提供的 Google Cloud PubSub 驱动程序。

1.1.2 2024-01-01 12:06 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:36:01 UTC


README

为 Laravel/Lumen 队列提供 Google Cloud PubSub 驱动程序。

CI Minimum PHP Version Software License

安装

您可以通过以下命令使用 Composer 安装此包:

composer require twipi-group/googlecloud-pubsub-laravel-queue-driver

Laravel

将以下行添加到您的 config/app.php 文件的自动加载服务提供者中,以注册此包:

TwipiGroup\GoogleCloudPubSubLaravelQueueDriver\GcServiceProviderQueue::class,

Lumen

对于 Lumen 的使用,应该在您的 bootstrap/app.php 文件中手动注册服务提供者,如下所示:

$app->configure('queue');
$app->register(TwipiGroup\GoogleCloudPubSubLaravelQueueDriver\GcServiceProviderQueue::class);

配置

在您的 config/queue.php 文件中添加名为 gcpubsub 的新连接。您可以直接从您的 .env 文件中自定义以下选项。

'gcpubsub' => [
    'driver' => 'gcpubsub',
    'project_id' => env('PUBSUB_PROJECT_ID', 'google-cloud-project-id'), // Google cloud project id
    'queue' => env('PUBSUB_QUEUE_DEFAULT', 'default'), // Default queue name corresponding to the gc pubsub topic
    'topic_suffix' => env('PUBSUB_TOPIC_SUFFIX', ''),
    'subscriber_suffix' => env('PUBSUB_SUBSCRIBER_SUFFIX', ''),
    'max_tries' => env('PUBSUB_JOB_MAX_TRIES', 1), // Number of times the job may be attempted.
    'retry_delay' => env('PUBSUB_JOB_RETRY_DELAY', 0), // Delay in seconds before retrying a job that has failed 
],

运行队列工作进程

您可以使用 queue:work Artisan 命令运行工作进程。(Laravel 文档

php artisan queue:work gcpubsub [--queue=myqueue]

当您的 .env 文件中的 APP_DEBUG=true 时,您可以从队列工作进程输出中检查 Google Cloud 订阅者。

测试

vendor/bin/phpunit tests

贡献

您可以通过发现错误、打开问题或提出新功能来为此包做出贡献。

许可

该项目根据 MIT 许可证的条款许可。有关更多信息,请参阅许可文件。