diff --git a/fluent-plugin-azureeventhubs.gemspec b/fluent-plugin-azureeventhubs.gemspec index 31da545..1a69c90 100644 --- a/fluent-plugin-azureeventhubs.gemspec +++ b/fluent-plugin-azureeventhubs.gemspec @@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) Gem::Specification.new do |spec| spec.name = "fluent-plugin-azureeventhubs" - spec.version = "0.0.7" + spec.version = "0.0.8" spec.authors = ["Hidemasa Togashi", "Toddy Mladenov", "Justin Seely"] spec.email = ["togachiro@gmail.com", "toddysm@gmail.com"] spec.summary = "Fluentd output plugin for Azure Event Hubs" @@ -20,4 +20,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.7" spec.add_development_dependency "rake", "~> 10.0" spec.add_dependency "fluentd", [">= 0.14.15", "< 2"] + spec.add_dependency "httpclient", ">= 2.8.3" end diff --git a/lib/fluent/plugin/azureeventhubs/http.rb b/lib/fluent/plugin/azureeventhubs/http.rb index 02d435c..da64f14 100644 --- a/lib/fluent/plugin/azureeventhubs/http.rb +++ b/lib/fluent/plugin/azureeventhubs/http.rb @@ -7,6 +7,7 @@ def initialize(connection_string, hub_name, expiry=3600,proxy_addr='',proxy_port require 'json' require 'cgi' require 'time' + require 'httpclient' @connection_string = connection_string @hub_name = hub_name @expiry_interval = expiry @@ -29,6 +30,13 @@ def initialize(connection_string, hub_name, expiry=3600,proxy_addr='',proxy_port end end @uri = URI.parse("#{@endpoint}#{@hub_name}/messages") + + if (proxy_addr.to_s.empty?) + @client = HTTPClient.new + else + proxy_url = "#{proxy_addr}:#{proxy_port}" + @client = HTTPClient.new(proxy) + end end def generate_sas_token(uri) @@ -56,19 +64,8 @@ def send_w_properties(payload, properties) if not properties.nil? headers = headers.merge(properties) end - if (@proxy_addr.to_s.empty?) - https = Net::HTTP.new(@uri.host, @uri.port) - https.open_timeout = @open_timeout - https.read_timeout = @read_timeout - else - https = Net::HTTP.new(@uri.host, @uri.port,@proxy_addr,@proxy_port) - https.open_timeout = @open_timeout - https.read_timeout = @read_timeout - end - https.use_ssl = true - req = Net::HTTP::Post.new(@uri.request_uri, headers) - req.body = payload.to_json - res = https.request(req) - rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Errno::ETIMEDOUT, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e + body = payload.to_json + res = @client.post(@uri.to_s, body, headers) + rescue HTTPClient::TimeoutError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Errno::ETIMEDOUT, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e end end