Skip to content
Alex Sherman edited this page Aug 2, 2016 · 2 revisions

There are two methods of invoking a remote RPC service. Either a direct call to MRPC.rpc specifying the path, or wrapping a path in an MRPC.Proxy to be called repeatedly. Both methods return an RPCRequest, which can be used to retrieve the response of the request synchronously or register callback functions to be executed when a response arrives.

##MRPC.rpc MRPC objects have an rpc method to invoke services on other MRPC nodes.

MRPC.rpc(self, path, value = None, timeout = 3, resend_delay = 0.5, transport = None) -> RPCRequest

###Path The path of the service(s) to be invoked.

###Value An optional JSON serializable value to use as an argument to the service

###Timeout Maximum time in seconds to wait for a response or responses, afterwards throwing a TimeoutError

###Resend Delay An interval in seconds to resend the RPC request while not all responses have come back and before a timeout

###Transport Optionally specify a specific transport to send the message over, used mostly internally.


##MRPC.Proxy Proxies can be used to wrap an MRPC path that will be used more than once. The resulting proxy behaves like a function and can be called similarly to MRPC.rpc without specifying a path.

MRPC.Proxy(path, **kwargs) -> MRPC.Proxy

Any kwargs passed to the constructor will be passed to MRPC.rpc, (timeout, resend_delay...)

Proxy(*args, **kwargs) -> RPCResult

Because services can only take a single argument, Proxies offer some convenient calling conventions. When called with multiple arguments a proxy will convert the arguments to either an array (if the arguments are not named) or an object (if the arguments are named). Proxies cannot be invoked with both named and unnamed arguments.

Proxy(value) => MRPC.rpc(Proxy.path, value, **Proxy.kwargs)
Proxy(value1, value2) => Proxy([value1, value2])
Proxy(key1 = value1, key2 = value2) => Proxy({key1: value1, key2: value2})
Clone this wiki locally