Giter Club home page Giter Club logo

learn-ruby-zeromq's Introduction

Learn ZeroMQ by Example!

A Work in Progress

If you'd like to help write examples, or if you've found an error, please write me, or fork and patch this repo.

About ZeroMQ

ZeroMQ is one of the simplest and most exciting ways to build high performance, concurrent local and network applications. ZeroMQ uses a sockets style API to make powerful message-based programs fun to build.

Be sure to follow the examples in order, as concepts shown in earlier chapters won't be described later on.

Getting Started

  1. Get a functioning ruby, either jruby (recommended) or 1.9.2. I recommend using rvm to manage multiple rubies
  2. If you're using jruby the ffi gem it comes with will work fine. If using 1.9.2 you MUST install the special ffi gem.
  3. Download and install ZeroMQ from the ZeroMQ download page. ./configure && make && make install
  4. gem install ffi ffi-rzmq zmqmachine. Make sure you have the ffi-rzmq gem >= 0.9.0 . All examples have been updated to use the newer API exposed in ffi-rzmq 0.9.0 and later. If your libzmq version >= 3.2.1, Make sure you have the ffi-rzmq gem >= 0.9.7(you can clone git://github.com/chuckremes/ffi-rzmq.git and build from source), otherwise you will get "Function 'zmq_ctx_set_monitor' not found" error message.

Now you're set! Follow the numbered examples in order, where there are no numbers, there is no order.

Thanks Chuck!

Many thanks to Chuck Remes, author of both ffi-rzmq and zmqmachine for providing the ruby community with these gems, and helping answer my questions. None of this, would have been possible without his efforts.

learn-ruby-zeromq's People

Contributors

andrewvc avatar bachue avatar xentek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learn-ruby-zeromq's Issues

Deregistering a writable socket causes an error.

Running the latest ffi-rzmq and zmqmachine the following code:

https://gist.github.com/2b1b44d8ef4fad1a84d8

gives me the error:

/Users/admin/.rvm/gems/jruby-1.5.1/gems/ffi-rzmq-0.5.0/lib/ffi-rzmq/poll.rb:98:in deregister': undefined local variable or methoditems' for #ZMQ::Poller:0x3e5646a5 (NameError)
from /Users/admin/.rvm/gems/jruby-1.5.1/gems/ffi-rzmq-0.5.0/lib/ffi-rzmq/poll.rb:123:in deregister_writable' from /Users/admin/.rvm/gems/jruby-1.5.1/gems/zmqmachine-0.3.1/lib/zm/reactor.rb:288:inderegister_writable'
from 003_ZMQMachine/002_a_pub_sub_example.rb:24:in on_writable' from /Users/admin/.rvm/gems/jruby-1.5.1/gems/zmqmachine-0.3.1/lib/zm/sockets/base.rb:181:inresume_write'
from /Users/admin/.rvm/gems/jruby-1.5.1/gems/zmqmachine-0.3.1/lib/zm/reactor.rb:385:in poll' from /Users/admin/.rvm/gems/jruby-1.5.1/gems/zmqmachine-0.3.1/lib/zm/reactor.rb:385:ineach'
from /Users/admin/.rvm/gems/jruby-1.5.1/gems/zmqmachine-0.3.1/lib/zm/reactor.rb:385:in poll' from /Users/admin/.rvm/gems/jruby-1.5.1/gems/zmqmachine-0.3.1/lib/zm/reactor.rb:351:inrun_once'
from /Users/admin/.rvm/gems/jruby-1.5.1/gems/zmqmachine-0.3.1/lib/zm/reactor.rb:84:in run' from /Users/admin/.rvm/gems/jruby-1.5.1/gems/zmqmachine-0.3.1/lib/zm/reactor.rb:80:ininitialize'
from /Users/admin/.rvm/gems/jruby-1.5.1/gems/zmqmachine-0.3.1/lib/zm/reactor.rb:80:in new' from /Users/admin/.rvm/gems/jruby-1.5.1/gems/zmqmachine-0.3.1/lib/zm/reactor.rb:80:inrun'
from 003_ZMQMachine/002_a_pub_sub_example.rb:46

Trying to run examples under XP

So far I had no success setting up environment to run your examples under Windows XPSP3 (32bit). I have successfully built zeromq-2.0.10 - with Visual Studio from Windows package and from sources under Cygwin. So, I have zeromq library working and in path.

Here are the Rubies that I tried (since it is indicated that either JRuby or 1.9.2 are adequate, I only tried those):
Ruby 1.9.2-p0 (Rubyinstaller)
JRuby 1.5.2
Ruby 1.9.2-p0 (built from source under Cygwin)

Unfortunately, trying to run example from https://github.com/andrewvc/learn-ruby-zeromq/ fails with a following trace:

Y:\Dev\apps\win\learn-ruby-zeromq\001_Socket_Types>jruby -v
jruby 1.5.2 (ruby 1.8.7 patchlevel 249) (2010-08-20 1c5e29d) (Java HotSpot(TM) Client VM 1.6.0_20) [x86-java]

Y:\Dev\apps\win\learn-ruby-zeromq\001_Socket_Types>gem list

columnize (0.3.1)
ffi (0.6.3)
ffi-rzmq (0.6.0)
rake (0.8.7)
rspec (1.3.0)
ruby-debug (0.10.3)
ruby-debug-base (0.10.3.2)
sources (0.0.1)
zmqmachine (0.3.2)

Y:\Dev\apps\win\learn-ruby-zeromq\001_Socket_Types>jruby 001_push_pull.rb
C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/shared/ffi/ffi.rb:112:in create_invoker': Function 'valloc' not found in [msvcrt] (FFI::NotFoundError) from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/shared/ffi/library.rb:98:inattach_function'
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/shared/ffi/library.rb:96:in each' from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/shared/ffi/library.rb:96:inattach_function'
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/wrapper.rb:11
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/wrapper.rb:31:in require' from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:71
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:70:in each' from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:70 from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/gems/1.8/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:36:inrequire'
from C:/Documents and Settings/bezrodnykh/.pik/rubies/JRuby-152/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from 001_push_pull.rb:2


$ ruby -v
ruby 1.9.2dev (2009-07-18 trunk 24186) [i386-cygwin]

$ gem list

ffi (0.6.3)
ffi-rzmq (0.6.0)
rake (0.8.7)
rubygems-update (1.3.7)
zmqmachine (0.3.2)

vb@vb-mac /y/dev/apps/win/learn-ruby-zeromq/001_Socket_Types
$ ruby 001_push_pull.rb
/home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-0.6.3/lib/ffi/library.rb:129:in attach_function': Function 'valloc' not found in [msvcrt.dll] (FFI::NotFoundError) from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/wrapper.rb:11:inmodule:LibC'
from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq/wrapper.rb:3:in <top (required)>' from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:71:inrequire'
from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:71:in block in <top (required)>' from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:70:ineach'
from /home/bezrodnykh/.rvm/gems/ruby-1.9.2-preview1/gems/ffi-rzmq-0.6.0/lib/ffi-rzmq.rb:70:in <top (required)>' from 001_push_pull.rb:2:inrequire'
from 001_push_pull.rb:2:in `

'


Any advice/suggestion/hint to help me moving forward?

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.