fork of for private editing
C Ruby
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 1 commit ahead, 2 commits behind zeromq:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
libzmq @ 44f96a3

Build Status


mruby bindings for (v4)

Everything libzmq offers is mapped 1:1 to the LibZMQ namespace, no beautification was done. High level ruby functions are inside the ZMQ Namespace, you can find most of it inside the mrblib folder, except some of the Msg and Socket classes functions which have to be done in c.

As a bonus a Threading abstraction can be found in the ZMQ::Thread and ZMQ::Thread_fn Namespaces.


If you dont have libzmq installed on a non Windows platform we will build it and statically link it into your mruby app. If you have it installed you need to have pkg-config installed. Then add

conf.gem mgem: 'mruby-zmq'

to your build_config.rb



Client to Server

server ="tcp://*") # you can optionally add a boolean argument if it should connect instead of bind
client = # you can optionally add a boolean argument if it should bind instead of connect

msg = server.recv
puts msg['Peer-Address'] # This gets you the metadata of a message
puts msg.to_str
msg2 ="hello too")
msg2.routing_id = msg.routing_id
puts client.recv.to_str

Dealer to Router

router ="tcp://*")
dealer =

msg = router.recv
puts msg[1].to_str
router.send([msg[0], "hello too"])
puts dealer.recv.to_str

Pub to Sub

pub ="tcp://*")
sub =, "testme")
# you have to wait a short time here because of the slow joiner Problem
pub.send("testme hallo")
puts sub.recv.to_str


thread = # you can optionally add a background class here which manages the thread, all arguments get passed to the background thread too
string =, "hallo")
puts string.send(:to_str)
puts string.async(:upcase!)
puts string.to_str # this gets routed through method_missing and is as such a bit slower


You can define a environment variable called ZMQ_LOGGER_ENDPOINT to create pub sockets which connect to that endpoint. There is also a ZMQ_LOGGER_IDENT env var which adds a ident to each msg from ZMQ.logger"hallo")


Copyright 2017 Hendrik Beskow

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, You can obtain one at

Contribution Policy

mruby-zmq follows the C4 Process: