Project

zkruby

0.01
No commit activity in last 3 years
No release in over 3 years
Pure ruby client for ZooKeeper (http://zookeeper.apache.org)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.4.0
~> 0.12.10
~> 2.13
>= 0.1.2
>= 1.4.1
>= 2.7.0
~> 0.1.0

Runtime

~> 1.4.1
~> 0.4.2
 Project Readme

zkruby¶ ↑

DESCRIPTION:¶ ↑

Pure ruby client for ZooKeeper (zookeeper.apache.org)

FEATURES¶ ↑

Supports full ZooKeeper API, synchronous or asynchronous style, watches etc.. with implementations over EventMachine or plain old Ruby IO/Threads

Other ruby libraries for zookeeper tend to use the underlying C/Java client libraries while zkruby implements the zookeeper wire protocol directly.

Advantages:

  • Rubyist API - with block is asynchronous, without block is synchronous

  • Avoids conflicts between various Ruby threading models and the C/Java apis

  • Same code for JRuby or MRI

  • Connection bindings for pure ruby IO and eventmachine, or roll your own

Disadvantages:

  • Duplicated code from Java/C libraries, particularly around herd effect protection

  • Needs to keep up with changes in wire protocol which are possibly more likely than changes in the client API

  • Possibly not as optimised in terms of performance (but your client code is ruby anyway)

  • Not production tested (yet- do you want to be the first?)

SYNOPSIS:¶ ↑

  1. Configure Slf4R Logging (rubygems.org/gems/slf4r)

  2. Get a connection {ZooKeeper.connect}

  3. Make requests on the returned {ZooKeeper::Client}

require 'slf4r/ruby_logging' 
require 'zkruby'

# Using ruby threads and sockets (default)
zk = ZooKeeper.connect("localhost:2181")
# Synchronous
stat = zk.exists("/aPath")

# Asynchronous
zk.exists("/aPath) { |stat| puts stat.inspect }

# Watches
watch = lambda { |state,path,event| puts "Watch fired #{state} #{path} #{event}" }

stat,data = zk.get("/aPath",watch)

# OR with EventMachine
require 'em_zkruby'
EventMachine.run do
   # Magic of Fibers (via Empathy) lets us code normally and execute asynchronously
   Empathy::EM::Thread.new() do
      begin
          zk = ZooKeeper.connect("localhost:2181")
          #Sync
          path = zk.create("/aPath/mynode",ZK::ACL_ANYONE_UNSAFE,:ephemeral,:sequential) 

          #Async
          zk.get(path) do |stat,data|
             puts "#{stat.inspect} #{data}" 
          end

      rescue ZooKeeper::Error => zkex
          puts zkex.message
      end
   end
end

REQUIREMENTS:¶ ↑

  • A ZooKeeper cluster to connect to

  • Ruby 1.9 (but a backport should be straightforward)

INSTALL:¶ ↑

$ (sudo) gem install zkruby

DEVELOPERS:¶ ↑

Download ZooKeeper from zookeeper.apache.org

Create a conf/zoo.cfg file (copying sample.zoo.cfg is fine)

Checkout the zkruby source into the contrib directory

Copy (if different) src/zookeeper.jute to contrib/zkruby/src/zookeeper.jute

Get gem dependencies

$ bundle install

Generate docs and run the tests/specs

$ rake

LICENSE:¶ ↑

(The MIT License)

Copyright © 2012 Grant Gardner

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.