0.06
No commit activity in last 3 years
No release in over 3 years
Celluloid bindings to the ffi-rzmq library
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Project Readme

Celluloid::ZMQ

Gem Version Build Status Code Climate Coverage Status

Celluloid::ZMQ provides Celluloid actors that can interact with 0MQ sockets. Underneath, it's built on the CZTop library. Celluloid::ZMQ was primarily created for the purpose of writing DCell, distributed Celluloid over 0MQ, so before you go building your own distributed Celluloid systems with Celluloid::ZMQ, be sure to give DCell a look and decide if it fits your purposes.

It provides different Celluloid::ZMQ::Socket classes which can be initialized then sent bind or connect. Once bound or connected, the socket can read or send depending on whether it's readable or writable.

Supported Platforms

You will need the ZeroMQ library and the CZMQ library installed as it's accessed via FFI. See CZTop for installation instructions.

Supported Rubies are MRI >= 2.2, JRuby >= 9.0.4.0, and Rubinius >= 3.7.

0MQ Socket Types

The following 0MQ socket types are supported (see types.rb for more info)

  • Req / Rep
  • Push / Pull
  • Pub / Sub
  • Dealer / Router

Usage

require 'celluloid/zmq'

class Server
  include Celluloid::ZMQ

  def initialize(address)
    @socket = Socket::Pull.new

    begin
      @socket.bind(address)
    rescue IOError
      @socket.close
      raise
    end
  end

  def run
    loop { async.handle_message @socket.read }
  end

  def handle_message(message)
    puts "got message: #{message}"
  end
end

class Client
  include Celluloid::ZMQ

  def initialize(address)
    @socket = Socket::Push.new

    begin
      @socket.connect(address)
    rescue IOError
      @socket.close
      raise
    end
  end

  def write(message)
    @socket << message
    nil
  end
end

addr = 'tcp://127.0.0.1:3435'

server = Server.new(addr)
client = Client.new(addr)

server.async.run
client.write('hi')

sleep

Copyright

Copyright (c) 2014-2015 Tony Arcieri, Donovan Keme.

Distributed under the MIT License. See LICENSE.txt for further details.