Class: Workling::Clients::AmqpBunnyClient
- Inherits:
-
BrokerBase
- Object
- Base
- BrokerBase
- Workling::Clients::AmqpBunnyClient
- Defined in:
- lib/workling/clients/amqp_bunny_client.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#close ⇒ Object
no need for explicit closing.
-
#connect ⇒ Object
starts the client.
- #request(key, value) ⇒ Object
-
#retrieve(key) ⇒ Object
request and retrieve work.
-
#subscribe(key) ⇒ Object
subscribe to a queue.
Methods inherited from BrokerBase
Methods inherited from Base
#dispatch, installed?, #logger
Class Method Details
.load ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/workling/clients/amqp_bunny_client.rb', line 9 def self.load begin require 'bunny' rescue LoadError => e raise WorklingError.new("WORKLING: couldn't find the bunny amqp client") end end |
Instance Method Details
#close ⇒ Object
no need for explicit closing. when the event loop terminates, the connection is closed anyway.
29 30 31 32 |
# File 'lib/workling/clients/amqp_bunny_client.rb', line 29 def close @bunny.stop # normal amqp does not require stopping end |
#connect ⇒ Object
starts the client.
18 19 20 21 22 23 24 25 |
# File 'lib/workling/clients/amqp_bunny_client.rb', line 18 def connect begin @bunny = Bunny.new((Workling.config[:amqp_options] ||{}).symbolize_keys) @bunny.start rescue raise WorklingError.new("Couldn't start bunny amqp client, ensure the AMQP server is running.") end end |
#request(key, value) ⇒ Object
47 48 49 50 |
# File 'lib/workling/clients/amqp_bunny_client.rb', line 47 def request(key, value) data = Marshal.dump(value) @bunny.queue(queue_for(key)).publish(data) end |
#retrieve(key) ⇒ Object
request and retrieve work
43 44 45 |
# File 'lib/workling/clients/amqp_bunny_client.rb', line 43 def retrieve(key) @bunny.queue(queue_for(key)).pop[:payload] end |
#subscribe(key) ⇒ Object
subscribe to a queue
35 36 37 38 39 40 |
# File 'lib/workling/clients/amqp_bunny_client.rb', line 35 def subscribe(key) @bunny.queue(queue_for(key)).subscribe(:timeout => 30) do |value| data = Marshal.load(value) rescue value yield data end end |