Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to using a class member httpclient for persistent connections #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fluent-plugin-azureeventhubs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
25 changes: 11 additions & 14 deletions lib/fluent/plugin/azureeventhubs/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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