Class: DripDrop::Agent
- Inherits:
-
Object
- Object
- DripDrop::Agent
- 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
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize(sock_type, address, sock_ctype) ⇒ Agent
constructor
address should be a string like tcp://127.0.0.1.
-
#send_message(name, body, head = {}) ⇒ Object
Sends a DripDrop::Message to the socket.
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
#address ⇒ Object (readonly)
Returns the value of attribute address.
15 16 17 |
# File 'lib/dripdrop/agent.rb', line 15 def address @address end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
15 16 17 |
# File 'lib/dripdrop/agent.rb', line 15 def context @context end |
#socket ⇒ Object (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 (name,body,head={}) = DripDrop::Message.new(name,:body => body, :head => head).encoded if ZMQGEM == :rbzmq @socket.send name, ZMQ::SNDMORE @socket.send else @socket.send_string name, ZMQ::SNDMORE @socket.send_string end end |