From 76fde327871b0b64e36d6d1cc556f3ac33ea4ee4 Mon Sep 17 00:00:00 2001 From: jquick <314127900@qq.com> Date: Tue, 21 Feb 2017 15:54:00 +0800 Subject: [PATCH] Update README.md detail example --- README.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3cf0e77..afb0e70 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,42 @@ composer require quickj/dubbo-php-client ###Usage ```php +require_once "src/dubboClient.php"; use \dubbo\dubboClient; + // options for register consumer // 注册消费者配置 + $options= array( - "registry_address" => "127.0.0.1:2181" + "registry_address" => "127.0.0.1:2181", + 'version' => '1.0.0', + 'group' =>null, + 'protocol' => 'jsonrpc' ); -$dubboCli = new dubboClient($options); -$HelloService = $dubboCli->getService("com.dubbo.demo.HelloService","1.0.0",null); -$ret = $HelloService->hello("dubbo php client"); -echo $ret; + +//try is must +try { + $dubboCli = new dubboClient($options); + $testService = $dubboCli->getService("com.dubbo.demo.HelloService"); + $ret = $testService->hello("dubbo php client"); + $mapRet = $testService->mapEcho(); + $objectRet = $testService->objectEcho(); + + var_dump($ret); + var_dump($mapRet); + var_dump($objectRet); + +} catch (Exception $e) { + print($e->getMessage()); +} + +/* getService method support 2 way. If the forceVgp = true, It will assign the function parameter to service version,group and protocol. Default way is assign the $options configs to these. + getService支持两种方式调用。如果forceVgp=true, 该方法将使用传参来绑定服务的版本号,组和协议。默认方式是使用$options数组里的配置绑定。 +*/ +$testServiceWithvgp = $dubboCli->getService("com.dubbo.demo.HelloService","1.0.0",null, $forceVgp = true); +var_dump($testServiceWithvgp->hello("this request from vgp")); + +``` ``` ###example ```bash @@ -79,16 +105,41 @@ composer require quickj/dubbo-php-client ``` ###如何使用 ```php +require_once "src/dubboClient.php"; use \dubbo\dubboClient; + // options for register consumer // 注册消费者配置 + $options= array( - "registry_address" => "127.0.0.1:2181" + "registry_address" => "127.0.0.1:2181", + 'version' => '1.0.0', + 'group' =>null, + 'protocol' => 'jsonrpc' ); -$dubboCli = new dubboClient($options); -$HelloService = $dubboCli->getService("com.dubbo.demo.HelloService","1.0.0",null); -$ret = $HelloService->hello("dubbo php client"); -echo $ret; + +//try is must +try { + $dubboCli = new dubboClient($options); + $testService = $dubboCli->getService("com.dubbo.demo.HelloService"); + $ret = $testService->hello("dubbo php client"); + $mapRet = $testService->mapEcho(); + $objectRet = $testService->objectEcho(); + + var_dump($ret); + var_dump($mapRet); + var_dump($objectRet); + +} catch (Exception $e) { + print($e->getMessage()); +} + +/* getService method support 2 way. If the forceVgp = true, It will assign the function parameter to service version,group and protocol. Default way is assign the $options configs to these. + getService支持两种方式调用。如果forceVgp=true, 该方法将使用传参来绑定服务的版本号,组和协议。默认方式是使用$options数组里的配置绑定。 +*/ +$testServiceWithvgp = $dubboCli->getService("com.dubbo.demo.HelloService","1.0.0",null, $forceVgp = true); +var_dump($testServiceWithvgp->hello("this request from vgp")); + ``` ###例子 ```bash