An HTTP adapter for the php-pubsub package

1.0.0 2017-05-24 06:47 UTC

This package is auto-updated.

Last update: 2024-05-11 23:41:22 UTC


An HTTP adapter for the php-pubsub package.

Author Build Status StyleCI Software License Packagist Version Total Downloads

This adapter assumes that you have a HTTP service which accepts an array of messages POSTed to a /messages/(channel) end-point.

A server-side implementation, js-pubsub-rest-proxy, is available as a plug and play Docker appliance.


composer require superbalist/php-pubsub-http


putenv('GOOGLE_APPLICATION_CREDENTIALS=' . __DIR__ . '/../your-gcloud-key.json');

// create the underlying adapter which is going to be decorated
$pubSubClient = new \Google\Cloud\PubSub\PubSubClient([
    'projectId' => 'your-project-id-here',

$subscribeAdapter = new \Superbalist\PubSub\GoogleCloud\GoogleCloudPubSubAdapter($pubSubClient);

// now create our decorator
// the decorator will proxy subscribe calls straight to the $subscribeAdapter
// publish calls will be POSTed to the service uri
$client = new \GuzzleHttp\Client();

$adapter = new \Superbalist\PubSub\HTTP\HTTPPubSubAdapter($client, '', $subscribeAdapter);

// consume messages
$adapter->subscribe('my_channel', function ($message) {

// publish messages
$adapter->publish('my_channel', 'HELLO WORLD');
$adapter->publish('my_channel', ['hello' => 'world']);

// publish multiple messages
$messages = [
    'Hello World!',
    ['hello' => 'world'],
$adapter->publishBatch('my_channel', $messages);


The library comes with examples for the adapter and a Dockerfile for running the example scripts.

Run make up.

You will start at a bash prompt in the /opt/php-pubsub directory.

If you need another shell to publish a message to a blocking consumer, you can run docker-compose run php-pubsub-http /bin/bash

To run the examples:

$ ./
$ ./ (in a separate shell)