README 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. jsonrpc-c (client) Module
  2. Matthew Williams
  3. <[email protected]>
  4. Edited by
  5. Jordan Levy
  6. <[email protected]>
  7. Copyright © 2011 Flowroute LLC (flowroute.com)
  8. __________________________________________________________________
  9. Table of Contents
  10. 1. Admin Guide
  11. 1. Overview
  12. 2. Dependencies
  13. 2.1. Kamailio Modules
  14. 2.2. External Libraries or Applications
  15. 3. Parameters
  16. 3.1. servers (string)
  17. 4. Functions
  18. 4.1. jsonrpc_notification(method, parameters)
  19. 4.2. jsonrpc_request(method, parameters, return_route,
  20. error_route, result_var)
  21. List of Examples
  22. 1.1. Set servers parameter
  23. 1.2. jsonrpc_notification usage
  24. 1.3. jsonrpc_request usage
  25. Chapter 1. Admin Guide
  26. Table of Contents
  27. 1. Overview
  28. 2. Dependencies
  29. 2.1. Kamailio Modules
  30. 2.2. External Libraries or Applications
  31. 3. Parameters
  32. 3.1. servers (string)
  33. 4. Functions
  34. 4.1. jsonrpc_notification(method, parameters)
  35. 4.2. jsonrpc_request(method, parameters, return_route,
  36. error_route, result_var)
  37. 1. Overview
  38. This module provides access to json-rpc services (operating over
  39. TCP/Netstrings).
  40. This module uses t_suspend() and t_continue() from the TM module.
  41. Note that after invoking an asyncronous operation, the processing will
  42. continue later, in another application process. Therefore, do not rely
  43. on variables stored in private memory, use shared memory if you want to
  44. get values after the processing is resumend (e.g., $shv(...) or htable
  45. $sht(...)).
  46. 2. Dependencies
  47. 2.1. Kamailio Modules
  48. 2.2. External Libraries or Applications
  49. 2.1. Kamailio Modules
  50. The following modules must be loaded before this module:
  51. * tm - transaction management.
  52. 2.2. External Libraries or Applications
  53. The following libraries or applications must be installed before
  54. running Kamailio with this module loaded:
  55. * libjson (https://github.com/json-c/json-c/wiki)
  56. * libevent - http://libevent.org/
  57. 3. Parameters
  58. 3.1. servers (string)
  59. 3.1. servers (string)
  60. The servers providing the remote jsonrpc service. Format is
  61. "host1:port1,priority1 host2:port2,priority2". Requests to servers of
  62. the same priority will be distributed evenly (round robin). Server
  63. groups with higher priority are used first.
  64. Example 1.1. Set servers parameter
  65. ...
  66. modparam("jsonrpc", "servers", "localhost:9999,2 10.10.0.1:9999,2 backup.server:
  67. 9999,1")
  68. ...
  69. 4. Functions
  70. 4.1. jsonrpc_notification(method, parameters)
  71. 4.2. jsonrpc_request(method, parameters, return_route, error_route,
  72. result_var)
  73. 4.1. jsonrpc_notification(method, parameters)
  74. Invokes the remote 'method' with the given 'parameters' as a
  75. notification. Unlike jsonrpc_request (below), notifications do not
  76. receive a response. Script processing continues in the usual fashion as
  77. soon as the notification has been sent.
  78. The method and parameters can be a static string or dynamic string
  79. value with config variables.
  80. Example 1.2. jsonrpc_notification usage
  81. ...
  82. jsonrpc_notification("update_user", "{'id': 1234, 'name': 'Petros'}")
  83. ...
  84. 4.2. jsonrpc_request(method, parameters, return_route, error_route,
  85. result_var)
  86. Invokes the remote 'method' with the given 'parameters'. When the
  87. response is received, continues processing of the SIP request with the
  88. route[return_route]. If a timeout occurs, no servers can be reached, or
  89. a jsonrpc error message is received, continues process at
  90. route[error_route]. In this case, the result_var will contain one of
  91. "timeout", "failure", or the error message received back from the
  92. jsonrpc server.
  93. The method, parameters, return_route, and error_route can be a static
  94. string or a dynamic string value with config variables.
  95. Since the SIP request handling is resumed in another process, the
  96. config file execution is lost. As mentioned above, only shared
  97. variables ($shv, etc) should be used for any value that will be needed
  98. when the script is resumed.
  99. The result is stored in the pseudo-variable 'result_var'. Since this
  100. variable is set after the response is received, it is possible to use a
  101. $var for this parameter.
  102. Example 1.3. jsonrpc_request usage
  103. ...
  104. jsonrpc_request("get_user", "{'id': 1234}", "RESPONSE", "ERROR", "$var(result)")
  105. ;
  106. ...
  107. route[RESPONSE] {
  108. xlog("Result received: $var(result)");
  109. ...
  110. }
  111. ...
  112. route[ERROR] {
  113. xlog("Error received: $var(result)");
  114. ...
  115. }
  116. ...