Documentation for pulsar 0.4.6. For development docs, go here.
Asynchronous WSGI Remote Procedure Calls middleware. It implements a JSON-RPC server and client.
To create a server first you create your rpc handler and (optional) subhandlers:
from pulsar.apps import rpc, wsgi
class Root(rpc.PulsarServerCommands):
pass
class Calculator(rpc.JSONRPC):
def rpc_add(self, request, a, b):
return float(a) + float(b)
def rpc_subtract(self, request, a, b):
return float(a) - float(b)
def rpc_multiply(self, request, a, b):
return float(a) * float(b)
def rpc_divide(self, request, a, b):
return float(a) / float(b)
Then you create the WSGI middleware:
def server():
root = Root().putSubHandler('calc',Calculator())
return wsgi.WSGIServer(callable=rpc.RpcMiddleware(root))
if __name__ == '__main__':
server().start()
A RpcHandler for class for JSON-RPC services. Design to comply with the JSON-RPC 2.0 Specification.
Overrides the RpcHandler:get_method_and_args() to obtain method data from the JSON data string.
Modify JSON dumps method to comply with JSON-RPC Specification 2.0
A python Proxy class for JSONRPC Servers.
| Parameters: |
|
|---|
Lets say your RPC server is running at http://domain.name.com/:
>>> a = JsonProxy('http://domain.name.com/')
>>> a.add(3,4)
7
>>> a.ping()
'pong'
Can be re-implemented by your own Proxy
Usefull little utility for timing responses from server. The usage is simple:
>>> from pulsar.apps import rpc
>>> p = rpc.JsonProxy('http://127.0.0.1:8060')
>>> p.timeit('ping',10)
0.56...
>>> _
Create an array or positional or named parameters Mixing positional and named parameters in one call is not possible.
A decorator which exposes a function func as an rpc function.
| Parameters: |
|
|---|
Return pong.
Return a dictionary of information regarding the server and workers. It invokes the extra_server_info() for adding custom information.
| Return type: | dict. |
|---|
Return the list of functions available in the rpc handler
| Return type: | list. |
|---|
| Parameters: | aid – pulsar.Actor.aid of the actor to kill |
|---|
Add additional information to the info dictionary.