Skip to content
An idiomatic Ruby wrapper for the ZeroMQ messaging library.
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.


Works like ZeroMQ. Feels like Ruby.

Build Status Gem Version

The 0mq gem is a Ruby wrapper for the ZeroMQ (libzmq) API. Built on ffi-rzmq-core, the bridge from Ruby to ZeroMQ’s C API, the 0mq gem conceals the interaction with FFI and exposes an interface that uses blocks, raises exceptions, and feels like the Ruby we love to use.


Supported ZeroMQ (libzmq) versions:

  • 3.x

  • 4.x

Supported Ruby versions:

  • MRI >= 1.9

  • Rubinius 2.x

Feature Requests / Bug Reports

File them as issues or pull requests on the 0mq github repository.


  • Joe McIlvain

  • Alex McLain

Installation / Prerequisites

  • Requires the libzmq library.

  • PGM (multicast) requires compiling libzmq with ./configure --with-pgm

  • Curve cryptography requires compiling libzmq with libsodium.

ZeroMQ Documentation

Code Examples

Using The 0mq Gem

require '0mq'

Create A Socket

Sockets can be created by specifying the ZMQ socket type. Any errors will be raised as exceptions.

socket = ZMQ::PULL
socket.connect 'tcp://'

Send And Receive Data

address = 'tcp://'

push = ZMQ::PUSH
push.bind address

pull = ZMQ::PULL
pull.connect address

push.send_string 'test'

string = pull.recv_string

puts string

Poll A Socket For Data

address = 'inproc://poll_example'

pull = ZMQ::PULL
pull.bind address

# Push a message after a delay. do
  push = ZMQ::PUSH
  push.connect address
  sleep 3

  push.send_string 'test'

# Check if pull has any data (it doesn't yet).
# (Non-blocking demonstration.)
result = ZMQ::Poll.poll_nonblock pull
puts "No data available yet." if result.empty?

# Do a blocking poll until the pull socket has data.
ZMQ::Poll.poll pull do |socket, event|
  puts socket.recv_string

Proxy Sockets

A proxy can be used to funnel multiple endpoints into a single connection. See: Pub-Sub Network with a Proxy

# ----------------     ----------------     ----------------     ----------------
# | Endpoint REQ | --> | Proxy ROUTER | --> | Proxy DEALER | --> | Endpoint REP |
# ----------------     ----------------     ----------------     ----------------

# Create sockets.
endpoint_req =    { |s| s.bind    'inproc://proxy_in'  }
proxy_router = { |s| s.connect 'inproc://proxy_in'  }
proxy_dealer = { |s| s.bind    'inproc://proxy_out' }
endpoint_rep =    { |s| s.connect 'inproc://proxy_out' }

# Create the proxy. { ZMQ::Proxy.proxy proxy_router, proxy_dealer }

# Send a message.
endpoint_req.send_string 'test'

puts endpoint_rep.recv_string
You can’t perform that action at this time.