PHP code example of bernardwiesner / laravel-gcp-pubsub

1. Go to this page and download the library: Download bernardwiesner/laravel-gcp-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/ */

    

bernardwiesner / laravel-gcp-pubsub example snippets


<?
return [
    // rest or grcp
    'transport' => 'grcp',
    // ...
];

<?
return [
    // How many times to retry the request when it fails
    'retry' => 2,
    // How many milliseconds to wait after retry fails
    'retry_wait' => 100
];

    use PubSub;
    // ...
    PubSub::topic('your-topic')
    ->delaySeconds(30)
    ->publish(['your data'], [
        "your-attribute" => "your-value"
    ]);

class YourController extends Controller
{
    public function __invoke(Request $request): HttpResponse
    {
        $message = $request->message;
        $data = json_decode(base64_decode($message['data']), true);
    }
}

    public function handle(Request $request, Closure $next)
    {
        $availableAt = (int) ($request->message['attributes']['available_at'] ?? 0);
        if ($availableAt > time()) {
            return response()->noContent(409);
        }
        return $next($request);
    }


    use PubSub;
    // ...
    PubSub::publish('test-topic', [
        'data' => ['foo' => 1],
        'attributes' => [
            'bar' => 2,
        ]
    ], $delaySeconds = 10);

PubSub::fake();

$this->assertEquals(1, count(PubSub::getPublished()));

PubSub::assertPublished('your-topic');
sh
php artisan vendor:publish --tag=gcp-pubsub