On ZeroMQ

Message queue? We don't need no stinking message queue

ZeroMQ touts itself as being "The Intelligent Transport Layer". Using a low-level API that closely resembles BSD sockets, not only is it intelligent, it is easy to use too.

ZeroMQ provides bindings for an astonishing number of languages, but the Ruby bindings are of particular interest to me for a professional project I am involved with. Getting up and running with a simple echo message passing interface is a snap.

	
require 'zmq'

context = ZMQ::Context.new
socket  = context.socket(ZMQ::REP)
socket.bind('tcp://127.0.0.1:5000')

while true
  data = socket.recv
  socket.send(data)
end
	

As one instance listens, another instance needs to start pump the listener with data.

	
require 'zmq'

context = ZMQ::Context.new
socket  = context.socket(ZMQ::REQ)
socket.connect('tcp://127.0.0.1:5000')

while true
  socket.send('Hello World!')
  puts socket.recv
end
	

This is, of course, the most basic example of getting up and running. ZeroMQ provides a host of routing and connection options, such as publish/subscribe interfaces, to meet all kinds of needs. For those who have the need to pass messages between applications, or even within the same application, it is a technology worth taking a closer look at.