Created
          March 10, 2012 22:18 
        
      - 
      
- 
        Save freegenie/2013593 to your computer and use it in GitHub Desktop. 
    EventMachine + ZeroMQ Pipeline Pattern
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # vim: ft=ruby | |
| source :rubygems | |
| gem 'eventmachine' | |
| gem 'em-zeromq', :path => '~/Work/em-zeromq' | |
| gem 'sinatra' | |
| gem 'zmq' | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | require 'rubygems' | |
| require 'bundler/setup' | |
| require 'eventmachine' | |
| require 'em-zeromq' | |
| class Puller < EM::ZeroMQ::Connection | |
| def on_readable messages | |
| puts messages.join("|") | |
| end | |
| end | |
| WebAppPull = EM::ZeroMQ::Context.new | |
| EM.run do | |
| WebAppPull.socket(ZMQ::PULL, Puller) do |socket| | |
| socket.set_hwm(1) | |
| socket.bind("tcp://*:#{ENV['port']}") | |
| end | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | require 'rubygems' | |
| require 'zmq' | |
| require 'sinatra' | |
| count = 0 | |
| context = ZMQ::Context.new 1 | |
| sock = context.socket(ZMQ::PUSH) | |
| sock.setsockopt(ZMQ::HWM, 1) | |
| sock.connect('tcp://0.0.0.0:4444') | |
| sock.connect('tcp://0.0.0.0:4445') | |
| sock.connect('tcp://0.0.0.0:4446') | |
| sleep 1 | |
| get '/' do | |
| count = count.succ | |
| message = "Hello World! #{count}" | |
| puts sock.send(message, ZMQ::NOBLOCK) | |
| message | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment