Got an example of a Spyne client?

I am trying to use spyne ( http://spyne.io ) on my server with ZeroMQ and MsgPack. I followed the examples to program the server side, but I can not find any example that will help me learn how to program the client side.

I found the class spyne.client.zeromq.ZeroMQClient, but I do not know what it should be the "app" parameter of its constructor.

Thank you in advance!

Edit:

(simplified) server code:

from spyne.application import Application from spyne.protocol.msgpack import MessagePackRpc from spyne.server.zeromq import ZeroMQServer from spyne.service import ServiceBase from spyne.decorator import srpc from spyne.model.primitive import Unicode class RadianteRPC(ServiceBase): @srpc(_returns=Unicode) def whoiam(): return "Hello I am Seldon!" radiante_rpc = Application( [RadianteRPC], tns="radiante.rpc", in_protocol=MessagePackRpc(validator="soft"), out_protocol=MessagePackRpc() ) s = ZeroMQServer(radiante_rpc, "tcp://127.0.0.1:5001") s.serve_forever() 
+6
source share
1 answer

Spyne is the author here.

There are many problems with the transport of the Spyne client.

First of all, the most important thing is that they require the server code to work. And this is because the spyne wsdl parser runs halfway, so there is no way to tell the interface that the server provides to the client.

After the Wsdl parser is completed, Spyne client transports will also be restored. They work very well, although the tests pass, but they are (slightly) outdated and, as you noticed, do not have the proper documents.

Now back to your question: the application parameter for the client designer is the same application instance that is sent to the server designer. Therefore, if you do this:

 c = ZeroMQClient("tcp://127.0.0.1:5001", radiante_rpc) print c.service.whoiam() 

He will print "Hello, I'm Seldon!"

Here's the full code I just made: https://github.com/arskom/spyne/tree/master/examples/zeromq

BUT

All this suggests that you should not use ZeroMQ for RPC.

I looked at ZeroMQ for RPC purposes when its ads arose at crazy levels (I even got my name on the ZeroMQ developers list :)) I didn’t like what I saw, and I switched.

Insert my corresponding news.yc comment from https://news.ycombinator.com/item?id=6089252 here:

In my experience, ZeroMQ is very fragile in RPC-like applications, especially because it tries to distract "communication." This mindset is very suitable when you are doing multicast (and ZeroMQ stones when doing multicast), but for unicast I really want to detect disconnection or failure of the connection and handle it properly before my outgoing buffers suffocate to death. So, I would appreciate other alternatives before settling on ZeroMQ as a transport for internal messaging like RPC.

If you are fine with the fact that the entire message is in memory before parsing (or sending) (Http is not so bad when it comes to transferring huge documents over the network), write the raw MessagePack document to the regular TCP stream (or drag it into the UDP datagram) will perform the trick just fine. The MessagePack library supports thread parsing - see, for example, its Python example on the home page ( http://msgpack.org ).

Disclosure: I'm just a happy MessagePack user (and sometimes ZeroMQ). I work for Spyne ( http://spyne.io ), so I have experience with some of the most popular protocols.

I think I wrote this comment more than a year ago. Accelerated transition to today, I received the MessagePack transport, implemented and released in Spyne 2.11. Therefore, if you are looking for an easy transport for sending small messages, my recommendation is to use it instead of ZeroMQ.

However, once you are outside of Http-land, you will return to sockets at the system level, which may or may not be what you want, depending on the amount of resources you should save for this fragment of your project.

Unfortunately, there is no documentation on this subject, except for the examples that I just collected here: https://github.com/arskom/spyne/tree/master/examples/msgpack_transport

Server code is standard Spyne / Twisted code, but the client uses sockets at the system level to illustrate how it should work. I would gladly accept the transfer request, linking it to the appropriate transport of the Spyne client.

Hope this helps. Patches are welcome.

Yours faithfully,

+3
source

Source: https://habr.com/ru/post/973435/


All Articles