These devices can do intermediation of addresses, services, queues, or any other abstraction you care to define above the message and socket layers. 0MQ provides three simple devices an application may invoke using the zmq_device() API:
- Queue: a request-reply broker
- Forwarder: a pub-sub proxy server
- Streamer: a forwarder for pipeline flows.
It’s likely that application writers will create their own devices to provide functions such as brokering, routing, logging, interfacing non-secure environments to secure applications, etc.
How We Use It
We’ve exploited 0MQ in a relatively straightforward data-gathering system. A central server listens for work from any number of clients that could be running on the same processor complex or on boxes distributed on LAN or WAN connections. The clients periodically gather data, package it, and use the ZMQ::REQ socket type to ship the data to the server. The server sends an acknowledgement to the client and any updated configuration information.
The 0MQ Guide, “Mongrel2 Documentation” (see http://mongrel2.org/doc/tip/docs/manual/book.wiki#x1-640005.2) describes how the software can be used to provide function-rich systems. The guide also provides an excellent way to understand how the APIs are used and how components can be put together. Here are a couple of commercial users of the suite:
- Mongrel2 – a language-independent Web server
- Solvians IT-Solutions GmbH creates Web projects in the financial and stock market environment. They report: “0MQ is used as a MOM for all components in the system … the new design method is capable of processing current dataflow from our client up to 10 times faster than the old system.”
The Python scripts in Figure 4 illustrate the pub/sub socket types. The publisher continuously sends randomly generated temperature and relative humidity figures for a randomly chosen ZIP code.
A client program subscribes to the port that the publisher is sending its weather information on, but specifies a ZIP code as a filter. 0MQ will only satisfy client receive requests based on that filter. Once it has received five weather readings, it will calculate an average, report it, and then exit (see Figure 5, which also shows the launch of the publisher and then four subscribers, each with a different ZIP code).