gepard/gepard-php

PHP client for gepard:General purpose communications for distributed applications / Microservices / events, semaphores and messages for JavaScript, Java, Python and PHP

dev-master 2017-08-09 21:35 UTC

This package is not auto-updated.

Last update: 2024-04-13 17:19:06 UTC


README

General purpose communication and synchronization layer for distributed applications / Microservices / events, semaphores, locks and messages for JavaScript, Java, Python and PHP

Overview

This PHP module implements a simple client for the GEPARD middleware for general purpose distributed applications.

In order to use this PHP client you must have installed the GEPARD middleware. This is simply done by executing the command:

	npm install gepard

Prerequisite for this command is the installation of node and npm. For more information see gepard on npm and gessinger-hj/gepard on github.

If you are interested in the python client see gepard-python on pypi and gepard-python on github

Install

If you not yet have a composer.json create this file with the following content:

{
    "require": {
        "gepard/gepard-php": ">=1.0"
    },
    "minimum-stability": "dev" 
}

If this composer.json file already exists in your project-directory add the body-lines above. After this is done execute the command:

composer install

Usecases

Updating a Customer-record in the Database

Suppose there is a database containing customer base-data like for example name, id, enabled,...

The access to the database for example is done with laravel/eloquent. The UPDATE is coded with the following code-snippet:

$customer_Id = 1 ;
$customer = App\Customer::find($customer_id);

$customer->name = 'New Customer Name';

$customer->save();

Interested 3rd parties now are informed by sending an Event:

Client::getInstance()->emit('CUSTOMER_CHANGED', ['CUSTOMER_ID' => $customer_id]);

Interested parties for example are:

  • A Java program which sends an e-mail.

     Client.getInstance().on ( new String[] { "CUSTOMER_CHANGED" }, (e) -> {
     	Integer customer_id = e.getValue ( "CUSTOMER_ID" ) ;
    
     	*select customer from database with customer_id*
     	*use any mail-api to send mail*
     } ) ;
  • A JavaScript program which sends an e-mail:

     gepard.getClient().on ( 'CUSTOMER_CHANGED', (e) => {
     	let customer_id = e.getValue ( 'CUSTOMER_ID' ) ;
    
     	*select customer from database with customer_id*
     	*use any mail-api to send mail*
     } ) ;
  • A Python program which sends an e-mail:

     def on_CUSTOMER_CHANGED ( event ):
     	customer_id = event.getValue ( 'CUSTOMER_ID' ) ;
    
     	*select customer from database with customer_id*
     	*use any mail-api to send mail*
    
     gepard.Client.getInstance().on ( 'CUSTOMER_CHANGED', on_CUSTOMER_CHANGED ) ;
  • A single page web-app or a React-native app

     gepard.getWebClient().on ( 'CUSTOMER_CHANGED', (e) => {
     	let customer_id = e.getValue ( 'CUSTOMER_ID' ) ;
    
     	if ( customer-data are displayed in any part of the page ) {
     		*select customer from database with customer_id via a REST call*
     		*update appropriate display*
     	}
     } ) ;