Sha256: 3947b618f1dcc9a19bcd67d6259845287bb8481c0cc83ad796eb88da3b2743cc

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 Bytes

Contents

module RabbitRPC
  class RequestHandler
    include Logging

    attr_reader :one_way

    def initialize(serialized_message)
      @message = Message.unpack serialized_message
    end

    def execute
      parser = MessageParser.new(@message)
      parser.parse

      @one_way = parser.one_way?

      logger.info "Received message #{@message}"

      Kernel.const_get(parser.service_name).send(parser.method_name, *@message['args'] )
    rescue ArgumentError => e
      log_exception(e)
      { ok: false, message: e.message }
    rescue Exception => e
      log_exception(e)
      exception_response
    end

    private

    # We do not want to return the actual exceptions back
    # TODO: Perhaps have this user defined?
    def exception_response
      { ok: false, message: 'Error processing request' }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rabbit_rpc-0.0.2 lib/rabbit_rpc/request_handler.rb