l2t / laravel-pubsub-queue
Laravel Pub/Sub Queue 支持
1.0.0
2022-05-13 17:32 UTC
Requires
- google/cloud-pubsub: ^1.36
This package is not auto-updated.
Last update: 2024-09-29 08:08:50 UTC
README
Laravel Pub/Sub Queue
如果您想在 Laravel 中获得 pub/sub 队列驱动程序的 support,这个包正是您所需要的。
请按照以下步骤进行安装或在我的博客上查看: https://learn2torials.com/a/laravel9-pub-sub-integration
如何安装此包
# install composer dependency
composer require l2t/laravel-pubsub-queue
# go to your laravel config/queue.php file and add following block
'connections' => [
// other settings
'pubsub' => [
'retries' => 3,
'driver' => 'pubsub',
'request_timeout' => 60,
'queue' => env('PUBSUB_DEFAULT_QUEUE'),
'project_id' => env('GOOGLE_CLOUD_PROJECT'),
'queue_prefix' => env('PUBSUB_QUEUE_PREFIX', ''),
'keyFilePath' => storage_path(env('GOOGLE_APPLICATION_CREDENTIALS')),
],
]
# let's create a directory in storage folder
mkdir -p storage/secrets
# add following new env variables in .env file
# google credentials
PUBSUB_DEFAULT_QUEUE=<topic-name>
GOOGLE_CLOUD_PROJECT=<project-name>
GOOGLE_APPLICATION_CREDENTIALS=secrets/<google-credentials>.json
# enable pub/sub queue driver in .env
QUEUE_CONNECTION=pubsub
如何将作业调度到 pub/sub 队列
# queue jobs to default topic
dispatch(new PubSubJob());
# queue jobs to specific topic
dispatch(new PubSubJob())->onQueue(env('PUBSUB_CUSTOM_QUEUE'));
# process the topic in pubsub
php artisan queue:work pubsub
# process the topic
php artisan queue:work --queue=<some-topic>
现在,您应该能够在 Laravel 项目中使用 pub/sub 队列了。