Git Product home page Git Product logo

celluloid-zmq's Introduction

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.

celluloid-zmq's People

Contributors

tarcieri avatar digitalextremist avatar paddor avatar niamster avatar halorgium avatar jnicklas avatar grantr avatar benlangfeld avatar bts avatar chuckremes avatar cootcraig avatar gurpartap avatar jasonroelofs avatar mjio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.