4
4
zerorpc is a flexible RPC implementation based on zeromq and messagepack.
5
5
Service APIs exposed with zerorpc are called "zeroservices".
6
6
7
- zerorpc comes with a convenient script, "zerorpc-client ", allowing to:
7
+ zerorpc comes with a convenient script, "zerorpc", allowing to:
8
8
9
9
* expose Python modules without modifying a single line of code,
10
10
* call those modules remotely through the command line.
@@ -16,7 +16,7 @@ Create a server with a one-liner
16
16
Let's see zerorpc in action with a simple example. In a first terminal,
17
17
we will expose the Python "time" module::
18
18
19
- $ zerorpc-client --server --bind tcp://0:1234 time
19
+ $ zerorpc --server --bind tcp://0:1234 time
20
20
21
21
.. note ::
22
22
The bind address uses the zeromq address format. You are not limited
@@ -31,21 +31,21 @@ Call the server from the command-line
31
31
32
32
Now, in another terminal, call the exposed module::
33
33
34
- $ zerorpc-client --client --connect tcp://0:1234 strftime %Y/%m/%d
34
+ $ zerorpc --client --connect tcp://0:1234 strftime %Y/%m/%d
35
35
Connecting to "tcp://0:1234"
36
36
"2011/03/07"
37
37
38
38
Since the client usecase is the most common one, "--client" is the default
39
39
parameter, and you can remove it safely::
40
40
41
- $ zerorpc-client --connect tcp://0:1234 strftime %Y/%m/%d
41
+ $ zerorpc --connect tcp://0:1234 strftime %Y/%m/%d
42
42
Connecting to "tcp://0:1234"
43
43
"2011/03/07"
44
44
45
45
Moreover, since the most common usecase is to *connect * (as opposed to *bind *)
46
46
you can also omit "--connect"::
47
47
48
- $ zerorpc-client tcp://0:1234 strftime %Y/%m/%d
48
+ $ zerorpc tcp://0:1234 strftime %Y/%m/%d
49
49
Connecting to "tcp://0:1234"
50
50
"2011/03/07"
51
51
@@ -56,7 +56,7 @@ See remote service documentation
56
56
You can introspect the remote service; it happens automatically if you don't
57
57
specify the name of the function you want to call::
58
58
59
- $ zerorpc-client tcp://0:1234
59
+ $ zerorpc tcp://0:1234
60
60
Connecting to "tcp://0:1234"
61
61
tzset tzset(zone)
62
62
ctime ctime(seconds) -> string
@@ -78,7 +78,7 @@ Specifying non-string arguments
78
78
Now, see what happens if we try to call a function expecting a non-string
79
79
argument::
80
80
81
- $ zerorpc-client tcp://0:1234 sleep 3
81
+ $ zerorpc tcp://0:1234 sleep 3
82
82
Connecting to "tcp://0:1234"
83
83
Traceback (most recent call last):
84
84
[...]
@@ -87,7 +87,7 @@ argument::
87
87
That's because all command-line arguments are handled as strings. Don't worry,
88
88
we can specify any kind of argument using JSON encoding::
89
89
90
- $ zerorpc-client --json tcp://0:1234 sleep 3
90
+ $ zerorpc --json tcp://0:1234 sleep 3
91
91
Connecting to "tcp://0:1234"
92
92
[wait for 3 seconds...]
93
93
null
@@ -101,12 +101,12 @@ your server to act as a kind of worker, and connect to a hub or queue which
101
101
will dispatch requests. You can achieve this by swapping "--bind" and
102
102
"--connect"::
103
103
104
- $ zerorpc-client --bind tcp://0:1234 localtime
104
+ $ zerorpc --bind tcp://0:1234 localtime
105
105
106
106
We now have "something" wanting to call the "localtime" function, and waiting
107
107
for a worker to connect to it. Let's start the worker::
108
108
109
- $ zerorpc-client --server tcp://0:1234 time
109
+ $ zerorpc --server tcp://0:1234 time
110
110
111
111
The worker will connect to the listening client and ask him "what should I
112
112
do?"; the client will send the "localtime" function call; the worker will
@@ -120,10 +120,10 @@ Listening on multiple addresses
120
120
What if you want to run the same server on multiple addresses? Just repeat
121
121
the "--bind" option::
122
122
123
- $ zerorpc-client --server --bind tcp://0:1234 --bind ipc:///tmp/time time
123
+ $ zerorpc --server --bind tcp://0:1234 --bind ipc:///tmp/time time
124
124
125
- You can then connect to it using either "zerorpc-client tcp://0:1234" or
126
- "zerorpc-client ipc:///tmp/time".
125
+ You can then connect to it using either "zerorpc tcp://0:1234" or
126
+ "zerorpc ipc:///tmp/time".
127
127
128
128
Wait, there is more! You can even mix "--bind" and "--connect". That means
129
129
that your server will wait for requests on a given address, *and * connect
0 commit comments