}, "testNotification": { "doc" : "Notification : one-way message", "request": [{"name": "notification", "type": "Notification"}], "one-way": true }, "testRequestResponseException": { "doc" : "Request Response with Exception", "request": [{"name": "exception", "type": "RaiseException"}], "response" : "NeverSend", "errors" : ["AlwaysRaised"] } } } PROTO; $client = NettyFramedSocketTransceiver::create('127.0.0.1', 1411); $requestor = new Requestor(AvroProtocol::parse($protocol), $client); try { $response = $requestor->request('testSimpleRequestResponse', array("message" => array("subject" => "pong"))); echo "Response received: " . json_encode($response) . "\n"; $response = $requestor->request('testSimpleRequestResponse', array("message" => array("subject" => "ping"))); echo "Response received: " . json_encode($response) . "\n"; } catch (AvroRemoteException $e) { echo "Exception received: " . json_encode($e->getDatum()) . "\n"; } try { $response = $requestor->request('testSimpleRequestWithoutParameters', array()); echo "Response received: " . json_encode($response) . "\n"; } catch (AvroRemoteException $e) { echo "Exception received: " . json_encode($e->getDatum()) . "\n"; }
public function start($max_clients = 10) { $transceivers = array(); while (true) { // $read contains all the client we listen to $read = array($this->socket); for ($i = 0; $i < $max_clients; $i++) { if (isset($transceivers[$i]) && $transceivers[$i] != null) { $read[$i + 1] = $transceivers[$i]->socket(); } } // check all client to know which ones are writing $ready = socket_select($read, $write, $except, null); // $read contains all client that send something to the server // New connexion if (in_array($this->socket, $read)) { for ($i = 0; $i < $max_clients; $i++) { if (!isset($transceivers[$i])) { $transceivers[$i] = $this->use_netty_framed_transceiver ? NettyFramedSocketTransceiver::accept($this->socket) : SocketTransceiver::accept($this->socket); break; } } } // Check all client that are trying to write for ($i = 0; $i < $max_clients; $i++) { if (isset($transceivers[$i]) && in_array($transceivers[$i]->socket(), $read)) { $is_closed = $this->handle_request($transceivers[$i]); if ($is_closed) { unset($transceivers[$i]); } } } } socket_close($this->socket); }
public function __construct($host, $port) { $client = \NettyFramedSocketTransceiver::create($host, $port); parent::__construct(\AvroProtocol::parse(self::$json_protocol), $client); }