offload-project/laravel-google-pubsub
Composer 安装命令:
composer require offload-project/laravel-google-pubsub
包简介
Google Cloud Pub/Sub for Laravel with full feature support
README 文档
README
A comprehensive Google Cloud Pub/Sub integration for Laravel that goes beyond a basic queue driver — a complete toolkit for event-driven architectures, microservice communication, and real-time data pipelines.
Features
- Full Laravel queue driver — drop-in replacement for any other queue connection
- Publisher / Subscriber services — direct publishing with compression, metadata, and batch support
- Event integration — bidirectional flow between Laravel events and Pub/Sub topics
- Webhook support — handle push subscriptions with built-in IP allowlist and token verification
- Schema validation — JSON Schema validation for message contracts
- Streaming support — real-time, lower-latency processing with StreamingPull
- CloudEvents support — industry-standard event formatting with v1.0 compatibility
- Dead-letter topics & retry policies — auto-wired for resilient message delivery
- Emulator support — local development with the Google Cloud Pub/Sub emulator
- Laravel Octane compatible — connection pooling and warm bindings
- Rich Artisan command set — manage topics, subscriptions, publishing, and listening from the CLI
Table of Contents
- Requirements
- Installation
- Quick Start
- Full Documentation
- AI Coding Assistant Skill
- Testing
- Contributing
- Security
- License
Requirements
- PHP 8.3+
- Laravel 11 / 12 / 13
- A Google Cloud project with the Pub/Sub API enabled (or the Pub/Sub emulator for local development)
Installation
composer require offload-project/laravel-google-pubsub php artisan vendor:publish --provider="OffloadProject\GooglePubSub\PubSubServiceProvider" --tag="config"
Add the basics to your .env:
QUEUE_CONNECTION=pubsub GOOGLE_CLOUD_PROJECT_ID=your-project-id # Authentication — pick one PUBSUB_AUTH_METHOD=application_default # or PUBSUB_AUTH_METHOD=key_file GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
Then add a pubsub connection to config/queue.php:
'connections' => [ 'pubsub' => [ 'driver' => 'pubsub', 'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'), 'queue' => env('PUBSUB_DEFAULT_QUEUE', 'default'), 'auth_method' => env('PUBSUB_AUTH_METHOD', 'application_default'), 'key_file' => env('GOOGLE_APPLICATION_CREDENTIALS'), 'auto_create_topics' => true, 'auto_create_subscriptions' => true, 'subscription_suffix' => '-laravel', 'enable_message_ordering' => false, ], ],
See the Configuration reference for every option.
Quick Start
1. Basic Queue Usage
Use it exactly like any other Laravel queue:
ProcessPodcast::dispatch($podcast); // Dispatch to a specific topic ProcessPodcast::dispatch($podcast)->onQueue('audio-processing');
2. Direct Publishing
use OffloadProject\GooglePubSub\Facades\PubSub; PubSub::publish('orders', [ 'order_id' => 123, 'total' => 99.99, 'customer_id' => 456, ]); // With attributes and an ordering key PubSub::publish('orders', $data, [ 'priority' => 'high', 'source' => 'api', ], [ 'ordering_key' => 'customer-456', ]);
3. Event Integration
use OffloadProject\GooglePubSub\Attributes\PublishTo; use OffloadProject\GooglePubSub\Contracts\ShouldPublishToPubSub; #[PublishTo('orders')] class OrderPlaced implements ShouldPublishToPubSub { public function __construct(public Order $order) {} public function pubsubTopic(): string { return 'orders'; } public function toPubSub(): array { return [ 'order_id' => $this->order->id, 'total' => $this->order->total, 'customer_id' => $this->order->customer_id, ]; } } event(new OrderPlaced($order));
4. Subscribing to Messages
use OffloadProject\GooglePubSub\Facades\PubSub; $subscriber = PubSub::subscribe('orders-processor', 'orders'); $subscriber->handler(function ($data, $message) { processOrder($data); }); $subscriber->listen();
Full Documentation
- Installation
- Configuration — every config key, with defaults
- Queue Driver
- Publisher & Subscriber
- Event Integration
- Webhooks (Push Subscriptions)
- Message Schemas and Validation
- CloudEvents
- Artisan Commands
- Monitoring & Debugging — performance tuning and troubleshooting
- Testing
- Examples
AI Coding Assistant Skill
This package ships a Laravel Boost skill so coding assistants (Claude Code, Cursor, etc.) follow the package's conventions when generating code. Install it in your app with:
php artisan boost:add-skill offload-project/laravel-google-pubsub
The skill source lives at skills/SKILL.md.
Testing
composer test
Contributing
Contributions are welcome! Please see the documents below before getting started.
- Contributing Guide — setup, workflow, commit conventions, and PR process
- Code of Conduct — expectations for participation in this project
Security
- Security Policy — how to report a vulnerability privately
License
The MIT License (MIT). Please see License File for more information.
offload-project/laravel-google-pubsub 适用场景与选型建议
offload-project/laravel-google-pubsub 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 128 次下载、GitHub Stars 达 8, 最近一次更新时间为 2025 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「google」 「cloud」 「laravel」 「pubsub」 「gcp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 offload-project/laravel-google-pubsub 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 offload-project/laravel-google-pubsub 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 offload-project/laravel-google-pubsub 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
PHP AMQP Binding Library
A Laravel package to monitor queue jobs.
UCloud Resource (Cloud) Storage SDK for PHP
The flysystem adapter for yandex disk rest api.
统计信息
- 总下载量: 128
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 23
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-16