class Lapine::Consumer::Dispatcher

Attributes

delegate_class[R]
message[R]
payload[R]

Public Class Methods

error_handler() click to toggle source
# File lib/lapine/consumer/dispatcher.rb, line 19
def self.error_handler
  @error_handler || DefaultErrorHandler.new
end
error_handler=(handler) click to toggle source
# File lib/lapine/consumer/dispatcher.rb, line 15
def self.error_handler=(handler)
  @error_handler = handler
end
new(delegate_class, message) click to toggle source
# File lib/lapine/consumer/dispatcher.rb, line 23
def initialize(delegate_class, message)
  @delegate_class = delegate_class
  @message = message
  @payload = message.decoded_payload
end

Public Instance Methods

dispatch() click to toggle source
# File lib/lapine/consumer/dispatcher.rb, line 29
def dispatch
  Lapine::DTrace.fire!(:dispatch_enter, delegate_class.name, message.payload)
  with_timed_logging(payload) { do_dispatch(payload) }
  Lapine::DTrace.fire!(:dispatch_return, delegate_class.name, message.payload)
end

Private Instance Methods

delegate_method_names() click to toggle source
# File lib/lapine/consumer/dispatcher.rb, line 46
def delegate_method_names
  [:handle_lapine_payload, :perform_async]
end
do_dispatch(payload) click to toggle source
# File lib/lapine/consumer/dispatcher.rb, line 50
def do_dispatch(payload)
  delegate_method_names.each do |meth|
    return delegate_class.send(meth, payload, message.metadata) if delegate_class.respond_to?(meth)
  end
end
with_timed_logging(json) { || ... } click to toggle source
# File lib/lapine/consumer/dispatcher.rb, line 37
def with_timed_logging(json)
  time = Time.now
  ret = yield
  time_end = Time.now
  duration = (time_end - time) * 1000
  message.logger.info "Processing rabbit message handler:#{delegate_class.name} duration(ms):#{duration} routing_key:#{message.routing_key} payload:#{json.inspect}"
  ret
end