Class: Huck::Senders::SQSSender

Inherits:
Huck::Sender show all
Defined in:
lib/huck/senders/sqs.rb

Overview

A sender that talks to Amazon Simple Queue Service

Instance Attribute Summary

Attributes inherited from Huck::Sender

#config

Instance Method Summary collapse

Methods inherited from Huck::Sender

factory

Constructor Details

#initializeSQSSender

Includes all required modules for the SQS sender



9
10
11
# File 'lib/huck/senders/sqs.rb', line 9

def initialize
  Huck::must_load 'aws-sdk'
end

Instance Method Details

#send(msg) ⇒ Object

Send an arbitrary text message to the queue for processing

Parameters:

msg

The message to process



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/huck/senders/sqs.rb', line 32

def send msg
  verify_config

  options = Hash.new
  [:access_key_id, :secret_access_key, :region].each do |arg|
    if @config['sqs'].has_key? arg.to_s
      options[arg] = @config['sqs'][arg.to_s]
    end
  end

  sqs = AWS::SQS.new options

  queue = sqs.queues.create @config['sqs']['queue_name']
  queue.send_message msg
end

#verify_configObject

Ensures that configuration is set properly before trying to use the connection data to talk to AWS. It is possible that IAM profiles are in use, so we can’t strictly require that all of the access information is set in the configuration.



17
18
19
20
21
22
23
24
# File 'lib/huck/senders/sqs.rb', line 17

def verify_config
  if !@config.has_key? 'sqs'
    raise Huck::Error, 'missing sqs sender config'
  end
  if !@config['sqs'].has_key? 'queue_name'
    raise Huck::Error, 'missing sqs sender config: queue_name'
  end
end