Dimitar Kostov ramblings

Introduction to ZeroMQ


Last week I was looking at ZeroMQ mostly because of Mongrel2. Reading the documentation, turoials and examples I decided to write series about ZeroMQ only because I want to clear out some things for me. I always said that I write crappy blog posts, because I want to remember stuff I’ve used/found interesting. Another reason is that I have to dig in the object of the post. The series will include different things about ZeroMQ: transport, infrastructural and messaging pattern choices. But before we start …

A few things about the series:

  • I’m not professional programmer
  • I really like UNIX stuff, but I haven’t had time to dig in
  • I’ll be using Ruby for the examples, because I’m familiar with it and the code can be read and understood by anyone (hopefully)
  • This series are shallow and I want to show the basic usage of ZeroMQ
  • Any suggestions are welcomed :)

So here we go

When I try to write some network application code, I have to choose between low-level API ( Berkeley Sockets ) or some kind of high-level messaging protocol like AMQP(and implementation of that protocol like RabbitMQ messaging system). Being low-level sockets are hard to use and there is a lot of stuff I have to handle by myself(buffering, error handling, etc.). On the other hand AMQP gives me great power, but I lose some scalability and flexibility. And in the middle is ZeroMQ.

The best explanation of ZeroMQ I found comes from Zed Shaw:

What ZeroMQ ends up being is “sockets the way programmers think sockets work”. 

ZeroMQ is minimalistic, powerful, scalable, fast and transport agnostic networking library which gives me the ease of using “human-face” sockets. There are bindings for 20+ languages including C, C++, Java, .NET, Ruby, Python etc. It’s transport agnosticism enables me to use TCP, IPC, INPROC and PGM very easy. Being message-oriented ZeroMQ handles all the work for me (like load balancing messages) and leaves to me the choice of message pattern (REQUEST/REPLY, PUBLISH/SUBSCRIBE, Pipeline, PAIR).

The series

I know there are a l1ot of buzzwords, but I’ll try to explain them in the series:

Installing ZeroMQ and zmq gem

The instructions how to get and compile ZeroMQ are on their web site.

In the examples I’m using zmq gem:

[sudo] gem install zmq


Feel free to smack me in the face at mitko.kostov[at]gmail.com if you find some rubbish statement.