Basic zeroMQ Ruby example

Update: As Jake pointed out in the comments you obviously need zero MQ installed for this example to work. Just ‘brew install zeromq’ or ‘port install zmq’ on OS X, or use your Linux package manager.

I couldn’t find may examples of zeroMQ usage in Ruby so here is a basic sender/consumer I made to test it. First install the ‘zmq’ gem:

gem install zmq --no-ri --no-rdoc

Now start a worker, you can start as many as you want:

Now stick some messages on the queue:

You should get messages distributed to all the worker processes you started up. Pretty simple!

Tagged ,

4 thoughts on “Basic zeroMQ Ruby example

  1. Jake says:

    This of course implies you have 0mq binaries installed already. nice demo.

  2. Will says:

    Jake, indeed it does, updated the post with installation instructions.

  3. junior says:

    thanks! i had to follow all these instruction in order to get ruby 1.9.2 zeromq ruby binding installed properly and now i can follow your sample.

    install rvm on ubuntu 10.04

    install zeromq

    ##Prepare the Server
    apt-get update
    apt-get upgrade
    apt-get install build-essential
    apt-get install zlib1g-dev
    apt-get install uuid-dev
    ##Download, Build, make, make install – Ruby 1.9.2p0
    cd /tmp
    tar -zvxf ruby-1.9.2-p0.tar.gz
    cd ruby-1.9.2-p0
    make install
    ## Download, Build, make, make install – ZeroMQ
    cd /tmp
    tar -zvxf zeromq-2.0.9.tar.gz
    cd zeromq-2.0.9
    make install

    if you get error after zeromq is installed, try this one to update the library

    now you are set to run the samples mentioned in this blog post.

  4. You might also be interested in the ruby zeromq tutorials I’ve been making. They do use ffi-rzmq rather than zmq however (there are only a few minor differences). You can find them at:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s