PHP code example of offload-project / laravel-google-pubsub
1. Go to this page and download the library: Download offload-project/laravel-google-pubsub library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
offload-project / laravel-google-pubsub example snippets
ProcessPodcast::dispatch($podcast);
// Dispatch to a specific topic
ProcessPodcast::dispatch($podcast)->onQueue('audio-processing');
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',
]);
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));