Class: TinyQ::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/tinyq/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



25
26
27
# File 'lib/tinyq/client.rb', line 25

def initialize
    @callbacks = []
end

Instance Attribute Details

#callbacksObject

Returns the value of attribute callbacks.



23
24
25
# File 'lib/tinyq/client.rb', line 23

def callbacks
  @callbacks
end

Instance Method Details

#connect(host, port) ⇒ Object



29
30
31
32
33
# File 'lib/tinyq/client.rb', line 29

def connect(host, port)
    @host, @port = host, port
    @connection = EM.connect @host, @port, TinyQ::ClientConnection
    @connection.client = self
end

#feed_funnel(bucket, funnel) ⇒ Object



53
54
55
56
# File 'lib/tinyq/client.rb', line 53

def feed_funnel(bucket, funnel)
    command = {:Command => "FeedFunnel", :Bucket => bucket, :Funnel => funnel}
    @connection.send_data("#{command.to_json}#{TinyQ::DELIMITER}")
end

#get_message(funnel) ⇒ Object



43
44
45
46
# File 'lib/tinyq/client.rb', line 43

def get_message(funnel)
    command = {:Command => "GetMessages", :Funnel => funnel}
    @connection.send_data("#{command.to_json}#{TinyQ::DELIMITER}")
end

#onreply(&block) ⇒ Object



48
49
50
# File 'lib/tinyq/client.rb', line 48

def onreply(&block)
    @callbacks << block
end

#put_message(bucket, message) ⇒ Object

Public API



38
39
40
41
# File 'lib/tinyq/client.rb', line 38

def put_message(bucket, message)
    command = {:Command => "PutMessages", :Bucket => bucket, :Message => message}
    @connection.send_data("#{command.to_json}#{TinyQ::DELIMITER}")
end