有一个Spyne客户的例子吗? [英] There is an example of Spyne client?

查看:211
本文介绍了有一个Spyne客户的例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的服务器中的spyne( http://spyne.io )与ZeroMQ和MsgPack一起使用.我已经按照示例对服务器端进行了编程,但是找不到任何可以帮助我了解如何对客户端进行编程的示例.

I'm trying to use spyne (http://spyne.io) in my server with ZeroMQ and MsgPack. I've followed the examples to program the server side, but i can't find any example that helps me to know how to program the client side.

我找到了类spyne.client.zeromq.ZeroMQClient,但是我不知道它应该是其构造函数的"app"参数.

I've found the class spyne.client.zeromq.ZeroMQClient , but I don't know what it's supposed to be the 'app' parameter of its constructor.

提前谢谢!

(简化的)服务器端代码:

The (simplified) server-side 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()

推荐答案

Spyne作者在这里.

Spyne author here.

Spyne的客户端传输存在很多问题.

There are many issues with the Spyne's client transports.

首先也是最重要的是它们需要服务器代码才能工作.这是因为Spyne的wsdl解析器仅完成了一半,因此无法将服务器公开给客户端的接口进行通信.

First and most important being that they require server code to work. And that's because Spyne's wsdl parser is just halfway done, so there's no way to communicate the interface the server exposes to a client.

一旦Wsdl解析器完成,Spyne的客户端传输也将恢复.虽然测试通过了,但是它们工作得还不错,但是(略)过时了,并且您注意到,没有适当的文档.

Once the Wsdl parser is done, Spyne's client transports will be revived as well. They're working just fine though, the tests pass, but they are (slightly) obsolete and, as you noticed, don't have proper docs.

现在回到您的问题:客户端构造函数的app参数与服务器构造函数的应用程序实例相同.因此,如果您这样做:

Now back to your question: The app parameter to the client constructor is the same application instance that goes to the server constructor. So if you do this:

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

它将显示你好,我是塞尔登!"

It will print "Hello I am Seldon!"

这是我刚提交的完整代码: https://github.com/arskom/spyne/tree/master/examples/zeromq

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

:

所有这些,您不应该将ZeroMQ用于RPC.

All this said, you should not use ZeroMQ for RPC.

我回想起出于RPC目的的ZeroMQ时,它的炒作达到了疯狂的水平((甚至在ZeroMQ贡献者列表中也有我的名字:))我不喜欢自己所看到的,我继续前进.

I looked at ZeroMQ for RPC purposes back when its hype was up at crazy levels, (I even got my name in ZeroMQ contributors list :)) I did not like what I saw, and I moved on.

https://news.ycombinator.com/item上粘贴我的相关news.yc评论? id = 6089252 在这里:

根据我的经验,ZeroMQ在类似RPC的应用程序中非常脆弱, 特别是因为它试图抽象化连接".这 在进行多播(和ZeroMQ)时,心态非常合适 进行多播时会摇滚),但对于单播,我实际上想 检测断开连接或连接故障并进行处理 适当地在我的缓冲区被窒息杀死之前.所以,我会 在选择ZeroMQ作为运输工具之前评估其他选择 用于内部RPC类型的消息传递.

In my experience, ZeroMQ is very fragile in RPC-like applications, especially because it tries to abstract away the "connection". This mindset is very appropriate when you're doing multicast (and ZeroMQ rocks when doing multicast), but for unicast, I actually want to detect a disconnection or a connection failure and handle it appropriately before my outgoing buffers are choked to death. So, I'd evaluate other alternatives before settling on ZeroMQ as a transport for internal RPC-type messaging.

如果您可以在解析之前将整个消息存储在内存中, (或发送)它(在传输方面,Http还不错) 网络上的大量文档),将原始MessagePack文档写入 常规的TCP流(或将其塞入UDP数据报中)将完成 把戏就好了. MessagePack库确实支持解析流- 参见例如在其首页上( http://msgpack.org ).

If you are fine with having the whole message in memory before parsing (or sending) it (Http is not that bad when it comes to transferring huge documents over the network), writing raw MessagePack document to a regular TCP stream (or tucking it inside a UDP datagram) will do the trick just fine. MessagePack library does support parsing streams -- see e.g. its Python example in its homepage (http://msgpack.org).

披露:我只是一个快乐的MessagePack(有时是ZeroMQ)用户. 我在Spyne( http://spyne.io 上工作),所以我只是对一些 其中最流行的协议.

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

我似乎已经在一年多以前写了那条评论.时至今日,我在Spyne 2.11中实现并发布了MessagePack传输.因此,如果您正在寻找一种用于内部传递小消息的轻量级传输,我的建议是使用它而不是ZeroMQ.

I seem to have written that comment more than a year ago. Fast forward to today, I got the MessagePack transport implemented and released in Spyne 2.11. So if you're looking for a lightweight transport for internally passing small messages, my recommendation would be to use it instead of ZeroMQ.

但是,一旦您离开Http领域,您就回到系统级别上处理套接字,这可能不是您想要的,特别是取决于您必须节省的资源量为您的项目做准备.

However, once you're outside the Http-land, you're back to dealing with sockets at the system-level, which may or may not be what you want, depending especially on the amount of resources you have to spare for this bit of your project.

可悲的是,除了我在此处整理的示例外,没有关于它的文档: https://github.com/arskom/spyne/tree/master/examples/msgpack_transport

Sadly, there is no documentation about it besides the examples I just put together here: https://github.com/arskom/spyne/tree/master/examples/msgpack_transport

服务器代码是相当标准的Spyne/Twisted代码,但是客户端使用系统级套接字来说明其工作方式.我很乐意接受将请求包装到适当的Spyne客户端传输中的拉取请求.

The server code is fairly standard Spyne/Twisted code but the client is using system-level sockets to illustrate how it's supposed to work. I'd happily accept a pull request wrapping it to a proper Spyne client transport.

我希望这会有所帮助.欢迎打补丁.

I hope this helps. Patches are welcome.

最诚挚的问候,

这篇关于有一个Spyne客户的例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆