123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?xml version="1.0" encoding='ISO-8859-1'?>
- <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
- "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
- <!-- Include general documentation entities -->
- <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
- %docentities;
- ]>
- <!-- Module User's Guide -->
- <chapter>
- <title>&adminguide;</title>
- <section>
- <title>Overview</title>
- <para>
- This module provides access to json-rpc services (operating over TCP/Netstrings).
- </para>
- <para>
- This module uses t_suspend() and t_continue() from the TM module.
- </para>
- <para>
- Note that after invoking an asyncronous operation, the processing
- will continue later, in another application process. Therefore, do not
- rely on variables stored in private memory, use shared memory if you
- want to get values after the processing is resumend (e.g., $shv(...)
- or htable $sht(...)).
- </para>
- </section>
- <section>
- <title>Dependencies</title>
- <section>
- <title>&kamailio; Modules</title>
- <para>
- The following modules must be loaded before this module:
- <itemizedlist>
- <listitem>
- <para>
- <emphasis>tm</emphasis> - transaction management.
- </para>
- </listitem>
- </itemizedlist>
- </para>
- </section>
- <section>
- <title>External Libraries or Applications</title>
- <para>
- The following libraries or applications must be installed before running
- &kamailio; with this module loaded:
- <itemizedlist>
- <listitem>
- <para>
- <emphasis>libjson (https://github.com/json-c/json-c/wiki)</emphasis>
- </para>
- </listitem>
- <listitem>
- <para>
- <emphasis>libevent</emphasis> - http://libevent.org/
- </para>
- </listitem>
- </itemizedlist>
- </para>
- </section>
- </section>
- <section>
- <title>Parameters</title>
- <section>
- <title><varname>servers</varname> (string)</title>
- <para>
- The servers providing the remote jsonrpc service. Format is "host1:port1,priority1 host2:port2,priority2". Requests to servers of the same priority will be distributed evenly (round robin). Server groups with higher priority are used first.
- </para>
- <example>
- <title>Set <varname>servers</varname> parameter</title>
- <programlisting format="linespecific">
- ...
- modparam("jsonrpc", "servers", "localhost:9999,2 10.10.0.1:9999,2 backup.server:9999,1")
- ...
- </programlisting>
- </example>
- </section>
- </section>
- <section>
- <title>Functions</title>
- <section>
- <title>
- <function moreinfo="none">jsonrpc_notification(method, parameters)</function>
- </title>
- <para>
- Invokes the remote 'method' with the given 'parameters' as a notification.
- Unlike jsonrpc_request (below), notifications do not receive a response.
- Script processing continues in the usual fashion as soon as the notification
- has been sent.
- </para>
- <para>
- The method and parameters can be a static string or dynamic string value with
- config variables.
- </para>
- <example>
- <title><function>jsonrpc_notification</function> usage</title>
- <programlisting format="linespecific">
- ...
- jsonrpc_notification("update_user", "{'id': 1234, 'name': 'Petros'}")
- ...
- </programlisting>
- </example>
- </section>
- <section>
- <title>
- <function moreinfo="none">jsonrpc_request(method, parameters, return_route, error_route, result_var)</function>
- </title>
- <para>
- Invokes the remote 'method' with the given 'parameters'.
- When the response is received, continues processing of the SIP request
- with the route[return_route]. If a timeout occurs, no servers can be reached,
- or a jsonrpc error message is received, continues process at route[error_route].
- In this case, the result_var will contain one of "timeout", "failure", or the error
- message received back from the jsonrpc server.
- </para>
- <para>
- The method, parameters, return_route, and error_route can be a static string or
- a dynamic string value with config variables.
- </para>
- <para>
- Since the SIP request handling is resumed in another process,
- the config file execution is lost. As mentioned above, only
- shared variables ($shv, etc) should be used for any value that
- will be needed when the script is resumed.
- </para>
- <para>
- The result is stored in the pseudo-variable 'result_var'. Since this
- variable is set <emphasis>after</emphasis> the response is received,
- it is possible to use a $var for this parameter.
- </para>
- <example>
- <title><function>jsonrpc_request</function> usage</title>
- <programlisting format="linespecific">
- ...
- jsonrpc_request("get_user", "{'id': 1234}", "RESPONSE", "ERROR", "$var(result)");
- ...
- route[RESPONSE] {
- xlog("Result received: $var(result)");
- ...
- }
- ...
- route[ERROR] {
- xlog("Error received: $var(result)");
- ...
- }
- ...
- </programlisting>
- </example>
- </section>
- </section>
- </chapter>
|