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.
Illuminate\Bus) but extends to Google Cloud Pub/Sub for distributed scalability.Illuminate\Queue) but adds serverless scalability.ServiceProvider to initialize Pub/Sub clients as singletons.PubSub::publish()) for consistency with Laravel’s ecosystem..env may require additional security controls (e.g., secret rotation).| Risk Area | Mitigation Strategy |
|---|---|
| Vendor Lock-in | Abstract Pub/Sub logic behind interfaces (e.g., PubSubPublisherInterface) for future swaps (e.g., AWS SQS). |
| Error Handling | Use Laravel’s exception handling (e.g., App\Exceptions\Handler) to translate ApiException into domain-specific errors. |
| Performance | Benchmark batch publishing (e.g., PublisherClient::publish() with multiple messages) vs. Laravel’s queue batching. |
| Cold Starts | For serverless Laravel (e.g., Cloud Run), warm-up requests or connection pooling may be needed. |
| Schema Evolution | Monitor Google’s Pub/Sub API changes and update Laravel models/data contracts accordingly. |
Monolog integration possible.)PublisherClient/SubscriberClient as Laravel bindings.Event system to publish to Pub/Sub topics.PubSubQueue driver to offload jobs to Pub/Sub.pecl install grpc).config/pubsub.php).| Phase | Action | Laravel Integration Point |
|---|---|---|
| Discovery | Audit Laravel services emitting events/jobs to identify Pub/Sub candidates. | EventServiceProvider, Queue Workers |
| Pilot | Replace a single queue worker with Pub/Sub publishing (e.g., UserRegistered event). |
Event::dispatch(new UserRegistered()) |
| Hybrid | Route high-priority jobs to Pub/Sub, keep low-priority in Laravel queues. | Queue::later()->onConnection('pubsub') |
| Full Cutover | Migrate all async workflows to Pub/Sub; decommission legacy queues. | AppServiceProvider::boot() |
composer require google/cloud-pubsub..env:
GOOGLE_CLOUD_PROJECT=your-project
GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
PubSubService facade:
// app/Facades/PubSub.php
public static function publish(string $topic, array $data): void {
$client = app(PublisherClient::class);
$client->publish($topic, json_encode($data));
}
PublisherClient in PHPUnit:
$mock = Mockery::mock(PublisherClient::class);
$mock->shouldReceive('publish')->once();
google/cloud-pubsub for breaking changes (e.g., protobuf updates).json:validate rules.keyFile → credentials).GOOGLE_GRPC_VERBOSITY=DEBUG.google.auth.exceptions.DefaultCredentialsError → Verify GOOGLE_APPLICATION_CREDENTIALS.RESOURCE_EXHAUSTED → Check Google Cloud Pub/Sub quotas.publish delays → Optimize batching or switch to gRPC.telescope to track Pub/Sub message flow.laravel-debugbar for real-time metrics.How can I help you explore Laravel packages today?