7

I heard some facts about ZeroMQ, and I think it's very powerful thing. But now I try to imagine how it can be applied in web application.

Could you make an example of using ZeroMQ in web applications?

So, the first that strikes me - simple chat application. So, we need frontend and backend. I prefer using python+Tornado as backend. There is python lib for using ZeroMQ. It's clear. So, the next thing is frontend. In frontend I will use some javascript to interact with backend.

So, to do this I should use ajax calls, right? Are there some other ways to do it?

TIA!

Dmitry Belaventsev
  • 6,347
  • 12
  • 52
  • 75

1 Answers1

3

The easiest way to do this is to map WebSockets to ZeroMQ sockets, which is quite simple with tornado and PyZMQ's ZMQStream objects. An example of such an app is the IPython Notebook. This approach has the downside of requiring websockets, which puts a limit on what browsers you can support. Of course, you could also map ajax calls with jQuery, etc. and handle the relay with async handlers in tornado.

A more sophisticated web:ZeroMQ app is the mongrel2 webserver.

The right choice for you is just going to depend on your communication patterns.

minrk
  • 37,545
  • 9
  • 92
  • 87
  • The question expressed a specific preference for tornado, so that's where the examples came from, but any web framework will do these days (the answer is from 10 years ago, before we had asyncio). – minrk Dec 13 '22 at 14:34
  • Since websockets already support chat nicely in http environment you are limited to from browser land I don't think this is a particularly good use case for zeromq. Now a conventional desktop gui talking to a server via zeromq for a chat app would be a good use. – Samantha Atkins Jan 12 '23 at 09:45
  • Great point! I also don't think zmq is a very logical choice for building a web-based chat application. I read the question as asking for _how_ it could be used, rather than _whether_ it should be. I figure it was an example to use for learning purposes more than anything else. – minrk Jan 12 '23 at 10:56