2017 © Pedro Peláez
 

library avro-rpc-php-generator

This library generates an Avro RPC client based on eliep/avro-rpc-php

image

eliep/avro-rpc-php-generator

This library generates an Avro RPC client based on eliep/avro-rpc-php

  • Sunday, August 21, 2016
  • by eliep
  • Repository
  • 3 Watchers
  • 2 Stars
  • 246 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

Avro RPC Generator

See Avro for a full documentation on Avro and its usage in PHP., (*1)

This library use avro-rpc-php as an implementation of the Avro RPC protocol in php., (*2)

Installation

composer require eliep/avro-rpc-php-generator

Protocol class Generation

The script is located in your vendor/bin folder:, (*3)

php vendor/bin/generate.php --help

Required arguments:, (*4)

  • --input (-i) dir : The folder containing your Avro protocol
  • --output (-o) dir : The folder where the protocol classes will be written

Optional argument:, (*5)

  • --prefix (-p) namespace: The namespace prefix of the output directory
  • --stringType (-s) : If the requestor will be used with a java implementation using String instead of CharSequence
  • --apcu (-a) : use APCu to cache the parsed protocol.

Namespacing

The generate script will respect the namespace defined in your avro protocol. For example, if you have define "my.avro" as your protocol namespace, the script: - create the folder My\Avro in the directory specified by the -o option. - use My\Avro for the generated php class., (*6)

Note: If the directory specified by the -o option has a namespace, you can use the option -p to specify it so that the namespace of the generated php class will use it., (*7)

The name of the generate class will be protocol name with the Requestor suffix (if your protocol's name is Protocol, the class name will be ProtocolRequestor);, (*8)

Protocol class Usage

For example, if your protocol is:, (*9)

{
 "namespace": "my.avro",
 "protocol": "Protocol",

 "types": [
     {"type": "record", "name": "SimpleRequest",
      "fields": [{"name": "subject",   "type": "string"}]
     },
     {"type": "record", "name": "SimpleResponse",
      "fields": [{"name": "something",   "type": "string"}]
     }
 ],

 "messages": {
    "requestSomething": {
      "request": [{"name": "message", "type": "SimpleRequest"}],
      "response": "SimpleResponse"
    }
  }
}

you can connect to an Avro RPC Server with, (*10)

use My\Avro\ProtocolRequestor

$serverHost = '127.0.0.1';
$serverPort = 1412;
try {
  $requestor = new ProtocolRequestor($serverHost, $serverPort);
} catch (\Exception $e) {
    // unable to reach the server.
}

The ProtocolRequestor set a temporary error handler to detect if the socket connection worked. If not, the constructor throw a php Exception., (*11)

The ProtocolRequestor class contains one function for each message in your protocol. These functions accept as many argument as defined by the corresponding message., (*12)

You can call:, (*13)

$response = $requestor->requestSomething(array("subject" => "ping"));

Example

An example is available in example/ folder., (*14)

  • Start a server
php bin/generate.php sample_rpc_server.php
  • Use the sample client
php bin/generate.php sample_rpc_client.php
  • Regenerate the sample client
php bin/generate.php --input example/avro/ --output example/ --prefix Example --stringType

The Versions

21/08 2016

dev-master

9999999-dev https://github.com/eliep/avro-rpc-php-generator

This library generates an Avro RPC client based on eliep/avro-rpc-php

  Sources   Download

Apache-2.0

The Requires

 

by Avatar eliep

serialization rpc avro

21/08 2016

1.7.7-p2

1.7.7.0-patch2 https://github.com/eliep/avro-rpc-php-generator

This library generates an Avro RPC client based on eliep/avro-rpc-php

  Sources   Download

Apache-2.0

The Requires

 

by Avatar eliep

serialization rpc avro

20/08 2016

1.7.7-p1

1.7.7.0-patch1 https://github.com/eliep/avro-rpc-php-generator

This library generates an Avro RPC client based on eliep/avro-rpc-php

  Sources   Download

Apache-2.0

The Requires

 

by Avatar eliep

serialization rpc avro

20/08 2016

1.7.7-p0

1.7.7.0-patch https://github.com/eliep/avro-rpc-php-generator

This library generates an Avro RPC client based on eliep/avro-rpc-php

  Sources   Download

Apache-2.0

The Requires

 

by Avatar eliep

serialization rpc avro