Module: BeetleJoevandykExtensions
- Defined in:
- lib/beetle_joevandyk_extensions.rb,
lib/beetle_joevandyk_extensions/version.rb
Defined Under Namespace
Classes: BeetleError
Constant Summary collapse
- DEFAULT_TIMEOUT =
10
- VERSION =
"0.0.10"
Instance Method Summary collapse
- #listen(name, &block) ⇒ Object
- #publish(name, message) ⇒ Object
- #rpc(name, message, options = {}) ⇒ Object
- #setup ⇒ Object
Instance Method Details
#listen(name, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/beetle_joevandyk_extensions.rb', line 26 def listen name, &block setup client = Beetle::Client.new client.register_queue name client.register_handler name do |input| block.call(JSON.parse(input.data)).to_json end client.listen do puts "Started #{ name } at #{ Time.now }" end end |
#publish(name, message) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/beetle_joevandyk_extensions.rb', line 38 def publish name, setup client = Beetle::Client.new client. name client.publish name, end |
#rpc(name, message, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/beetle_joevandyk_extensions.rb', line 15 def rpc name, , ={} setup client = Beetle::Client.new client. name Timeout.timeout([:timeout] || DEFAULT_TIMEOUT, BeetleError) do status, result = client.rpc(name, .to_json) raise BeetleError.new(result.to_s) if status != "OK" JSON.parse(result) end end |
#setup ⇒ Object
10 11 12 13 |
# File 'lib/beetle_joevandyk_extensions.rb', line 10 def setup uri = URI.parse(ENV['AMQP_URL']) Beetle.config.servers = uri.host end |