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



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

def send msg
  verify_config

  sqs = AWS::SQS.new(
    :access_key_id => @config['sqs']['access_key_id'],
    :secret_access_key => @config['sqs']['secret_access_key'],
    :region => @config['sqs']['region']
  )

  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



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

def verify_config
  if !@config.has_key? 'sqs'
    raise RuntimeError, 'missing sqs sender config'
  end
  ['access_key_id', 'secret_access_key', 'region',
   'queue_name'].each do |key|
    if !@config['sqs'].has_key? key
      raise RuntimeError, "missing sqs sender config: #{key}"
    end
  end
end