gdg-tangier / cloud-pubsub

Google Cloud Pub/Sub for Laravel
MIT License
48 stars 6 forks source link

Can't set up Pub/Sub for receiving play billing updates #29

Closed andrezanna closed 2 years ago

andrezanna commented 2 years ago

Hello, I'm not sure I understood how to setup the package, here i resume my tries.

after composer require i added in config/queue.php

/*
    |--------------------------------------------------------------------------
    | Pub-Sub Jobs for Play Store Billing Updates
    |--------------------------------------------------------------------------

    */

    'pubsub' => [
        'driver' => 'pubsub',
        'queue'  => env('SUBSCRIPTION'),
        'credentials' => [
            'keyFilePath' => storage_path(env('PUBSUB_CLIENT_KEY')), // credentials file path '.json'
            'projectId'   => env('GCP_PROJECT_ID'),
        ],
    ],

then created the file config/pubsub.php

<?php

return [
    /*
     * GCP Credentials.
     */
    'credentials' => [
        'keyFilePath' => storage_path(env('PUBSUB_CLIENT_KEY', 'client')),
        'projectId'   => env('GCP_PROJECT_ID'),
    ],

    /*
     * Here where you map events name with Google Pub/Sub topics.
     *
     * Means, map each event name to specific Google Pub/Sub topic.
     */
    'events'      => [
        'event_name' => 'Play-Store-Notifications',
    ],

    /*
     * Here where you can tie the subscription classes (jobs) to topics.
     *
     * Means, map each subscription job to a specific Google pubsub topic.
     * The subscription job is responsible for handling the incoming data
     * from a Google Pub/Sub topic.
     */
    'subscriptions'        => [
        \App\Subscribers\PlaySub::class => 'Play-Store-Notifications',
    ],
];

created the receiver class by doing

php artisan pubsub:make-subscriber PlaySub

pass to the server the service account json (i put it in root of project) and then added this lines to .env

PUBSUB_CLIENT_KEY=/var/www/html/pc-api-8658230392793226561-324-1fe7077700db.json
GCP_PROJECT_ID=pc-api-8658230392793226561-324
SUBSCRIPTION=play-billing

Then i tried to subscribe to this channel, since it will be only receiving updates from the store billing api and I won't send updates to it.

I tried with both commands: php artisan pubsub:subscribe play-billing php artisan pubsub:subscribe pubsub

but in both cases it returned me:

 InvalidArgumentException  : No connector for []

  at /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php:172
    168|      */
    169|     protected function getConnector($driver)
    170|     {
    171|         if (! isset($this->connectors[$driver])) {
  > 172|             throw new InvalidArgumentException("No connector for [$driver]");
    173|         }
    174| 
    175|         return call_user_func($this->connectors[$driver]);
    176|     }

  Exception trace:

  1   Illuminate\Queue\QueueManager::getConnector()
      /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php:156

  2   Illuminate\Queue\QueueManager::resolve("pubsub")
      /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php:138

As i'm not sure what the parameter SUBSCRIPTION should be, can you please explain me what I'm doing wrong or if this is not a suitable package for my usage.

Many thanks

amranidev commented 2 years ago

Hi @andrezanna, the package cannot find the credentials file path, in the config/queue.php and the config/pubsub.php, the keyFilePath has the storage_path as a reference, which mean when the package tries to get the file it hits {yout-project-folder}/storage//var/www/html/pc-api-8658230392793226561-324-1fe7077700db.json.

To solve this issue there are 2 solutions.

1 - Place the credentials file in the laravel storage folder. 2 - Reconfigure the keyFilePath in config/queue.php and the config/pubsub.php to use the correct path.

And yes this package is suitable for your usage. 👍

andrezanna commented 2 years ago

Ok thanks i figured it out.