NOVA 配套工具¶

nova 命令行工具¶

  • 单文件轻量级nova命令行客户端 (php 5.6+ & swoole);
  • 内部泛化调用实现,手工编解码,不依赖具体nova-service Thrift stub包;

安装¶

  1. php zanphp/src/toolkil/nova.php install

参数说明¶

  1. Usage: nova -h主机 -p端口 -m方法 -a参数
  2. -h nova 服务主机
  3. -p nova 服务端口
  4. -m nova服务.nova方法
  5. 例如(以下方thrift为例)
  6. ${thrift-namespace}.${thrift-service}.${thrift-method}
  7. com.yourcompany.demo.service.demoService.returnString
  8. -a nova服务参数, json字符串
  9. 例如 complexMethod 方法
  10. '{"paraBool":true, "paraI32": 42,"paraDouble":3.14, "paraString":"hello", "baseStruct":{}, "returnList":[{}], "returnSet":{}, "returnMap":{}, "errorLevel":1}'

使用¶

服务 tcp-demo 项目服务:

  1. namespace nova com.yourcompany.demo.service
  2.  
  3. service DemoService {
  4. void throwException() throws (1:DemoServiceException.DemoServiceException e);
  5.  
  6. void returnVoid();
  7.  
  8. bool returnBool();
  9. i32 returnI32();
  10. double returnDouble();
  11. string returnString();
  12. ErrorLevel.ErrorLevel returnEnum();
  13.  
  14.  
  15. BaseStruct.BaseStruct returnBaseStruct();
  16. MixedStruct.MixedStruct returnMixedStruct();
  17. list<BaseStruct.BaseStruct> returnList();
  18. set<BaseStruct.BaseStruct> returnSet();
  19. map<string, BaseStruct.BaseStruct> returnMap();
  20.  
  21. void paraBaseNoReturn(1:string paraString, 2:ErrorLevel.ErrorLevel errorLevel);
  22.  
  23. void paraMixedNoReturn (
  24. 1:bool paraBool,
  25. 2:i32 paraI32,
  26. 3:double paraDouble,
  27. 4:string paraString,
  28. 5:BaseStruct.BaseStruct baseStruct,
  29. 6:list<BaseStruct.BaseStruct> returnList,
  30. 7:set<BaseStruct.BaseStruct> returnSet,
  31. 8:map<string, BaseStruct.BaseStruct> returnMap,
  32. 9:ErrorLevel.ErrorLevel errorLevel
  33. );
  34.  
  35. map<string, BaseStruct.BaseStruct> complexMethod(
  36. 1:bool paraBool,
  37. 2:i32 paraI32,
  38. 3:double paraDouble,
  39. 4:string paraString,
  40. 5:BaseStruct.BaseStruct baseStruct,
  41. 6:list<BaseStruct.BaseStruct> returnList,
  42. 7:set<BaseStruct.BaseStruct> returnSet,
  43. 8:map<string, BaseStruct.BaseStruct> returnMap,
  44. 9:ErrorLevel.ErrorLevel errorLevel
  45. )
  46. }
  1. nova -h127.0.0.1 -p8100 -mcom.yourcompany.demo.service.returnVoid -a='{}'
  2.  
  3. {
  4. "code": 0,
  5. "message": "Service \"Com\\Yourcompany\\Demo\\Service\" not found"
  6. }
  1. nova -h127.0.0.1 -p8100 -mcom.yourcompany.demo.service.demoService.returnVoid -a '{}'
  2.  
  3. null
  1. nova -h127.0.0.1 -p8100 -mcom.yourcompany.demo.service.demoService.returnString -a '{}'
  2.  
  3. "aaaaaaaaaaaaaaaaaaaa"
  1. nova -h127.0.0.1 -p8100 -mcom.yourcompany.demo.service.demoService.returnBaseStruct -a '{}'
  2.  
  3. {
  4. "propBool": true,
  5. "propByte": "a",
  6. "propI16": 10,
  7. "propI32": 100,
  8. "propI64": 1000,
  9. "propDouble": 1000,
  10. "propString": "BaseStruct",
  11. "errorLevel": null
  12. }
  1. nova -h127.0.0.1 -p8100 -mcom.yourcompany.demo.service.demoService.paraBaseNoReturn -a '{}'
  2.  
  3. {
  4. "code": 0,
  5. "message": "Too few arguments to paraBaseNoReturn, 0 passed and at least 2 expected"
  6. }
  1. nova -h127.0.0.1 -p8100 -mcom.yourcompany.demo.service.demoService.complexMethod -a '{"paraBool":true}'
  2.  
  3. {
  4. "code": 0,
  5. "message": "Too few arguments to complexMethod, 1 passed and at least 9 expected"
  6. }
  1. nova -h127.0.0.1 -p8100 -mcom.yourcompany.demo.service.demoService.complexMethod -a '{"paraBool":true, "paraI32": 42,"paraDouble":3.14, "paraString":"hello", "baseStruct":null, "returnList":[1,2,3], "returnSet":null, "returnMap":null, "errorLevel":1}'
  2.  
  3. {
  4. "code": 0,
  5. "message": "Invalid <baseStruct> type, expects object"
  6. }
  1. nova -h127.0.0.1 -p8100 -mcom.yourcompany.demo.service.demoService.complexMethod -a '{"paraBool":true, "paraI32": 42,"paraDouble":3.14, "paraString":"hello", "baseStruct":{}, "returnList":[1,2,3], "returnSet":null, "returnMap":null, "errorLevel":1}'
  2.  
  3. {
  4. "code": 0,
  5. "message": "Invalid <returnList[0]> type, expects object"
  6. }
  1. nova -h127.0.0.1 -p8100 -mcom.yourcompany.demo.service.demoService.complexMethod -a '{"paraBool":true, "paraI32": 42,"paraDouble":3.14, "paraString":"hello", "baseStruct":{}, "returnList":[{}], "returnSet":{}, "returnMap":{}, "errorLevel":1}'
  2.  
  3. {
  4. "paraBool": true,
  5. "paraI32": 42,
  6. "paraDouble": 3.1400000000000001,
  7. "paraString": "hello",
  8. "baseStruct": {
  9. "propBool": null,
  10. "propByte": null,
  11. "propI16": null,
  12. "propI32": null,
  13. "propI64": null,
  14. "propDouble": null,
  15. "propString": null,
  16. "errorLevel": null
  17. },
  18. "returnList": [
  19. {
  20. "propBool": null,
  21. "propByte": null,
  22. "propI16": null,
  23. "propI32": null,
  24. "propI64": null,
  25. "propDouble": null,
  26. "propString": null,
  27. "errorLevel": null
  28. }
  29. ],
  30. "returnSet": [],
  31. "returnMap": [],
  32. "errorLevel": 1
  33. }

原文: http://zanphpdoc.zanphp.io/nova/tools.html