class EventQ::Amazon::QueueClient

Public Class Methods

new(options = {}) click to toggle source
# File lib/eventq/eventq_aws/aws_queue_client.rb, line 6
def initialize(options = {})
  invalid_keys = options.keys - %i[sns_keep_alive_timeout sns_continue_timeout]
  raise(OptionParser::InvalidOption, invalid_keys) unless invalid_keys.empty?

  @sns_keep_alive_timeout = options[:sns_keep_alive_timeout] || 30
  @sns_continue_timeout = options[:sns_continue_timeout] || 15
end

Public Instance Methods

sns(region = nil) click to toggle source

Returns the AWS SNS Client

# File lib/eventq/eventq_aws/aws_queue_client.rb, line 24
def sns(region = nil)
  if region.nil?
    @sns ||= sns_client
  else
    sns_client(region)
  end
end
sns_helper(region = nil) click to toggle source
# File lib/eventq/eventq_aws/aws_queue_client.rb, line 40
def sns_helper(region = nil)
  if region.nil?
    @sns_helper ||= Amazon::SNS.new(sns)
  else
    Amazon::SNS.new(sns_client(region))
  end
end
sqs(region = nil) click to toggle source

Returns the AWS SQS Client

# File lib/eventq/eventq_aws/aws_queue_client.rb, line 15
def sqs(region = nil)
  if region.nil?
    @sqs ||= sqs_client
  else
    sqs_client(region)
  end
end
sqs_helper(region = nil) click to toggle source
# File lib/eventq/eventq_aws/aws_queue_client.rb, line 32
def sqs_helper(region = nil)
  if region.nil?
    @sqs_helper ||= Amazon::SQS.new(sqs)
  else
    Amazon::SQS.new(sqs_client(region))
  end
end

Private Instance Methods

custom_endpoint(service) click to toggle source
# File lib/eventq/eventq_aws/aws_queue_client.rb, line 50
def custom_endpoint(service)
  aws_env = ENV["AWS_#{service.upcase}_ENDPOINT"].to_s.dup
  aws_env.strip!
  { endpoint: aws_env } unless aws_env.empty?
end
sns_client(region = nil) click to toggle source
# File lib/eventq/eventq_aws/aws_queue_client.rb, line 68
def sns_client(region = nil)
  custom_endpoint('sns')
  options = {
    http_idle_timeout: @sns_keep_alive_timeout,
    http_continue_timeout: @sns_continue_timeout
  }
  endpoint = custom_endpoint('sns')
  options.merge!(endpoint) if endpoint
  options[:region] = region if region

  Aws::SNS::Client.new(options)
end
sqs_client(region = nil) click to toggle source
# File lib/eventq/eventq_aws/aws_queue_client.rb, line 56
def sqs_client(region = nil)
  options = custom_endpoint('sqs')
  options[:verify_checksums] = false if options
  options[:region] = region if region

  if options
    Aws::SQS::Client.new(options)
  else
    Aws::SQS::Client.new
  end
end