Sha256: c2520a17abb7d09fa54de8db333c481eed3253812572bcfad2ec33b941831306

Contents?: true

Size: 1 KB

Versions: 18

Compression:

Stored size: 1 KB

Contents

require 'dripdrop/message'
#Check if we're in 1.8.7
unless defined?(RUBY_ENGINE)
  require 'zmq'
  ZMQGEM = :rbzmq
else
  require 'ffi-rzmq'
  ZMQGEM = :ffirzmq
end
require 'uri'

class DripDrop
  #The Agent class is a simple ZMQ Pub client. It uses DripDrop::Message messages
  class Agent
    attr_reader :address, :context, :socket
    
    #address should be a string like tcp://127.0.0.1
    def initialize(sock_type,address,sock_ctype)
      @context = ZMQ::Context.new(1)
      @socket  = @context.socket(sock_type)
      if sock_ctype == :bind
        @socket.bind(address)
      else
        @socket.connect(address)
      end
    end

    #Sends a DripDrop::Message to the socket
    def send_message(name,body,head={})
      message = DripDrop::Message.new(name,:body => body, :head => head).encoded
      if ZMQGEM == :rbzmq
        @socket.send name, ZMQ::SNDMORE
        @socket.send message
      else
        @socket.send_string name, ZMQ::SNDMORE
        @socket.send_string message
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dripdrop-0.11.0-java lib/dripdrop/agent.rb
dripdrop-0.11.0 lib/dripdrop/agent.rb
dripdrop-0.10.0 lib/dripdrop/agent.rb
dripdrop-0.10.0-java lib/dripdrop/agent.rb
dripdrop-0.10.0.beta2 lib/dripdrop/agent.rb
dripdrop-0.10.0.beta1 lib/dripdrop/agent.rb
dripdrop-0.9.10 lib/dripdrop/agent.rb
dripdrop-0.9.9 lib/dripdrop/agent.rb
dripdrop-0.9.8 lib/dripdrop/agent.rb
dripdrop-0.9.6 lib/dripdrop/agent.rb
dripdrop-0.9.5 lib/dripdrop/agent.rb
dripdrop-0.9.4 lib/dripdrop/agent.rb
dripdrop-0.9.3 lib/dripdrop/agent.rb
dripdrop-0.9.2 lib/dripdrop/agent.rb
dripdrop-0.8.1 lib/dripdrop/agent.rb
dripdrop-0.8.0 lib/dripdrop/agent.rb
dripdrop-0.7.1 lib/dripdrop/agent.rb
dripdrop-0.6.0 lib/dripdrop/agent.rb