Class: Freddy::MessageHandlers::RequestHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/freddy/message_handlers.rb

Instance Method Summary collapse

Constructor Details

#initialize(producer, destination, logger) ⇒ RequestHandler

Returns a new instance of RequestHandler.



41
42
43
44
45
# File 'lib/freddy/message_handlers.rb', line 41

def initialize(producer, destination, logger)
  @producer = producer
  @logger = logger
  @destination = destination
end

Instance Method Details

#error(reply_to, response) ⇒ Object



64
65
66
# File 'lib/freddy/message_handlers.rb', line 64

def error(reply_to, response)
  send_response(reply_to, response, type: 'error')
end

#handle_message(payload, msg_handler, &block) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/freddy/message_handlers.rb', line 47

def handle_message(payload, msg_handler, &block)
  @correlation_id = msg_handler.correlation_id

  if !@correlation_id
    @logger.error "Received request without correlation_id"
  else
    block.call payload, msg_handler
  end
rescue Exception => e
  @logger.error "Exception occured while handling the request with correlation_id #{@correlation_id}: #{Utils.format_exception(e)}"
  Utils.notify_exception(e, correlation_id: @correlation_id, destination: @destination)
end

#success(reply_to, response) ⇒ Object



60
61
62
# File 'lib/freddy/message_handlers.rb', line 60

def success(reply_to, response)
  send_response(reply_to, response, type: 'success')
end