Class: FreeMessageQueue::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/fmq/server.rb

Overview

This implements server that plugs the free message queue into a rack enviroment

Instance Method Summary collapse

Constructor Details

#initialize(queue_manager) ⇒ Server

When creating a server you have to pass the QueueManager



27
28
29
30
# File 'lib/fmq/server.rb', line 27

def initialize(queue_manager)
  @queue_manager = queue_manager
  @log = FreeMessageQueue.logger
end

Instance Method Details

#call(env) ⇒ Object

Process incoming request and send them to the right sub processing method like process_get



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fmq/server.rb', line 33

def call(env)
  request = Rack::Request.new(env)
  queue_path = request.env["PATH_INFO"]
  @log.debug("[Server] Request params: #{YAML.dump(request.params)})")
  
  response = nil
  begin
    # process supported features
    if request.request_method.match(/^(GET|POST|HEAD|DELETE)$/) then
      response = self.send("process_" + request.request_method.downcase, request, queue_path)
    else
      response = client_exception(request, queue_path, 
        ArgumentError.new("[Server] Method is not supported '#{method}'"))
    end
  rescue QueueException => ex
    response = client_exception(request, queue_path, ex)
  rescue QueueManagerException => ex
    response = client_exception(request, queue_path, ex)
  end
  
  response.header["SERVER"] = SERVER_HEADER
  return response.finish
end