[英]ZeroMQ usage in web application: how frontend interacts with backend
I heard some facts about ZeroMQ, and I think it's very powerful thing. 我听说过有关ZeroMQ的一些事实,我认为这是非常有用的。 But now I try to imagine how it can be applied in web application. 但现在我试着想象它如何应用于Web应用程序。
Could you make an example of using ZeroMQ in web applications? 你能举一个在Web应用程序中使用ZeroMQ的例子吗?
So, the first that strikes me - simple chat application. 所以,第一个打动我 - 简单的聊天应用程序。 So, we need frontend and backend. 所以,我们需要前端和后端。 I prefer using python+Tornado as backend. 我更喜欢使用python + Tornado作为后端。 There is python lib for using ZeroMQ. 使用ZeroMQ有python库。 It's clear. 很明显。 So, the next thing is frontend. 所以,接下来就是前端。 In frontend I will use some javascript to interact with backend. 在前端,我将使用一些JavaScript与后端进行交互。
So, to do this I should use ajax calls, right? 所以,要做到这一点,我应该使用ajax调用,对吧? Are there some other ways to do it? 还有其他方法吗?
TIA! TIA!
The easiest way to do this is to map WebSockets to ZeroMQ sockets, which is quite simple with tornado and PyZMQ's ZMQStream objects. 最简单的方法是将WebSockets映射到ZeroMQ套接字,这对于龙卷风和PyZMQ的ZMQStream对象来说非常简单。 An example of such an app is the IPython Notebook . 这种应用程序的一个例子是IPython Notebook 。 This approach has the downside of requiring websockets, which puts a limit on what browsers you can support. 这种方法的缺点是需要websockets,这限制了您可以支持的浏览器。 Of course, you could also map ajax calls with jQuery, etc. and handle the relay with async handlers in tornado. 当然,您也可以使用jQuery等映射ajax调用,并使用龙卷风中的异步处理程序处理中继。
A more sophisticated web:ZeroMQ app is the mongrel2 webserver. 一个更复杂的网站:ZeroMQ应用程序是mongrel2网络服务器。
The right choice for you is just going to depend on your communication patterns. 正确的选择取决于您的沟通模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.