2017 © Pedro Peláez
 

library php-pubsub-http

An HTTP adapter for the php-pubsub package

image

superbalist/php-pubsub-http

An HTTP adapter for the php-pubsub package

  • Wednesday, July 26, 2017
  • by matthewgoslett
  • Repository
  • 22 Watchers
  • 1 Stars
  • 15,489 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 17 % Grown

The README.md

php-pubsub-http

An HTTP adapter for the php-pubsub package., (*1)

Author Build Status StyleCI Software License Packagist Version Total Downloads, (*2)

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

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

Installation

composer require superbalist/php-pubsub-http

Usage

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, 'https://127.0.0.1', $subscribeAdapter);

// consume messages
$adapter->subscribe('my_channel', function ($message) {
    var_dump($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);

Examples

The library comes with examples for the adapter and a Dockerfile for running the example scripts., (*5)

Run make up., (*6)

You will start at a bash prompt in the /opt/php-pubsub directory., (*7)

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

To run the examples:, (*9)

$ ./run_consumer.sh
$ ./run_publisher.sh (in a separate shell)

The Versions

26/07 2017

dev-master

9999999-dev

An HTTP adapter for the php-pubsub package

  Sources   Download

MIT

The Requires

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

24/05 2017

1.0.0

1.0.0.0

An HTTP adapter for the php-pubsub package

  Sources   Download

MIT

The Requires

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd