Download the PHP package bernardwiesner/laravel-gcp-pubsub without Composer

On this page you can find all versions of the php package bernardwiesner/laravel-gcp-pubsub. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-gcp-pubsub

Overview

Wrapper over Google Cloud PubSub for PHP.

This wrapper provides a convenient fluent API and has some usefull features such as timeout, retries and a delay API method. It also provides a mock facade for testing.

The recommended way to use this package is setting up a PubSub API with laravel that processes push subscription events from GCP pubsub. You can then publish topics from any of your microservices in laravel to GCP pubsub, and GCP will call your configured push subscription endpoints (APIs) to process the job. This is an alternative over using laravel queue for processing background jobs.

The advantage of using this package over laravel queue, is you can easily scale your APIs by simply adding more servers or containers. Another big advantage is it decouples your jobs from your code, there is no need to define your jobs in the same repo as from where they are dispatched/published, allowing for a firendlier microservice architecture. You could even process the jobs in another language other than PHP/laravel in one of your microservices.

For more details on how to setup a PubSub API with laravel refer to this guide.

Installation

Publish config

If you would like to adjust the retry attemps, or modify some of the other configurations you should publish the config:

Transport protocol

By default the wrapper is using http 1.1 REST. I have tested with gRPC and observed a slower response rate. If you would like to use gRPC instead you can modify the transport inside the gcp-pubsub.php config file:

Retry

GCP PubSub allows you to configure retries on the client, however this feature only works on certain response codes. This package's retry settings works on any failed request to GCP, including timeouts. By default retries are set to 2 times with a delay of 100 ms. You can modify these defaults in the gcp-pubsub.php file:

Fluent API

You can chain the API by using the fluent syntax:

publish

publish accepts 2 parameters, both arrays. The first is the message data which is required, and the second is the message attributes that is optional (refer to message format on GCP pubsub. The data parameter will always get json encoded by this package and base64 encoded if you use rest, so you need to json_decode and base64_decode the data when you receive the event from GCP pubsub. For example if you are using push subscriptions on pubsub, your laravel controller should decode as following:

delaySeconds

This will add an attribute called available_at to the request payload. You can use this attribute to determine if your job is due to be processed. For exampe if you configure your GCP pubsub subscription as push you can check the available_at attribute in your API and return early if the time is not yet met.

This is an example of a middleware you can use to return early:

Without fluent API

You can also opt to avoid using the fluent API and call the underlying API:

Testing

You can mock the PubSub facade in your test by doing:

You can also verify the topics published by doing:

You can also assert a single topic was published to:


All versions of laravel-gcp-pubsub with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
google/cloud-pubsub Version ^1.38
illuminate/support Version 5.7.* | 5.8.* | ^6.0 | ^7.0 | ^8.0 | ^9.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bernardwiesner/laravel-gcp-pubsub contains the following files

Loading the files please wait ....