How to use Google Cloud Pub/Sub as Laravel Queue Driver

Viewed 167

So I was following this tutorial on how to use pub sub as Laravel queue driver. but I am stuck as I was trying to run the worker with php artisan queue:work --queue=clcej which showed error

No connector for [pubsub]

this is the lines I added at my config/queue.php

        'default' => env('QUEUE_CONNECTION', 'pubsub'),
        'pubsub' => [
            'driver' => 'pubsub',
            'queue' => 'clcej',
            'queue_prefix' => env('PUBSUB_QUEUE_PREFIX', ''),
            'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'ciputra-nusantara'),
            'retries' => 3,
            'request_timeout' => 60,
        ],

I am still confused because in the tutorial there is no step where I have to set up the pub/sub in GCP

or is there easier and efficient way to run a queue worker on a serverless environment ?

1 Answers

Cloud Pub/Sub requires messages to be published to “topics” and then delivered to consumers using “subscriptions”. Our overview documentation can help you understand topic and subscription concepts. Both topics and subscriptions need to be created before they can be used.

The configuration section of the library docs indicate that you may need to change the queue section of your configuration to be 'queue' => env('PUBSUB_QUEUE', 'clcej'),.

Alternatively our quickstart can help you create topics/subscriptions on the Google Cloud console.

Or, you may use the gcloud CLI and follow the steps outlined in the gcloud quickstart to:

Create a topic with the ID my-topic

gcloud pubsub topics create my-topic

Create a subscription with the ID my-sub and attach it to my-topic:

gcloud pubsub subscriptions create my-sub --topic=my-topic

You can retry the tutorial after creating the topic/subscription.

Related