quinluong/miczone-wrapper-php

There is no license information available for the latest version (1.0.2) of this package.

Miczone wrapper for php

1.0.2 2021-08-17 04:26 UTC

README

Installation

This library can be installed via Composer:

composer require quinluong/miczone-wrapper-php

Test

./vendor/phpunit/phpunit/phpunit --verbose tests
./vendor/phpunit/phpunit/phpunit --verbose tests/Miczone/Wrapper/MiczoneCatalogClient/GatewayTest.php --filter testPing
./vendor/phpunit/phpunit/phpunit --repeat 10 --verbose tests

EventBus

Prerequisite libraries

In order to use this library, must be install by following https://github.com/arnaud-lb/php-rdkafka#installation

Usage

Notifier

use Miczone\Wrapper\MiczoneEventBusClient\Notifier;
use Miczone\Thrift\EventBus\NotifyMessageResponse;

$client = new Notifier([
    'hosts' => '127.0.0.1:1234',
    'clientId' => 'my-service',
    'auth' => 'user:pass',
    'topics' => 'topicA,topicB',
    'numberOfRetries' => 3 // optional
]);

// Async
$client->ow_notifyString([
    'topic' => 'topicA',
    'key' => 'my-key', // to keep packages in order if they have the same key
    'data' => '{}' // data type can be Boolean / Integer / Double / String
], function () {
    // Success callback
}, function ($ex) {
    // Error callback
});

// Sync, type of $response is NotifyMessageResponse
$response = $client->notifyString([
    'topic' => 'topicB',
    'key' => 'my-key',
    'data' => '{}',
]);

Watcher

use Miczone\Wrapper\MiczoneEventBusClient\Watcher;
use Miczone\Wrapper\MiczoneEventBusClient\WatcherHandler\StringWatcherHandlerInterface;

$client = new Watcher([
    'hosts' => '127.0.0.1:1234',
    'clientId' => 'my-service',
    'groupId' => 'my-group',
    'topics' => 'topicA,topicB'
]);


/**
 * Handler interface can be:
 * - BooleanWatcherHandlerInterface
 * - IntegerWatcherHandlerInterface
 * - DoubleWatcherHandlerInterface
 * - StringWatcherHandlerInterface
 */
$client->setHandler(new class implements StringWatcherHandlerInterface {
    public function onMessage(string $topic, int $partition, int $offset, int $timestamp, string $key = null, string $data = null) {
        // Do your stuff
    }

    public function onError($code, string $message, \Exception $exception = null) {
        // Catch error
    }
});

$client->start();