Class: DripDrop::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/dripdrop/agent.rb

Overview

The Agent class is a simple ZMQ Pub client. It uses DripDrop::Message messages

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sock_type, address, sock_ctype) ⇒ Agent

address should be a string like tcp://127.0.0.1



18
19
20
21
22
23
24
25
26
# File 'lib/dripdrop/agent.rb', line 18

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

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



15
16
17
# File 'lib/dripdrop/agent.rb', line 15

def address
  @address
end

#contextObject (readonly)

Returns the value of attribute context.



15
16
17
# File 'lib/dripdrop/agent.rb', line 15

def context
  @context
end

#socketObject (readonly)

Returns the value of attribute socket.



15
16
17
# File 'lib/dripdrop/agent.rb', line 15

def socket
  @socket
end

Instance Method Details

#send_message(name, body, head = {}) ⇒ Object

Sends a DripDrop::Message to the socket



29
30
31
32
33
34
35
36
37
38
# File 'lib/dripdrop/agent.rb', line 29

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