Class: Baton::Consumer
- Inherits:
-
Object
- Object
- Baton::Consumer
- Defined in:
- lib/baton/consumer.rb
Instance Attribute Summary collapse
-
#consumer_manager ⇒ Object
Returns the value of attribute consumer_manager.
-
#consumer_name ⇒ Object
Returns the value of attribute consumer_name.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
-
#attributes ⇒ Object
Public: Method that provides an hash of attributes, if they are needed.
-
#exception_notifier ⇒ Object
Public: Method that wraps a block and notifies when errors occur.
-
#handle_message(payload) ⇒ Object
Public: Method that decodes a json message and passes it to process_message to be processed.
-
#initialize(consumer_name, server) ⇒ Consumer
constructor
Public: Initialize a Consumer.
-
#process_message(message) ⇒ Object
Public: Method that will be called when handle_message receives a message.
-
#routing_key ⇒ Object
Public: Defines the routing key for the consumer.
Methods included from Logging
Methods included from Observer
#notify, #notify_error, #notify_info, #notify_log, #notify_success
Constructor Details
#initialize(consumer_name, server) ⇒ Consumer
Public: Initialize a Consumer.
consumer_name - A String naming the consumer. server - An instance of Baton::Server.
14 15 16 |
# File 'lib/baton/consumer.rb', line 14 def initialize(consumer_name, server) @consumer_name, @server = consumer_name, server end |
Instance Attribute Details
#consumer_manager ⇒ Object
Returns the value of attribute consumer_manager.
8 9 10 |
# File 'lib/baton/consumer.rb', line 8 def consumer_manager @consumer_manager end |
#consumer_name ⇒ Object
Returns the value of attribute consumer_name.
8 9 10 |
# File 'lib/baton/consumer.rb', line 8 def consumer_name @consumer_name end |
#server ⇒ Object
Returns the value of attribute server.
8 9 10 |
# File 'lib/baton/consumer.rb', line 8 def server @server end |
Instance Method Details
#attributes ⇒ Object
Public: Method that provides an hash of attributes, if they are needed.
Examples
attributes
# => {type: "pong"}.merge(server.attributes)
Returns Output depends on the implementation.
85 86 87 |
# File 'lib/baton/consumer.rb', line 85 def attributes {} end |
#exception_notifier ⇒ Object
Public: Method that wraps a block and notifies when errors occur.
Examples
exception_notifier do
<your code>
end
Returns nothing.
40 41 42 43 44 |
# File 'lib/baton/consumer.rb', line 40 def exception_notifier yield rescue Exception => e notify_error(e.class, e.) end |
#handle_message(payload) ⇒ Object
Public: Method that decodes a json message and passes it to process_message to be processed.
payload - A message in json format
Examples
("{\"message\":\"a message\",\"type\":\"a type\"}")
Returns nothing.
56 57 58 59 60 61 |
# File 'lib/baton/consumer.rb', line 56 def (payload) exception_notifier do = JSON.load(payload) () end end |
#process_message(message) ⇒ Object
Public: Method that will be called when handle_message receives a message. It should be implemented by baton-like gems and it should add logic to process messages.
message - A message in ruby-format
Examples
({"type" => "current"})
Returns Output depends on the implementation.
74 75 |
# File 'lib/baton/consumer.rb', line 74 def () end |
#routing_key ⇒ Object
Public: Defines the routing key for the consumer. Messages with the defined routing queue will be consumed by this consumer.
Examples
routing_key
# => "central-apu.production"
Returns the routing key.
27 28 29 |
# File 'lib/baton/consumer.rb', line 27 def routing_key "#{consumer_name}.#{server.environment}" end |