streamx / ingestion-client-php
PHP ingestion client for StreamX - a Digital Experience Data Mesh.
Installs: 4
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/streamx/ingestion-client-php
Requires
- ext-json: *
- cloudevents/sdk-php: ^1.2
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- ext-curl: *
- ext-mbstring: *
- ext-xdebug: *
- donatj/mock-webserver: ^2.7
- nyholm/psr7: ^1.8
- phpunit/phpunit: ^9.5
README
StreamX PHP Ingestion Client enables sending CloudEvents to StreamX via its REST Ingestion Service.
Requirements
PHP 7.4 or higher
Compatibility
The Client is compatible with StreamX 2.x and StreamX Blueprints 3.x
Main entry points:
- StreamxClientBuilders - with which it's possible to create default or customized clients,
- StreamxClient - with which it's possible to create publishers
- Publisher - with which it's possible to make actual ingestions of CloudEvents
Example usage:
<?php // Start your local StreamX instance. // The sample assumes rest ingestion service is available at port 8080 and web server sink at port 8081. // Create test page to be published to StreamX. It can be created as an associative array: $page = ['content' => base64_encode('Hello, StreamX!')]; // It can also be created as a PHP object that follows the same schema: class Page { public string $content; public function __construct(string $content) { $this->content = base64_encode($content); } } $page = new Page('Hello, StreamX!'); // Note: in both approaches, the content has to be in Base64 format. // Create the client and a publisher dedicated to a specific channel: $ingestionClient = \Streamx\Clients\Ingestion\Builders\StreamxClientBuilders::create('http://localhost:8080')->build(); $publisher = $ingestionClient->newPublisher(); // Publish page $key = '/pages/page1.html'; $publishPageEvent = new \CloudEvents\V1\CloudEventImmutable( 'publish-event', 'my-source', 'com.streamx.blueprints.page.published.v1', $page, 'application/json', null, // data schema $key ); $publisher->send($publishPageEvent); // Now the page should be available at http://localhost:8081/pages/page1.html // Then, unpublish the page (data is not needed) $unpublishPageEvent = new \CloudEvents\V1\CloudEventImmutable( 'unpublish-event', 'my-source', 'com.streamx.blueprints.page.unpublished.v1', null, // data null, // data content type null, // data schema $key ); $publisher->send($unpublishPageEvent); // Now the page should be unpublished from http://localhost:8081/pages/page1.html
Installation
The recommended way to install the client is through Composer.
composer require streamx/ingestion-client-php
Run tests with coverage
- Install xdebug (with version that supports PHP 7.4):
pecl install xdebug-3.1.5
- Configure xdebug mode:
export XDEBUG_MODE=coverage
- Run tests with coverage and open results in web browser:
./vendor/bin/phpunit --coverage-text --coverage-html target/coverage-report open target/coverage-report/index.html