Class: Freddy::MessageHandlers::RequestHandler

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

Instance Method Summary collapse

Constructor Details

#initialize(producer, logger) ⇒ RequestHandler

Returns a new instance of RequestHandler.



31
32
33
34
# File 'lib/freddy/message_handlers.rb', line 31

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

Instance Method Details

#error(reply_to, response) ⇒ Object



54
55
56
# File 'lib/freddy/message_handlers.rb', line 54

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

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



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/freddy/message_handlers.rb', line 36

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

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

#success(reply_to, response) ⇒ Object



50
51
52
# File 'lib/freddy/message_handlers.rb', line 50

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