Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Cloud Pubsub

Cloud Pubsub Laravel Package

google/cloud-pubsub

Idiomatic PHP client for Google Cloud Pub/Sub. Publish and receive messages between services using REST or gRPC (including streaming). Install via Composer and authenticate with Google Cloud credentials for managed, real-time messaging.

View on GitHub
Deep Wiki
Context7

Cloud PubSub Client for PHP

Frequently asked questions about Cloud Pubsub
How do I integrate Google Cloud Pub/Sub with Laravel’s queue system for background jobs?
Replace Laravel’s `dispatch()` or queue workers by publishing messages via `PublisherClient->publish()`. For consumption, use `SubscriberClient->pull()` or streaming to trigger Laravel jobs or events. Bind the client to Laravel’s service container for dependency injection, then dispatch jobs from Pub/Sub callbacks (e.g., `HandlePubSubMessage::dispatch()`).
What’s the best way to authenticate this package in Laravel?
Use Laravel’s `config('services.google.cloud.keyFile')` for service account credentials or environment variables. The package supports Google’s Application Default Credentials (ADC) via `google/auth`. For simplicity, store your JSON key file path in `.env` and inject it into the `PublisherClient` or `SubscriberClient` constructor.
Should I use REST or gRPC for Laravel Pub/Sub integration? What are the trade-offs?
Use **REST** for simplicity and debugging (e.g., monitoring via HTTP logs). Switch to **gRPC** for high-throughput scenarios (e.g., real-time event processing) due to lower latency and streaming support. Start with REST in Laravel, then migrate critical paths to gRPC later for performance gains.
How do I handle message serialization between Laravel and Pub/Sub (e.g., JSON vs. Protobuf)?
Laravel’s JSON serialization works with Pub/Sub’s raw JSON messages. For custom schemas (Avro/Protobuf), validate messages in Pub/Sub before processing or use Laravel’s `json_encode()`/`json_decode()` for compatibility. The package supports schema validation via Pub/Sub’s built-in tools, reducing Laravel-side logic.
Can I use Pub/Sub to replace Laravel’s event system for cross-service communication?
Yes. Publish events to Pub/Sub topics instead of Laravel’s `event()` helper, then subscribe to topics in other services. Use Laravel’s service container to bind `SubscriberClient` and trigger events via middleware (e.g., `PubSubMessageReceived`). This decouples services while maintaining event-driven architecture.
What Laravel versions and PHP requirements does this package support?
The package is compatible with **PHP 8.1–8.4** and **Laravel 9+**. Tested with the latest Google Cloud PHP SDK, which aligns with Laravel’s dependency management. Ensure your `composer.json` enforces these versions to avoid compatibility issues.
How do I monitor Pub/Sub errors or dead-letter messages in Laravel?
Configure **dead-letter topics** in Pub/Sub subscriptions to route failed messages. Log errors in Laravel using Monolog by injecting the logger into the Pub/Sub client’s options. For observability, export metrics to Google Cloud Operations Suite via `google/cloud-operations` and integrate with Laravel’s logging channels.
Are there cost considerations for using Pub/Sub in production with Laravel?
Monitor **message volume** (publish/pull operations) and **storage** (retention duration) via Google Cloud’s billing alerts. Set `message_retention_duration` (default: 7 days) to balance cost and reliability. For high-throughput apps, batch publishing reduces costs, while streaming pull optimizes latency.
How do I migrate from Laravel queues to Google Cloud Pub/Sub step-by-step?
Start by replacing **1–2 Laravel queues** (e.g., `orders.created`) with Pub/Sub topics. Use `PublisherClient` to publish messages and `SubscriberClient` to trigger Laravel jobs. Gradually migrate internal queues to Pub/Sub for cross-service events, then adopt gRPC for performance-critical paths.
What alternatives exist for Laravel Pub/Sub-like functionality, and why choose this package?
Alternatives include **RabbitMQ** (self-hosted) or **AWS SQS/SNS** (cloud). This package excels for **Google Cloud users** due to native integration, gRPC support, and managed infrastructure. It’s ideal for Laravel apps needing **scalable, distributed messaging** with minimal operational overhead compared to self-hosted solutions.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai