ØMQ - Fast, Broker-Free Messaging
ØMQ - Fast, Broker-Free Messaging
Join the DZone community and get the full member experience.
Join For FreeGet the Edge with a Professional Java IDE. 30-day free trial.
- Sends and receives messages asynchronously (a.k.a. "message queueing").
- Supports different messaging patterns such as point-to-point, publish-subscribe, request-reply, paralellized pipeline and more.
- Is fast. 13.4 usec end-to-end latencies and over 8M messages a second today (InfiniBand).
- Is thin. The core requires just a couple of pages in resident memory.
- Supports different transport protocols: TCP, PGM, IPC, and more.
- Runs on HP-UX, Linux, Mac OS X, NetBSD, OpenVMS, Solaris, Windows, AIX, and more.
- Supports microarchitectures such as x86, AMD64, SPARC, IA-64, ARM, and more.
- Is fully distributed: no central servers to crash, millions of WAN and LAN nodes.
- ZeroMQ bindings exist for: Ada, C, C++, Common Lisp, Erlang, Go, Haskell, Java, Lua, .NET, OOC, Perl, PHP, Python, and Ruby.

Sending messages with ZeroMQ is very simple compared to raw socket implementations (where you must constantly feed the socket buffer). When you fire an asynchronous send call, ZeroMQ will queue the message in a separate thread and handle all of the work - perfect for an event-based framework. ZeroMQ is also versatile enough to let you encode the message however you like (JSON, BSON, Protocol Buffers, or Thrift).
This Python code shows you how you could create a broadcasting server for live football/soccer events:
import zmqIn terms of scalability, ZeroMQ sockets may look low level, but they actually have quite a few features and can, for example, connect to multiple end points and automatically load balance messages over those points. It can also collect messages from multiple sources through a single socket. Because of ZeroMQ's brokerless design, it has no single point of failure.
from random import choice
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://127.0.0.1:5000")
countries = ['netherlands','brazil','germany','portugal']
events = ['yellow card', 'red card', 'goal', 'corner', 'foul']
while True:
msg = choice( countries ) +" "+ choice( events )
print "->",msg
socket.send( msg )
You should really take a look at Nicholas Piël's blog post, which describes how to implement a message layer with ZeroMQ using several common paradigms.
ZeroMQ is distributed under the LGPL and contributions are made under the MIT (X11) license.
Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.
Opinions expressed by DZone contributors are their own.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}