Class: Workling::Clients::AmqpClient

Inherits:
Base
  • Object
show all
Defined in:
lib/workling/clients/amqp_client.rb

Instance Method Summary collapse

Instance Method Details

#closeObject

no need for explicit closing. when the event loop terminates, the connection is closed anyway.



22
# File 'lib/workling/clients/amqp_client.rb', line 22

def close; true; end

#connectObject

starts the client.



12
13
14
15
16
17
18
# File 'lib/workling/clients/amqp_client.rb', line 12

def connect
  begin
    @amq = MQ.new
  rescue
    raise WorklingError.new("couldn't start amq client. if you're running this in a server environment, then make sure the server is evented (ie use thin or evented mongrel, not normal mongrel.)")
  end
end

#request(key, value) ⇒ Object



34
35
36
37
# File 'lib/workling/clients/amqp_client.rb', line 34

def request(key, value)
  data = Marshal.dump(value)
  @amq.queue(key).publish(data)
end

#retrieve(key) ⇒ Object

request and retrieve work



33
# File 'lib/workling/clients/amqp_client.rb', line 33

def retrieve(key); @amq.queue(key); end

#subscribe(key) ⇒ Object

subscribe to a queue



25
26
27
28
29
30
# File 'lib/workling/clients/amqp_client.rb', line 25

def subscribe(key)
  @amq.queue(key).subscribe do |data|
    value = Marshal.load(data)
    yield value
  end
end