Class: EventMachine::AWS::HttpHandler
- Inherits:
-
AWS::Core::Http::NetHttpHandler
- Object
- AWS::Core::Http::NetHttpHandler
- EventMachine::AWS::HttpHandler
- Defined in:
- lib/em-aws/http_handler.rb
Overview
An em-http-request handler for the aws-sdk for fiber based asynchronous ruby application. See github.com/igrigorik/async-rails and www.mikeperham.com/2010/04/03/introducing-phat-an-asynchronous-rails-app/ for examples of Aync-Rails application
In Rails add the following to your aws.rb initializer
require ‘aws-sdk’ require ‘aws/core/http/em_http_handler’ AWS.config(
:http_handler => AWS::Http::EMHttpHandler.new(
:proxy => {:host => '127.0.0.1', # proxy address
:port => 9000, # proxy port
:type => :socks5},
:pool_size => 10, # Default is 10
:max_size => 40, # Maximum size of pool, nil by default so pool can grow to meet concurrency under load
:reap_timeout => 600, # How long to wait to reap connections after load dies down
:async => false)) # If set to true all requests are handle asynchronously and initially return nil
EM-AWS exposes all connections options for EM-Http-Request at initialization For more information on available options see github.com/igrigorik/em-http-request/wiki/Issuing-Requests#available-connection–request-parameters If Options from the request section of the above link are present, they set on every request but may be over written by the request object
Instance Attribute Summary collapse
-
#client_options ⇒ Object
readonly
Returns the value of attribute client_options.
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
-
#pool_options ⇒ Object
readonly
Returns the value of attribute pool_options.
Instance Method Summary collapse
- #handle(request, response, &read_block) ⇒ Object
-
#handle_async(request, response, handle, &read_block) ⇒ Object
If the request option :async are set to true that request will handled asynchronously returning nil initially and processing in the background managed by EM-Synchrony.
-
#initialize(options = {}) ⇒ HttpHandler
constructor
Constructs a new HTTP handler using EM-Synchrony.
Constructor Details
#initialize(options = {}) ⇒ HttpHandler
Constructs a new HTTP handler using EM-Synchrony. each request. These options will be sent to get
, post
, head
, put
, or delete
when a request is made. Note that :body
, :head
, :parser
, and :ssl_ca_file
are ignored. If you need to set the CA file see: github.com/igrigorik/em-http-request/wiki/Issuing-Requests#available-connection–request-parameters
39 40 41 42 43 44 45 46 47 |
# File 'lib/em-aws/http_handler.rb', line 39 def initialize = {} @default_options = @pool_options = @client_options = @verify_content_length = [:verify_response_body_content_length] @sessions = EM::HotTub::Sessions.new() do |url| EM::HttpRequest.new(url,@client_options) end end |
Instance Attribute Details
#client_options ⇒ Object (readonly)
Returns the value of attribute client_options.
30 31 32 |
# File 'lib/em-aws/http_handler.rb', line 30 def @client_options end |
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
30 31 32 |
# File 'lib/em-aws/http_handler.rb', line 30 def @default_options end |
#pool_options ⇒ Object (readonly)
Returns the value of attribute pool_options.
30 31 32 |
# File 'lib/em-aws/http_handler.rb', line 30 def @pool_options end |
Instance Method Details
#handle(request, response, &read_block) ⇒ Object
49 50 51 |
# File 'lib/em-aws/http_handler.rb', line 49 def handle(request,response,&read_block) process_request(request,response,&read_block) end |
#handle_async(request, response, handle, &read_block) ⇒ Object
If the request option :async are set to true that request will handled asynchronously returning nil initially and processing in the background managed by EM-Synchrony. If the client option :async all requests will be handled asynchronously. EX:
EM.synchrony do
s3 = AWS::S3.new
s3.obj.write('test', :async => true) => nil
EM::Synchrony.sleep(2)
s3.obj.read => # 'test'
EM.stop
end
65 66 67 |
# File 'lib/em-aws/http_handler.rb', line 65 def handle_async(request,response,handle,&read_block) process_request(request,response,true,&read_block) end |