Esempio n. 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $services = $this->getContainer()->getParameter('thrift.config.services');
     $service = $input->getArgument('service');
     $method = $input->getArgument('method');
     $args = $input->getArgument('args');
     if (!isset($services[$service])) {
         $output->writeln(sprintf('<error>Unknow service: %s</error>', $service));
         return false;
     }
     // Instantiate client
     $thriftClient = new ThriftClient($this->getContainer()->get('thrift.factory'), array('service_config' => $services[$service], 'service' => $service, 'type' => $input->getOption('mode'), 'hosts' => array($service => array('host' => $input->getOption('host'), 'port' => $input->getOption('port'), 'recvTimeout' => $input->getOption('recvTimeout')))));
     $time_start = microtime(true);
     try {
         $client = $thriftClient->getClient();
         if (count($args) > 0) {
             $result = call_user_func_array(array($client, $method), $args);
         } else {
             $result = call_user_func(array($client, $method));
         }
         $end = microtime(true) - $time_start;
         $output->writeln(print_r($result, true));
         $output->writeln(sprintf('<info>Time taken for request: %s ms</info>', $end));
     } catch (\ThriftModel\User\InvalidValueException $e) {
         $output->writeln(sprintf('<error>Error Code: %s</error>', $e->getCode()));
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     } catch (\Thrift\Exception\TException $e) {
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
         $output->writeln(sprintf('<info>Have you started the server with: php app/console thrift:server %s ?</info>', $service));
         return false;
     } catch (\Exception $e) {
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     }
     return 0;
 }
Esempio n. 2
0
 public function testMultiSocketClient()
 {
     $thriftClient = new ThriftClient($this->factory, array('service' => 'test', 'type' => 'socket', 'hosts' => array('test' => array('host' => 'localhost', 'port' => 9090), 'test2' => array('host' => 'localhost', 'port' => 9091)), 'service_config' => array('definition' => 'Test', 'className' => 'TestService', 'namespace' => 'ThriftModel\\Test', 'protocol' => 'Thrift\\Protocol\\TBinaryProtocolAccelerated')));
     $this->assertInstanceOf('ThriftModel\\Test\\Test', $thriftClient->getFactory('ThriftModel\\Test\\Test'));
     // Server doesn't exists
     try {
         $thriftClient->getClient();
     } catch (\Exception $e) {
         $this->assertInstanceOf('Thrift\\Exception\\TException', $e);
     }
 }