Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Celluloid actors that talk over the 0MQ protocol

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGES.md
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 celluloid-zmq.gemspec
Octocat-spinner-32 logo.png
README.md

Celluloid::ZMQ

Build Status

Celluloid::ZMQ provides Celluloid actors that can interact with 0MQ sockets. Underneath, it's built on the ffi-rzmq 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

Celluloid::IO requires Ruby 1.9 support on all Ruby VMs. You will also need the ZeroMQ library installed as it's accessed via FFI.

Supported VMs are Ruby 1.9.3, JRuby 1.6, and Rubinius 2.0.

To use JRuby in 1.9 mode, you'll need to pass the "--1.9" command line option to the JRuby executable, or set the "JRUBY_OPTS=--1.9" environment variable.

0MQ Socket Types

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

  • ReqSocket / RepSocket
  • PushSocket / PullSocket
  • PubSocket / SubSocket

Usage

require 'celluloid/zmq'

Celluloid::ZMQ.init

class Server
  include Celluloid::ZMQ

  def initialize(address)
    @socket = PullSocket.new

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

  def run
    while true; handle_message! @socket.read; end
  end

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

class Client
  include Celluloid::ZMQ

  def initialize(address)
    @socket = PushSocket.new

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

  def write(message)
    @socket.send(message)

    nil
  end
end

addr = 'tcp://127.0.0.1:3435'

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

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

Copyright

Copyright (c) 2012 Tony Arcieri. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.